| ... | ... |
@@ -19,16 +19,21 @@ sub test {
|
| 19 | 19 |
$test = shift; |
| 20 | 20 |
} |
| 21 | 21 |
|
| 22 |
-# Varialbe for test |
|
| 22 |
+# Varialbes for test |
|
| 23 | 23 |
my $dbi; |
| 24 | 24 |
my $sth; |
| 25 | 25 |
my $tmpl; |
| 26 |
+my $select_tmpl; |
|
| 27 |
+my $insert_tmpl; |
|
| 26 | 28 |
my $params; |
| 27 | 29 |
my $sql; |
| 28 | 30 |
my $result; |
| 29 | 31 |
my @rows; |
| 30 | 32 |
my $rows; |
| 31 | 33 |
my $query; |
| 34 |
+my $select_query; |
|
| 35 |
+my $insert_query; |
|
| 36 |
+ |
|
| 32 | 37 |
|
| 33 | 38 |
|
| 34 | 39 |
# Prepare table |
| ... | ... |
@@ -97,6 +102,25 @@ is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch_all_hash list context"); |
| 97 | 102 |
|
| 98 | 103 |
__END__ |
| 99 | 104 |
|
| 105 |
+test 'Filter'; |
|
| 106 |
+$dbi->reconnect; |
|
| 107 |
+$dbi->dbh->do("create table table1 (key1 char(255), key2 char(255));");
|
|
| 108 |
+ |
|
| 109 |
+$tmpl = "insert into {insert_values key1 key2};";
|
|
| 110 |
+$query = $dbi->create_query($tmpl); |
|
| 111 |
+$query->bind_filter(sub {
|
|
| 112 |
+ my ($key, $value) = @_; |
|
| 113 |
+ if ($key eq 'k1') {
|
|
| 114 |
+ return "$value-$key-$column"; |
|
| 115 |
+ } |
|
| 116 |
+ return $value; |
|
| 117 |
+}); |
|
| 118 |
+ |
|
| 119 |
+ |
|
| 120 |
+$query->fetch_filter(sub {
|
|
| 121 |
+ my ($key, $value) |
|
| 122 |
+}); |
|
| 123 |
+ |
|
| 100 | 124 |
$dbi->fetch_filter(sub {
|
| 101 | 125 |
my ($key, $value, $type, $sth, $i) = @_; |
| 102 | 126 |
if ($key eq 'key1' && $value == 1 && $type =~ /char/i && $i == 0 && $sth->{TYPE}->[$i] eq $type) {
|
| ... | ... |
@@ -182,4 +206,5 @@ $dbi->filters(filter => sub {
|
| 182 | 206 |
is($sql, "update table set key1 = ?, key2 = ?;"); |
| 183 | 207 |
is_deeply(\@bind, ['A', 'b'], 'sql template bind' ); |
| 184 | 208 |
|
| 209 |
+$dbi->disconnnect; |
|
| 185 | 210 |
|