... | ... |
@@ -56,7 +56,7 @@ sub fetch_hash { |
56 | 56 |
# Filter |
57 | 57 |
my $row_hash = {}; |
58 | 58 |
for (my $i = 0; $i < @$columns; $i++) { |
59 |
- my $fname = $filter->{$columns->[$i]} || $filters->{$default_filter} || ''; |
|
59 |
+ my $fname = $filter->{$columns->[$i]} || $default_filter || ''; |
|
60 | 60 |
my $filter = $filters->{$fname}; |
61 | 61 |
$row_hash->{$columns->[$i]} = $filter |
62 | 62 |
? $filter->($row->[$i]) |
... | ... |
@@ -37,7 +37,7 @@ my $NEW_ARGS = { |
37 | 37 |
0 => {data_source => 'dbi:SQLite:dbname=:memory:'} |
38 | 38 |
}; |
39 | 39 |
|
40 |
-# Variables for test |
|
40 |
+# Variables |
|
41 | 41 |
my $dbi; |
42 | 42 |
my $sth; |
43 | 43 |
my $tmpl; |
... | ... |
@@ -48,6 +48,7 @@ my $update_tmpl; |
48 | 48 |
my $params; |
49 | 49 |
my $sql; |
50 | 50 |
my $result; |
51 |
+my $row; |
|
51 | 52 |
my @rows; |
52 | 53 |
my $rows; |
53 | 54 |
my $query; |
... | ... |
@@ -310,11 +311,16 @@ $rows = $result->fetch_hash_all; |
310 | 311 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : basic"); |
311 | 312 |
|
312 | 313 |
$dbi->execute('delete from table1'); |
313 |
-$dbi->resist_filter(three_times => sub { $_[0] * 3}); |
|
314 |
+$dbi->resist_filter( |
|
315 |
+ twice => sub { $_[0] * 2 }, |
|
316 |
+ three_times => sub { $_[0] * 3 } |
|
317 |
+); |
|
318 |
+$dbi->default_query_filter('twice'); |
|
314 | 319 |
$dbi->insert('table1', {key1 => 1, key2 => 2}, {filter => {key1 => 'three_times'}}); |
315 | 320 |
$result = $dbi->execute($SELECT_TMPLS->{0}); |
316 | 321 |
$rows = $result->fetch_hash_all; |
317 |
-is_deeply($rows, [{key1 => 3, key2 => 2}], "$test : filter"); |
|
322 |
+is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : filter"); |
|
323 |
+$dbi->default_query_filter(undef); |
|
318 | 324 |
|
319 | 325 |
$dbi->execute($DROP_TABLE->{0}); |
320 | 326 |
$dbi->execute($CREATE_TABLE->{0}); |
... | ... |
@@ -518,4 +524,17 @@ $query->filter('bbb'); |
518 | 524 |
$query = $dbi->create_query($tmpls[0]); |
519 | 525 |
ok(!$query->filter, "$test : only cached sql and columns"); |
520 | 526 |
|
527 |
+test 'fetch filter'; |
|
528 |
+$dbi = DBIx::Custom->new($NEW_ARGS->{0}); |
|
529 |
+$dbi->resist_filter( |
|
530 |
+ twice => sub { $_[0] * 2 }, |
|
531 |
+ three_times => sub { $_[0] * 3 } |
|
532 |
+); |
|
533 |
+$dbi->default_fetch_filter('twice'); |
|
534 |
+$dbi->execute($CREATE_TABLE->{0}); |
|
535 |
+$dbi->insert('table1', {key1 => 1, key2 => 2}); |
|
536 |
+$result = $dbi->select('table1'); |
|
537 |
+$result->filter({key1 => 'three_times'}); |
|
538 |
+$row = $result->fetch_hash_single; |
|
539 |
+is_deeply($row, {key1 => 3, key2 => 4}, "$test: default_fetch_filter and filter"); |
|
521 | 540 |
|