...
|
...
|
@@ -73,7 +73,6 @@ while (my $row = $result->fetch) {
|
73
|
73
|
}
|
74
|
74
|
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch scalar context");
|
75
|
75
|
|
76
|
|
-
|
77
|
76
|
$result = $dbi->execute($query);
|
78
|
77
|
@rows = ();
|
79
|
78
|
while (my @row = $result->fetch) {
|
...
|
...
|
@@ -81,7 +80,6 @@ while (my @row = $result->fetch) {
|
81
|
80
|
}
|
82
|
81
|
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch list context");
|
83
|
82
|
|
84
|
|
-
|
85
|
83
|
$result = $dbi->execute($query);
|
86
|
84
|
@rows = ();
|
87
|
85
|
while (my $row = $result->fetch_hash) {
|
...
|
...
|
@@ -89,7 +87,6 @@ while (my $row = $result->fetch_hash) {
|
89
|
87
|
}
|
90
|
88
|
is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : fetch_hash scalar context");
|
91
|
89
|
|
92
|
|
-
|
93
|
90
|
$result = $dbi->execute($query);
|
94
|
91
|
@rows = ();
|
95
|
92
|
while (my %row = $result->fetch_hash) {
|
...
|
...
|
@@ -97,22 +94,18 @@ while (my %row = $result->fetch_hash) {
|
97
|
94
|
}
|
98
|
95
|
is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : fetch hash list context");
|
99
|
96
|
|
100
|
|
-
|
101
|
97
|
$result = $dbi->execute($query);
|
102
|
98
|
$rows = $result->fetch_all;
|
103
|
99
|
is_deeply($rows, [[1, 2], [3, 4]], "$test : fetch_all scalar context");
|
104
|
100
|
|
105
|
|
-
|
106
|
101
|
$result = $dbi->execute($query);
|
107
|
102
|
@rows = $result->fetch_all;
|
108
|
103
|
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch_all list context");
|
109
|
104
|
|
110
|
|
-
|
111
|
105
|
$result = $dbi->execute($query);
|
112
|
106
|
@rows = $result->fetch_all_hash;
|
113
|
107
|
is_deeply($rows, [[1, 2], [3, 4]], "$test : fetch_all_hash scalar context");
|
114
|
108
|
|
115
|
|
-
|
116
|
109
|
$result = $dbi->execute($query);
|
117
|
110
|
@rows = $result->fetch_all;
|
118
|
111
|
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch_all_hash list context");
|
...
|
...
|
@@ -141,14 +134,12 @@ $dbi->execute($insert_tmpl, {key1 => 1, key2 => 2}, sub {
|
141
|
134
|
return $value;
|
142
|
135
|
});
|
143
|
136
|
});
|
144
|
|
-
|
145
|
137
|
$result = $dbi->execute($SELECT_TMPL->{0});
|
146
|
|
-
|
147
|
138
|
$rows = $result->fetch_all_hash;
|
148
|
139
|
is_deeply($rows, [{key1 => 1, key2 => 3}], $test);
|
149
|
140
|
|
150
|
141
|
|
151
|
|
-test 'Filter';
|
|
142
|
+test 'Filter basic';
|
152
|
143
|
$dbi->reconnect;
|
153
|
144
|
$dbi->do($CREATE_TABLE->{0});
|
154
|
145
|
|
...
|
...
|
@@ -161,9 +152,7 @@ $insert_query->bind_filter(sub {
|
161
|
152
|
}
|
162
|
153
|
return $value;
|
163
|
154
|
});
|
164
|
|
-
|
165
|
155
|
$dbi->execute($insert_query, {key1 => 1, key2 => 2});
|
166
|
|
-
|
167
|
156
|
$select_query = $dbi->create_query($SELECT_TMPL->{0});
|
168
|
157
|
$select_query->fetch_filter(sub {
|
169
|
158
|
my ($key, $value, $type, $sth, $i) = @_;
|
...
|
...
|
@@ -173,25 +162,20 @@ $select_query->fetch_filter(sub {
|
173
|
162
|
return $value;
|
174
|
163
|
});
|
175
|
164
|
$result = $dbi->execute($select_query);
|
176
|
|
-
|
177
|
165
|
$rows = $result->fetch_all_hash;
|
178
|
166
|
is_deeply($rows, [{key1 => 2, key2 => 6}], "$test : bind_filter fetch_filter");
|
179
|
167
|
|
180
|
|
-
|
181
|
168
|
$dbi->do("delete from table1;");
|
182
|
169
|
$insert_query->no_bind_filters('key1');
|
183
|
170
|
$select_query->no_fetch_filters('key2');
|
184
|
|
-
|
185
|
171
|
$dbi->execute($insert_query, {key1 => 1, key2 => 2});
|
186
|
172
|
$result = $dbi->execute($select_query);
|
187
|
173
|
$rows = $result->fetch_all_hash;
|
188
|
|
-is_deeply($rows, [{key1 => 1, key2 => 2}], 'no_fetch_filters no_bind_filters');
|
189
|
|
-
|
|
174
|
+is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : no_fetch_filters no_bind_filters");
|
190
|
175
|
|
191
|
176
|
$dbi->reconnect;
|
192
|
177
|
$dbi->do($CREATE_TABLE->{0});
|
193
|
178
|
$insert_tmpl = "insert into table1 {insert table1.key1 table1.key2}";
|
194
|
|
-
|
195
|
179
|
$insert_query = $dbi->create_query($insert_tmpl);
|
196
|
180
|
$insert_query->bind_filter(sub {
|
197
|
181
|
my ($key, $value, $table, $column) = @_;
|
...
|
...
|
@@ -200,14 +184,29 @@ $insert_query->bind_filter(sub {
|
200
|
184
|
}
|
201
|
185
|
return $value;
|
202
|
186
|
});
|
203
|
|
-
|
204
|
187
|
$dbi->execute($insert_query, {table1 => {key1 => 1, key2 => 2}});
|
205
|
|
-
|
206
|
188
|
$select_query = $dbi->create_query($SELECT_TMPL->{0});
|
207
|
189
|
$result = $dbi->execute($select_query);
|
208
|
190
|
$rows = $result->fetch_all_hash;
|
209
|
191
|
is_deeply($rows, [{key1 => 3, key2 => 2}], "$test : insert with table name");
|
210
|
192
|
|
|
193
|
+test 'Filter in';
|
|
194
|
+$insert_tmpl = "insert into table1 {insert key1 key2};";
|
|
195
|
+$insert_query = $dbi->create_query($insert_tmpl);
|
|
196
|
+$dbi->execute($insert_query, {key1 => 2, key2 => 4});
|
|
197
|
+$select_tmpl = "select * from table1 where {in table1.key1 2} and {in table1.key2 2}";
|
|
198
|
+$select_query = $dbi->create_query($select_tmpl);
|
|
199
|
+$select_query->bind_filter(sub {
|
|
200
|
+ my ($key, $value, $table, $column) = @_;
|
|
201
|
+ if ($key eq 'table1.key1' && $table eq 'table1' && $column eq 'key1' || $key eq 'table1.key2') {
|
|
202
|
+ return $value * 2;
|
|
203
|
+ }
|
|
204
|
+ return $value;
|
|
205
|
+});
|
|
206
|
+$result = $dbi->execute($select_query, {table1 => {key1 => [1,5], key2 => [2,5]}});
|
|
207
|
+$rows = $result->fetch_all_hash;
|
|
208
|
+is_deeply($rows, [{key1 => 2, key2 => 4}], "$test : bind_filter");
|
|
209
|
+
|
211
|
210
|
|
212
|
211
|
test 'DBI::Custom::SQL::Template basic tag';
|
213
|
212
|
$dbi->reconnect;
|
...
|
...
|
@@ -294,7 +293,6 @@ $result = $dbi->execute($SELECT_TMPL->{0});
|
294
|
293
|
$rows = $result->fetch_all_hash;
|
295
|
294
|
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : #insert");
|
296
|
295
|
|
297
|
|
-
|
298
|
296
|
$dbi->do("delete from table1");
|
299
|
297
|
$insert_tmpl = 'insert into table1 {insert table1.key1 table1.key2 table1.key3 table1.key4 table1.key5}';
|
300
|
298
|
$dbi->execute($insert_tmpl, {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}});
|
...
|
...
|
@@ -360,13 +358,11 @@ $dbi->execute($update_tmpl, {'#update' => {table1 => {key1 => 5, key2 => 5, key3
|
360
|
358
|
$result = $dbi->execute($SELECT_TMPL->{0});
|
361
|
359
|
$rows = $result->fetch_all_hash;
|
362
|
360
|
is_deeply($rows, [{key1 => 5, key2 => 5, key3 => 5, key4 => 5, key5 => 5},
|
363
|
|
- {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test update tag #update with table name");
|
|
361
|
+ {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : update tag #update with table name");
|
364
|
362
|
|
365
|
363
|
$dbi->execute($update_tmpl, {'#update' => {'table1.key1' => 6, 'table1.key2' => 6, 'table1.key3' => 6, 'table1.key4' => 6}, 'table1.key5' => 5});
|
366
|
364
|
$result = $dbi->execute($SELECT_TMPL->{0});
|
367
|
365
|
$rows = $result->fetch_all_hash;
|
368
|
366
|
is_deeply($rows, [{key1 => 6, key2 => 6, key3 => 6, key4 => 6, key5 => 5},
|
369
|
|
- {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test update tag #update with table name dot");
|
370
|
|
-
|
371
|
|
-
|
|
367
|
+ {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : update tag #update with table name dot");
|
372
|
368
|
|