... | ... |
@@ -2,6 +2,7 @@ |
2 | 2 |
- added EXPERIMENTAL DBIx::Custom::Result::kv method |
3 | 3 |
- added EXPERIMENTAL DBIx::Custom::Result::flat method |
4 | 4 |
- added where => {name => [val1, val2, val3]} support |
5 |
+ this is expaned to "where name in (val1, val2, val3)" |
|
5 | 6 |
0.2111 |
6 | 7 |
- "created_at" option is renamed to "ctime" option. |
7 | 8 |
"created_at" is DEPRECATED! |
... | ... |
@@ -1695,7 +1695,11 @@ sub _where_clause_and_param { |
1695 | 1695 |
my $column_quote = $self->q($c); |
1696 | 1696 |
$column_quote = $table_quote . '.' . $column_quote |
1697 | 1697 |
if defined $table_quote; |
1698 |
- push @$clause, "$column_quote = :$column"; |
|
1698 |
+ if (ref $where->{$column} eq 'ARRAY') { |
|
1699 |
+ my $c = join(', ', (":$column") x @{$where->{$column}}); |
|
1700 |
+ push @$clause, "$column_quote in ( $c )"; |
|
1701 |
+ } |
|
1702 |
+ else { push @$clause, "$column_quote = :$column" } |
|
1699 | 1703 |
} |
1700 | 1704 |
|
1701 | 1705 |
$w->{clause} = @$clause ? "where ( " . join(' and ', @$clause) . " ) " : '' ; |
... | ... |
@@ -3299,23 +3303,34 @@ Table name. |
3299 | 3303 |
|
3300 | 3304 |
=item C<where> |
3301 | 3305 |
|
3302 |
- # Hash refrence |
|
3303 |
- where => {author => 'Ken', 'title' => 'Perl'} |
|
3306 |
+ # (1) Hash reference |
|
3307 |
+ where => {author => 'Ken', 'title' => ['Perl', 'Ruby']} |
|
3308 |
+ # -> where author = 'Ken' and title in ('Perl', 'Ruby') |
|
3304 | 3309 |
|
3305 |
- # DBIx::Custom::Where object |
|
3310 |
+ # (2) DBIx::Custom::Where object |
|
3306 | 3311 |
where => $dbi->where( |
3307 | 3312 |
clause => ['and', ':author{=}', ':title{like}'], |
3308 | 3313 |
param => {author => 'Ken', title => '%Perl%'} |
3309 |
- ); |
|
3314 |
+ ) |
|
3315 |
+ # -> where author = 'Ken' and title like '%Perl%' |
|
3310 | 3316 |
|
3311 |
- # Array reference, this is same as above |
|
3317 |
+ # (3) Array reference[Array refenrece, Hash reference] |
|
3312 | 3318 |
where => [ |
3313 | 3319 |
['and', ':author{=}', ':title{like}'], |
3314 | 3320 |
{author => 'Ken', title => '%Perl%'} |
3315 |
- ]; |
|
3321 |
+ ] |
|
3322 |
+ # -> where author = 'Ken' and title like '%Perl%' |
|
3323 |
+ |
|
3324 |
+ # (4) Array reference[String, Hash reference] |
|
3325 |
+ where => [ |
|
3326 |
+ ':author{=} and :title{like}', |
|
3327 |
+ {author => 'Ken', title => '%Perl%'} |
|
3328 |
+ ] |
|
3329 |
+ # -> where author = 'Ken' and title like '%Perl%' |
|
3316 | 3330 |
|
3317 |
- # String |
|
3331 |
+ # (5) String |
|
3318 | 3332 |
where => 'title is null' |
3333 |
+ # -> where title is null |
|
3319 | 3334 |
|
3320 | 3335 |
Where clause. See L<DBIx::Custom::Where>. |
3321 | 3336 |
|
... | ... |
@@ -1351,6 +1351,21 @@ is_deeply($row, {$key1 => 1}); |
1351 | 1351 |
eval { $dbi->select(table => $table1, where => {';' => 1}) }; |
1352 | 1352 |
like($@, qr/safety/); |
1353 | 1353 |
|
1354 |
+eval { $dbi->execute("drop table $table1") }; |
|
1355 |
+$dbi->execute($create_table1); |
|
1356 |
+$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
|
1357 |
+$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
1358 |
+$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1); |
|
1359 |
+ |
|
1360 |
+$rows = $dbi->select(table => $table1, where => {$key1 => [1, 5]})->all; |
|
1361 |
+is_deeply($rows, [ |
|
1362 |
+ {$key1 => 1, $key2 => 2}, |
|
1363 |
+ {$key1 => 5, $key2 => 6} |
|
1364 |
+], "table"); |
|
1365 |
+ |
|
1366 |
+$rows = $dbi->select(table => $table1, where => {$key1 => []})->all; |
|
1367 |
+is_deeply($rows, [], "table"); |
|
1368 |
+ |
|
1354 | 1369 |
test 'fetch filter'; |
1355 | 1370 |
eval { $dbi->execute("drop table $table1") }; |
1356 | 1371 |
$dbi->register_filter( |