... | ... |
@@ -1,3 +1,7 @@ |
1 |
+0.1709 |
|
2 |
+ - fixed named placeholder bug and added escape syntax |
|
3 |
+0.1708 |
|
4 |
+ - improved execute method performance |
|
1 | 5 |
0.1707 |
2 | 6 |
- I call :title named placeholder, stoping calling it parameter |
3 | 7 |
- removed some EXPERIMENTAL status |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
package DBIx::Custom; |
2 | 2 |
use Object::Simple -base; |
3 | 3 |
|
4 |
-our $VERSION = '0.1707'; |
|
4 |
+our $VERSION = '0.1709'; |
|
5 | 5 |
use 5.008001; |
6 | 6 |
|
7 | 7 |
use Carp 'croak'; |
... | ... |
@@ -2169,6 +2169,12 @@ You can specify operator with named placeholder |
2169 | 2169 |
# Replaced |
2170 | 2170 |
select * from where title = ? and author like ?; |
2171 | 2171 |
|
2172 |
+Note that colons in time format such as 12:13:15 is exeption, |
|
2173 |
+it is not parsed as named placeholder. |
|
2174 |
+If you want to use colon generally, you must escape it by C<\\> |
|
2175 |
+ |
|
2176 |
+ select * from where title = "aa\\:bb"; |
|
2177 |
+ |
|
2172 | 2178 |
The following opitons are available. |
2173 | 2179 |
|
2174 | 2180 |
=over 4 |
... | ... |
@@ -68,17 +68,19 @@ sub _placeholder_count { |
68 | 68 |
|
69 | 69 |
sub _parse_parameter { |
70 | 70 |
my ($self, $source) = @_; |
71 |
- |
|
71 |
+ |
|
72 | 72 |
# Get and replace parameters |
73 | 73 |
my $sql = $source || ''; |
74 | 74 |
my $columns = []; |
75 | 75 |
my $c = $self->safety_character; |
76 | 76 |
# Parameter regex |
77 |
- my $re = qr/^(.*?):([$c\.]+)(?:\{(.*?)\})?(.*)/s; |
|
77 |
+ $sql =~ s/([^:]):(\d+):([^:])/$1\\:$2\\:$3/g; |
|
78 |
+ my $re = qr/(^|.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/s; |
|
78 | 79 |
while ($sql =~ /$re/g) { |
79 | 80 |
push @$columns, $2; |
80 | 81 |
$sql = defined $3 ? "$1$2 $3 ?$4" : "$1?$4"; |
81 | 82 |
} |
83 |
+ $sql =~ s/\\:/:/g; |
|
82 | 84 |
|
83 | 85 |
# Create query |
84 | 86 |
my $query = DBIx::Custom::Query->new( |
... | ... |
@@ -88,7 +90,7 @@ sub _parse_parameter { |
88 | 90 |
|
89 | 91 |
return $query; |
90 | 92 |
} |
91 |
- |
|
93 |
+ |
|
92 | 94 |
# DEPRECATED! |
93 | 95 |
has tags => sub { {} }; |
94 | 96 |
|
... | ... |
@@ -211,7 +211,7 @@ is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5}, |
211 | 211 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "basic"); |
212 | 212 |
|
213 | 213 |
|
214 |
-test 'parameter'; |
|
214 |
+test 'Named placeholder'; |
|
215 | 215 |
$dbi->execute($DROP_TABLE->{0}); |
216 | 216 |
$dbi->execute($CREATE_TABLE->{1}); |
217 | 217 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
... | ... |
@@ -241,6 +241,30 @@ $result = $dbi->execute( |
241 | 241 |
$rows = $result->all; |
242 | 242 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]); |
243 | 243 |
|
244 |
+$dbi->execute($DROP_TABLE->{0}); |
|
245 |
+$dbi->execute($CREATE_TABLE->{0}); |
|
246 |
+$dbi->insert(table => 'table1', param => {key1 => '2011-10-14 12:19:18', key2 => 2}); |
|
247 |
+$source = "select * from table1 where key1 = '2011-10-14 12:19:18' and key2 = :key2"; |
|
248 |
+$result = $dbi->execute( |
|
249 |
+ $source, |
|
250 |
+ param => {'key2' => 2}, |
|
251 |
+); |
|
252 |
+ |
|
253 |
+$rows = $result->all; |
|
254 |
+is_deeply($rows, [{key1 => '2011-10-14 12:19:18', key2 => 2}]); |
|
255 |
+ |
|
256 |
+$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
257 |
+$dbi->execute($CREATE_TABLE->{0}); |
|
258 |
+$dbi->insert(table => 'table1', param => {key1 => 'a:b c:d', key2 => 2}); |
|
259 |
+$source = "select * from table1 where key1 = 'a\\:b c\\:d' and key2 = :key2"; |
|
260 |
+$result = $dbi->execute( |
|
261 |
+ $source, |
|
262 |
+ param => {'key2' => 2}, |
|
263 |
+); |
|
264 |
+$rows = $result->all; |
|
265 |
+is_deeply($rows, [{key1 => 'a:b c:d', key2 => 2}]); |
|
266 |
+ |
|
267 |
+ |
|
244 | 268 |
test 'Error case'; |
245 | 269 |
eval {DBIx::Custom->connect(dsn => 'dbi:SQLit')}; |
246 | 270 |
ok($@, "connect error"); |
... | ... |
@@ -3436,7 +3460,7 @@ test 'DBIx::Custom header'; |
3436 | 3460 |
|
3437 | 3461 |
} |
3438 | 3462 |
|
3439 |
-test 'parameter :name(operater) syntax'; |
|
3463 |
+test 'Named placeholder :name(operater) syntax'; |
|
3440 | 3464 |
$dbi->execute($DROP_TABLE->{0}); |
3441 | 3465 |
$dbi->execute($CREATE_TABLE->{1}); |
3442 | 3466 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |