... | ... |
@@ -1235,8 +1235,27 @@ sub _create_query { |
1235 | 1235 |
unless ($query) { |
1236 | 1236 |
|
1237 | 1237 |
# Create query |
1238 |
- my $builder = $self->query_builder; |
|
1239 |
- $query = $builder->build_query($source); |
|
1238 |
+ if (exists $ENV{DBIX_CUSTOM_TAG_PARSE} && !$ENV{DBIX_CUSTOM_TAG_PARSE}) { |
|
1239 |
+ $source ||= ''; |
|
1240 |
+ my $columns = []; |
|
1241 |
+ my $c = $self->{safety_character} || $self->safety_character; |
|
1242 |
+ my %duplicate; |
|
1243 |
+ my $duplicate; |
|
1244 |
+ # Parameter regex |
|
1245 |
+ $source =~ s/([0-9]):/$1\\:/g; |
|
1246 |
+ while ($source =~ /(^|.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/sg) { |
|
1247 |
+ push @$columns, $2; |
|
1248 |
+ $duplicate = 1 if ++$duplicate{$columns->[-1]} > 1; |
|
1249 |
+ $source = defined $3 ? "$1$2 $3 ?$4" : "$1?$4"; |
|
1250 |
+ } |
|
1251 |
+ $source =~ s/\\:/:/g if index($source, "\\:") != -1; |
|
1252 |
+ |
|
1253 |
+ # Create query |
|
1254 |
+ $query = {sql => $source, columns => $columns, duplicate => $duplicate}; |
|
1255 |
+ } |
|
1256 |
+ else { |
|
1257 |
+ $query = $self->query_builder->build_query($source); |
|
1258 |
+ } |
|
1240 | 1259 |
|
1241 | 1260 |
# Save query to cache |
1242 | 1261 |
$self->cache_method->( |
... | ... |
@@ -1268,7 +1287,7 @@ sub _create_query { |
1268 | 1287 |
$query->{sth} = $sth; |
1269 | 1288 |
|
1270 | 1289 |
# Set filters |
1271 |
- $query->{filters} = $self->filters; |
|
1290 |
+ $query->{filters} = $self->{filters} || $self->filters; |
|
1272 | 1291 |
|
1273 | 1292 |
return $query; |
1274 | 1293 |
} |
... | ... |
@@ -14,12 +14,7 @@ sub build_query { |
14 | 14 |
my ($self, $sql) = @_; |
15 | 15 |
|
16 | 16 |
# Parse tag. tag is DEPRECATED! |
17 |
- my $tag_parse; |
|
18 |
- $tag_parse = $ENV{DBIX_CUSTOM_TAG_PARSE} |
|
19 |
- if exists $ENV{DBIX_CUSTOM_TAG_PARSE}; |
|
20 |
- $tag_parse = $self->dbi->{tag_parse} unless defined $tag_parse; |
|
21 |
- |
|
22 |
- if ($tag_parse && $sql =~ /(\s|^)\{/) { |
|
17 |
+ if ($self->dbi->{tag_parse} && $sql =~ /(\s|^)\{/) { |
|
23 | 18 |
my $query = $self->_parse_tag($sql); |
24 | 19 |
my $tag_count = delete $query->{tag_count}; |
25 | 20 |
warn qq/Tag system such as {? name} is DEPRECATED! / . |
... | ... |
@@ -52,7 +47,7 @@ sub build_query { |
52 | 47 |
$sql =~ s/\\:/:/g if index($sql, "\\:") != -1; |
53 | 48 |
|
54 | 49 |
# Create query |
55 |
- return {sql => $sql, columns => $columns}; |
|
50 |
+ return {sql => $sql, columns => $columns, duplicate => 1}; |
|
56 | 51 |
} |
57 | 52 |
|
58 | 53 |
# DEPRECATED! |
... | ... |
@@ -39,7 +39,8 @@ sub to_string { |
39 | 39 |
$self->{_query_builder} = $self->dbi->query_builder; |
40 | 40 |
$self->{_safety_character} = $self->dbi->safety_character; |
41 | 41 |
$self->{_quote} = $self->dbi->_quote; |
42 |
- $self->{_tag_parse} = $self->dbi->{tag_parse}; |
|
42 |
+ $self->{_tag_parse} = exists $ENV{DBIX_CUSTOM_TAG_PARSE} |
|
43 |
+ ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->dbi->{tag_parse}; |
|
43 | 44 |
$self->_parse($clause, $where, $count, 'and'); |
44 | 45 |
|
45 | 46 |
# Stringify |
... | ... |
@@ -3056,6 +3056,8 @@ test 'DBIX_CUSTOM_TAG_PARSE environment variable'; |
3056 | 3056 |
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1); |
3057 | 3057 |
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})}; |
3058 | 3058 |
ok($@); |
3059 |
+ eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) }; |
|
3060 |
+ ok($@); |
|
3059 | 3061 |
delete$ENV{DBIX_CUSTOM_TAG_PARSE}; |
3060 | 3062 |
} |
3061 | 3063 |
|
... | ... |
@@ -3065,7 +3067,7 @@ test 'DBIX_CUSTOM_TAG_PARSE environment variable'; |
3065 | 3067 |
eval { $dbi->execute("drop table $table1") }; |
3066 | 3068 |
$dbi->execute($create_table1); |
3067 | 3069 |
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1); |
3068 |
- is($dbi->select(table => $table1)->one->{$key1}, 1); |
|
3070 |
+ is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1); |
|
3069 | 3071 |
delete$ENV{DBIX_CUSTOM_TAG_PARSE}; |
3070 | 3072 |
} |
3071 | 3073 |
|