... | ... |
@@ -1248,26 +1248,29 @@ sub _create_query { |
1248 | 1248 |
unless ($query) { |
1249 | 1249 |
|
1250 | 1250 |
# Create query |
1251 |
- if (exists $ENV{DBIX_CUSTOM_TAG_PARSE} && !$ENV{DBIX_CUSTOM_TAG_PARSE}) { |
|
1252 |
- $source ||= ''; |
|
1253 |
- my $columns = []; |
|
1251 |
+ my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE} |
|
1252 |
+ ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse}; |
|
1253 |
+ |
|
1254 |
+ my $sql = $source || ''; |
|
1255 |
+ if ($tag_parse && ($sql =~ /\s\{/ || $sql =~ /^\{/)) { |
|
1256 |
+ $query = $self->query_builder->build_query($sql); |
|
1257 |
+ } |
|
1258 |
+ else { |
|
1259 |
+ my @columns; |
|
1254 | 1260 |
my $c = $self->{safety_character} || $self->safety_character; |
1255 | 1261 |
my %duplicate; |
1256 | 1262 |
my $duplicate; |
1257 | 1263 |
# Parameter regex |
1258 |
- $source =~ s/([0-9]):/$1\\:/g; |
|
1259 |
- while ($source =~ /(^|.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/sg) { |
|
1260 |
- push @$columns, $2; |
|
1261 |
- $duplicate = 1 if ++$duplicate{$columns->[-1]} > 1; |
|
1262 |
- $source = defined $3 ? "$1$2 $3 ?$4" : "$1?$4"; |
|
1264 |
+ $sql =~ s/([0-9]):/$1\\:/g; |
|
1265 |
+ while ($sql =~ /(^|.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/sg) { |
|
1266 |
+ push @columns, $2; |
|
1267 |
+ $duplicate = 1 if ++$duplicate{$columns[-1]} > 1; |
|
1268 |
+ $sql = defined $3 ? "$1$2 $3 ?$4" : "$1?$4"; |
|
1263 | 1269 |
} |
1264 |
- $source =~ s/\\:/:/g if index($source, "\\:") != -1; |
|
1270 |
+ $sql =~ s/\\:/:/g if index($sql, "\\:") != -1; |
|
1265 | 1271 |
|
1266 | 1272 |
# Create query |
1267 |
- $query = {sql => $source, columns => $columns, duplicate => $duplicate}; |
|
1268 |
- } |
|
1269 |
- else { |
|
1270 |
- $query = $self->query_builder->build_query($source); |
|
1273 |
+ $query = {sql => $sql, columns => \@columns, duplicate => $duplicate}; |
|
1271 | 1274 |
} |
1272 | 1275 |
|
1273 | 1276 |
# Save query to cache |
... | ... |
@@ -248,6 +248,8 @@ for my $i (1 .. 2) { |
248 | 248 |
} |
249 | 249 |
$rows = $dbi->select(table => $table1)->all; |
250 | 250 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 1, $key2 => 2}]); |
251 |
+ok(keys %$reuse); |
|
252 |
+ok((keys %$reuse)[0] !~ /\?/); |
|
251 | 253 |
|
252 | 254 |
# Get user table info |
253 | 255 |
$dbi = DBIx::Custom->connect; |