added common test executing ...
|
1 |
use Test::More; |
2 |
use strict; |
|
3 |
use warnings; |
|
test cleanup
|
4 |
use Encode qw/encode_utf8/; |
cleanup test
|
5 |
use FindBin; |
cleanup
|
6 |
use Scalar::Util 'isweak'; |
cleanup test
|
7 | |
- added DBIX_CUSTOM_SUPPRESS...
|
8 |
$ENV{DBIX_CUSTOM_SUPPRESS_DEPRECATION} = '0.25'; |
9 | ||
added common test executing ...
|
10 |
my $dbi; |
11 | ||
12 |
plan skip_all => $ENV{DBIX_CUSTOM_SKIP_MESSAGE} || 'common.t is always skipped' |
|
13 |
unless $ENV{DBIX_CUSTOM_TEST_RUN} |
|
14 |
&& eval { $dbi = DBIx::Custom->connect; 1 }; |
|
15 | ||
16 |
plan 'no_plan'; |
|
17 | ||
finished oracle test
|
18 |
sub test { print "# $_[0]\n" } |
19 | ||
fixed test
|
20 |
# Dot to under score |
21 |
sub u($) { |
|
22 |
my $value = shift; |
|
23 |
$value =~ s/\./_/g; |
|
24 |
return $value; |
|
25 |
} |
|
26 | ||
improved test
|
27 |
sub u2($) { |
28 |
my $value = shift; |
|
29 |
$value =~ s/\./__/g; |
|
30 |
return $value; |
|
31 |
} |
|
32 | ||
33 |
sub hy($) { |
|
34 |
my $value = shift; |
|
35 |
$value =~ s/\./-/g; |
|
36 |
return $value; |
|
37 |
} |
|
38 | ||
improved test
|
39 |
sub colon2 { |
40 |
my $value = shift; |
|
41 |
$value =~ s/\./::/g; |
|
42 |
return $value; |
|
43 |
} |
|
44 | ||
improved tests
|
45 |
sub table_only { |
46 |
my $value = shift; |
|
47 |
$value =~ s/^.+\.//; |
|
48 |
return $value; |
|
49 |
} |
|
50 | ||
cleanup test
|
51 |
# Constant |
52 |
my $table1 = $dbi->table1; |
|
53 |
my $table2 = $dbi->table2; |
|
54 |
my $table2_alias = $dbi->table2_alias; |
|
55 |
my $table3 = $dbi->table3; |
|
56 |
my $key1 = $dbi->key1; |
|
57 |
my $key2 = $dbi->key2; |
|
58 |
my $key3 = $dbi->key3; |
|
59 |
my $key4 = $dbi->key4; |
|
60 |
my $key5 = $dbi->key5; |
|
61 |
my $key6 = $dbi->key6; |
|
62 |
my $key7 = $dbi->key7; |
|
63 |
my $key8 = $dbi->key8; |
|
64 |
my $key9 = $dbi->key9; |
|
65 |
my $key10 = $dbi->key10; |
|
66 |
my $create_table1 = $dbi->create_table1; |
|
67 |
my $create_table1_2 = $dbi->create_table1_2; |
|
68 |
my $create_table1_type = $dbi->create_table1_type; |
|
69 |
my $create_table1_highperformance = $dbi->create_table1_highperformance; |
|
70 |
my $create_table2 = $dbi->create_table2; |
|
71 |
my $create_table2_2 = $dbi->create_table2_2; |
|
72 |
my $create_table3 = $dbi->create_table3; |
|
73 |
my $create_table_reserved = $dbi->create_table_reserved; |
|
improved test
|
74 |
my ($q, $p) = $dbi->_qp; |
cleanup test
|
75 |
my $date_typename = $dbi->date_typename; |
76 |
my $datetime_typename = $dbi->datetime_typename; |
|
77 |
my $date_datatype = $dbi->date_datatype; |
|
78 |
my $datetime_datatype = $dbi->datetime_datatype; |
|
79 | ||
80 |
# Variables |
|
81 |
my $builder; |
|
82 |
my $datas; |
|
83 |
my $sth; |
|
84 |
my $source; |
|
85 |
my @sources; |
|
86 |
my $select_source; |
|
87 |
my $insert_source; |
|
88 |
my $update_source; |
|
89 |
my $param; |
|
90 |
my $params; |
|
91 |
my $sql; |
|
92 |
my $result; |
|
93 |
my $row; |
|
94 |
my @rows; |
|
95 |
my $rows; |
|
96 |
my $query; |
|
97 |
my @queries; |
|
98 |
my $select_query; |
|
99 |
my $insert_query; |
|
100 |
my $update_query; |
|
101 |
my $ret_val; |
|
102 |
my $infos; |
|
103 |
my $model; |
|
104 |
my $model2; |
|
105 |
my $where; |
|
106 |
my $update_param; |
|
107 |
my $insert_param; |
|
108 |
my $join; |
|
109 |
my $binary; |
|
added test
|
110 |
my $user_table_info; |
cleanup
|
111 |
my $user_column_info; |
- update_param is DEPRECATED...
|
112 |
my $values_clause; |
113 |
my $assign_clause; |
|
added EXPERIMENTAL reuse_que...
|
114 |
my $reuse; |
- fixed update_or_insert bug...
|
115 |
my $affected; |
added EXPERIMENTAL DBIx::Cus...
|
116 |
my $dbi1; |
117 |
my $dbi2; |
|
118 |
my $dbi3; |
|
119 |
my $dbi4; |
|
120 |
my $dbi5; |
|
121 |
my $pool; |
|
cleanup test
|
122 | |
test cleanup
|
123 |
require MyDBI1; |
test cleanup
|
124 |
{ |
cleanup
|
125 |
package MyDBI4; |
test cleanup
|
126 | |
cleanup
|
127 |
use strict; |
128 |
use warnings; |
|
test cleanup
|
129 | |
cleanup
|
130 |
use base 'DBIx::Custom'; |
test cleanup
|
131 | |
cleanup
|
132 |
sub connect { |
133 |
my $self = shift->SUPER::connect(@_); |
|
134 |
|
|
135 |
$self->include_model( |
|
136 |
MyModel2 => [ |
|
137 |
$table1, |
|
138 |
{class => $table2, name => $table2} |
|
139 |
] |
|
140 |
); |
|
141 |
} |
|
test cleanup
|
142 | |
cleanup
|
143 |
package MyModel2::Base1; |
test cleanup
|
144 | |
cleanup
|
145 |
use strict; |
146 |
use warnings; |
|
test cleanup
|
147 | |
cleanup
|
148 |
use base 'DBIx::Custom::Model'; |
test cleanup
|
149 | |
cleanup
|
150 |
package MyModel2::table1; |
test cleanup
|
151 | |
cleanup
|
152 |
use strict; |
153 |
use warnings; |
|
test cleanup
|
154 | |
cleanup
|
155 |
use base 'MyModel2::Base1'; |
test cleanup
|
156 | |
cleanup
|
157 |
sub insert { |
158 |
my ($self, $param) = @_; |
|
159 |
|
|
160 |
return $self->SUPER::insert($param); |
|
161 |
} |
|
test cleanup
|
162 | |
cleanup
|
163 |
sub list { shift->select; } |
test cleanup
|
164 | |
cleanup
|
165 |
package MyModel2::table2; |
test cleanup
|
166 | |
cleanup
|
167 |
use strict; |
168 |
use warnings; |
|
test cleanup
|
169 | |
cleanup
|
170 |
use base 'MyModel2::Base1'; |
test cleanup
|
171 | |
cleanup
|
172 |
sub insert { |
173 |
my ($self, $param) = @_; |
|
174 |
|
|
175 |
return $self->SUPER::insert($param); |
|
176 |
} |
|
test cleanup
|
177 | |
cleanup
|
178 |
sub list { shift->select; } |
test cleanup
|
179 | |
cleanup
|
180 |
package MyModel2::TABLE1; |
test cleanup
|
181 | |
cleanup
|
182 |
use strict; |
183 |
use warnings; |
|
test cleanup
|
184 | |
cleanup
|
185 |
use base 'MyModel2::Base1'; |
test cleanup
|
186 | |
cleanup
|
187 |
sub insert { |
188 |
my ($self, $param) = @_; |
|
189 |
|
|
190 |
return $self->SUPER::insert($param); |
|
191 |
} |
|
test cleanup
|
192 | |
cleanup
|
193 |
sub list { shift->select; } |
test cleanup
|
194 | |
cleanup
|
195 |
package MyModel2::TABLE2; |
test cleanup
|
196 | |
cleanup
|
197 |
use strict; |
198 |
use warnings; |
|
199 | ||
200 |
use base 'MyModel2::Base1'; |
|
201 | ||
202 |
sub insert { |
|
203 |
my ($self, $param) = @_; |
|
204 |
|
|
205 |
return $self->SUPER::insert($param); |
|
206 |
} |
|
207 | ||
208 |
sub list { shift->select; } |
|
improved test
|
209 | |
210 | ||
211 |
package MyModel2::main::table1; |
|
212 | ||
213 |
use strict; |
|
214 |
use warnings; |
|
215 | ||
216 |
use base 'MyModel2::Base1'; |
|
217 | ||
218 |
sub insert { |
|
219 |
my ($self, $param) = @_; |
|
220 |
|
|
221 |
return $self->SUPER::insert($param); |
|
222 |
} |
|
223 | ||
224 |
sub list { shift->select; } |
|
225 | ||
226 |
package MyModel2::main::table2; |
|
227 | ||
228 |
use strict; |
|
229 |
use warnings; |
|
230 | ||
231 |
use base 'MyModel2::Base1'; |
|
232 | ||
233 |
sub insert { |
|
234 |
my ($self, $param) = @_; |
|
235 |
|
|
236 |
return $self->SUPER::insert($param); |
|
237 |
} |
|
238 | ||
239 |
sub list { shift->select; } |
|
added t/common-mysql-qualifi...
|
240 | |
241 |
package MyModel2::dbix_custom::table1; |
|
242 | ||
243 |
use strict; |
|
244 |
use warnings; |
|
245 | ||
246 |
use base 'MyModel2::Base1'; |
|
247 | ||
248 |
sub insert { |
|
249 |
my ($self, $param) = @_; |
|
250 |
|
|
251 |
return $self->SUPER::insert($param); |
|
252 |
} |
|
253 | ||
254 |
sub list { shift->select; } |
|
255 | ||
256 |
package MyModel2::dbix_custom::table2; |
|
257 | ||
258 |
use strict; |
|
259 |
use warnings; |
|
260 | ||
261 |
use base 'MyModel2::Base1'; |
|
262 | ||
263 |
sub insert { |
|
264 |
my ($self, $param) = @_; |
|
265 |
|
|
266 |
return $self->SUPER::insert($param); |
|
267 |
} |
|
268 | ||
269 |
sub list { shift->select; } |
|
test cleanup
|
270 |
} |
added t/common-mysql-qualifi...
|
271 | |
test cleanup
|
272 |
{ |
cleanup
|
273 |
package MyDBI5; |
test cleanup
|
274 | |
cleanup
|
275 |
use strict; |
276 |
use warnings; |
|
test cleanup
|
277 | |
cleanup
|
278 |
use base 'DBIx::Custom'; |
test cleanup
|
279 | |
cleanup
|
280 |
sub connect { |
281 |
my $self = shift->SUPER::connect(@_); |
|
282 |
|
|
283 |
$self->include_model('MyModel4'); |
|
284 |
} |
|
test cleanup
|
285 |
} |
286 |
{ |
|
cleanup
|
287 |
package MyDBI6; |
288 |
|
|
289 |
use base 'DBIx::Custom'; |
|
290 |
|
|
291 |
sub connect { |
|
292 |
my $self = shift->SUPER::connect(@_); |
|
test cleanup
|
293 |
|
cleanup
|
294 |
$self->include_model('MyModel5'); |
test cleanup
|
295 |
|
cleanup
|
296 |
return $self; |
297 |
} |
|
test cleanup
|
298 |
} |
299 |
{ |
|
cleanup
|
300 |
package MyDBI7; |
301 |
|
|
302 |
use base 'DBIx::Custom'; |
|
303 |
|
|
304 |
sub connect { |
|
305 |
my $self = shift->SUPER::connect(@_); |
|
test cleanup
|
306 |
|
cleanup
|
307 |
$self->include_model('MyModel6'); |
test cleanup
|
308 |
|
cleanup
|
309 |
|
310 |
return $self; |
|
311 |
} |
|
test cleanup
|
312 |
} |
313 |
{ |
|
cleanup
|
314 |
package MyDBI8; |
315 |
|
|
316 |
use base 'DBIx::Custom'; |
|
317 |
|
|
318 |
sub connect { |
|
319 |
my $self = shift->SUPER::connect(@_); |
|
test cleanup
|
320 |
|
cleanup
|
321 |
$self->include_model('MyModel7'); |
test cleanup
|
322 |
|
cleanup
|
323 |
return $self; |
324 |
} |
|
test cleanup
|
325 |
} |
326 | ||
327 |
{ |
|
cleanup
|
328 |
package MyDBI9; |
329 |
|
|
330 |
use base 'DBIx::Custom'; |
|
331 |
|
|
332 |
sub connect { |
|
333 |
my $self = shift->SUPER::connect(@_); |
|
test cleanup
|
334 |
|
cleanup
|
335 |
$self->include_model('MyModel8'); |
test cleanup
|
336 |
|
cleanup
|
337 |
return $self; |
338 |
} |
|
test cleanup
|
339 |
} |
340 | ||
added EXPERIMENTAL reuse_que...
|
341 |
test 'execute reuse option'; |
added EXPERIMENTAL reuse_sth...
|
342 |
eval { $dbi->execute("drop table $table1") }; |
343 |
$dbi->execute($create_table1); |
|
added EXPERIMENTAL reuse_que...
|
344 |
$reuse = {}; |
added EXPERIMENTAL reuse_sth...
|
345 |
for my $i (1 .. 2) { |
cleanup
|
346 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, reuse => $reuse); |
added EXPERIMENTAL reuse_sth...
|
347 |
} |
348 |
$rows = $dbi->select(table => $table1)->all; |
|
349 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 1, $key2 => 2}]); |
|
cleanup
|
350 |
ok(keys %$reuse); |
351 |
ok((keys %$reuse)[0] !~ /\?/); |
|
added EXPERIMENTAL reuse_sth...
|
352 | |
added test
|
353 |
# Get user table info |
354 |
$dbi = DBIx::Custom->connect; |
|
355 |
eval { $dbi->execute("drop table $table1") }; |
|
356 |
eval { $dbi->execute("drop table $table2") }; |
|
357 |
eval { $dbi->execute("drop table $table3") }; |
|
358 |
$dbi->execute($create_table1); |
|
359 |
$dbi->execute($create_table2); |
|
360 |
$dbi->execute($create_table3); |
|
361 |
$user_table_info = $dbi->get_table_info(exclude => $dbi->exclude_table); |
|
362 | ||
cleanup test
|
363 |
# Create table |
test cleanup
|
364 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
365 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
366 |
$dbi->execute($create_table1); |
367 |
$model = $dbi->create_model(table => $table1); |
|
368 |
$model->insert({$key1 => 1, $key2 => 2}); |
|
369 |
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]); |
|
cleanup
|
370 | |
- select method can receive ...
|
371 |
eval { $dbi->execute("drop table $table1") }; |
372 |
$dbi->execute($create_table1); |
|
373 |
$model = $dbi->create_model(table => $table1); |
|
374 |
$model->insert({$key1 => 1, $key2 => 2}); |
|
375 |
is_deeply($model->select($key1)->all, [{$key1 => 1}]); |
|
376 | ||
cleanup test
|
377 |
test 'DBIx::Custom::Result test'; |
378 |
$dbi->delete_all(table => $table1); |
|
test cleanup
|
379 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
380 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
cleanup test
|
381 |
$source = "select $key1, $key2 from $table1"; |
382 |
$query = $dbi->create_query($source); |
|
383 |
$result = $dbi->execute($query); |
|
cleanup
|
384 | |
cleanup test
|
385 |
@rows = (); |
386 |
while (my $row = $result->fetch) { |
|
cleanup
|
387 |
push @rows, [@$row]; |
cleanup test
|
388 |
} |
389 |
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch"); |
|
cleanup
|
390 | |
cleanup test
|
391 |
$result = $dbi->execute($query); |
392 |
@rows = (); |
|
393 |
while (my $row = $result->fetch_hash) { |
|
cleanup
|
394 |
push @rows, {%$row}; |
cleanup test
|
395 |
} |
396 |
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash"); |
|
test cleanup
|
397 | |
cleanup test
|
398 |
$result = $dbi->execute($query); |
399 |
$rows = $result->fetch_all; |
|
- added EXPERIMENTAL DBIx::C...
|
400 |
is_deeply($rows, [[1, 2], [3, 4]]); |
test cleanup
|
401 | |
cleanup test
|
402 |
$result = $dbi->execute($query); |
403 |
$rows = $result->fetch_hash_all; |
|
404 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "all"); |
|
test cleanup
|
405 | |
- added EXPERIMENTAL DBIx::C...
|
406 |
is_deeply($dbi->select($key1, table => $table1)->column, [1, 3]); |
- added DBIX_CUSTOM_SUPPRESS...
|
407 |
is_deeply($dbi->select($key1, table => $table1)->values, [1, 3]); |
- added EXPERIMENTAL DBIx::C...
|
408 | |
409 |
is($dbi->select('count(*)', table => $table1)->value, 2); |
|
410 |
ok(!defined $dbi->select($key1, table => $table1, where => {$key1 => 10})->value); |
|
411 | ||
cleanup test
|
412 |
test 'Insert query return value'; |
413 |
$source = "insert into $table1 {insert_param $key1 $key2}"; |
|
414 |
$query = $dbi->execute($source, {}, query => 1); |
|
test cleanup
|
415 |
$ret_val = $dbi->execute($query, {$key1 => 1, $key2 => 2}); |
cleanup test
|
416 |
ok($ret_val); |
test cleanup
|
417 | |
cleanup test
|
418 |
test 'Direct query'; |
419 |
$dbi->delete_all(table => $table1); |
|
420 |
$insert_source = "insert into $table1 {insert_param $key1 $key2}"; |
|
test cleanup
|
421 |
$dbi->execute($insert_source, {$key1 => 1, $key2 => 2}); |
cleanup test
|
422 |
$result = $dbi->execute("select * from $table1"); |
423 |
$rows = $result->all; |
|
424 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
|
cleanup test
|
425 | |
426 |
test 'Filter basic'; |
|
test cleanup in progress
|
427 |
$dbi->delete_all(table => $table1); |
cleanup
|
428 |
$dbi->register_filter(twice => sub { $_[0] * 2}, |
429 |
three_times => sub { $_[0] * 3}); |
|
cleanup test
|
430 | |
cleanup test
|
431 |
$insert_source = "insert into $table1 {insert_param $key1 $key2}"; |
cleanup test
|
432 |
$insert_query = $dbi->execute($insert_source, {}, query => 1); |
test cleanup in progress
|
433 |
$insert_query->filter({$key1 => 'twice'}); |
test cleanup
|
434 |
$dbi->execute($insert_query, {$key1 => 1, $key2 => 2}); |
cleanup test
|
435 |
$result = $dbi->execute("select * from $table1"); |
test cleanup in progress
|
436 |
$rows = $result->filter({$key2 => 'three_times'})->all; |
437 |
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter"); |
|
cleanup test
|
438 | |
439 |
test 'Filter in'; |
|
test cleanup in progress
|
440 |
$dbi->delete_all(table => $table1); |
cleanup test
|
441 |
$insert_source = "insert into $table1 {insert_param $key1 $key2}"; |
cleanup test
|
442 |
$insert_query = $dbi->execute($insert_source, {}, query => 1); |
test cleanup
|
443 |
$dbi->execute($insert_query, {$key1 => 2, $key2 => 4}); |
test cleanup in progress
|
444 |
$select_source = "select * from $table1 where {in $table1.$key1 2} and {in $table1.$key2 2}"; |
cleanup test
|
445 |
$select_query = $dbi->execute($select_source,{}, query => 1); |
finishied sqlite test cleanu...
|
446 |
$select_query->filter({"$table1.$key1" => 'twice'}); |
test cleanup
|
447 |
$result = $dbi->execute($select_query, {"$table1.$key1" => [1,5], "$table1.$key2" => [2,4]}); |
cleanup test
|
448 |
$rows = $result->all; |
test cleanup in progress
|
449 |
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter"); |
cleanup test
|
450 | |
cleanup test
|
451 |
test 'DBIx::Custom::SQLTemplate basic tag'; |
added EXPERIMENTAL reuse_sth...
|
452 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
453 |
$dbi->execute($create_table1_2); |
test cleanup
|
454 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
455 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
cleanup test
|
456 | |
cleanup test
|
457 |
$source = "select * from $table1 where $key1 = :$key1 and {<> $key2} and {< $key3} and {> $key4} and {>= $key5}"; |
cleanup test
|
458 |
$query = $dbi->execute($source, {}, query => 1); |
test cleanup
|
459 |
$result = $dbi->execute($query, {$key1 => 1, $key2 => 3, $key3 => 4, $key4 => 3, $key5 => 5}); |
cleanup test
|
460 |
$rows = $result->all; |
test cleanup in progress
|
461 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}], "basic tag1"); |
cleanup test
|
462 | |
cleanup test
|
463 |
$source = "select * from $table1 where $key1 = :$key1 and {<> $key2} and {< $key3} and {> $key4} and {>= $key5}"; |
cleanup test
|
464 |
$query = $dbi->execute($source, {}, query => 1); |
test cleanup in progress
|
465 |
$result = $dbi->execute($query, {$key1 => 1, $key2 => 3, $key3 => 4, $key4 => 3, $key5 => 5}); |
cleanup test
|
466 |
$rows = $result->all; |
test cleanup in progress
|
467 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}], "basic tag1"); |
cleanup test
|
468 | |
cleanup test
|
469 |
$source = "select * from $table1 where {<= $key1} and {like $key2}"; |
cleanup test
|
470 |
$query = $dbi->execute($source, {}, query => 1); |
test cleanup
|
471 |
$result = $dbi->execute($query, {$key1 => 1, $key2 => '%2%'}); |
cleanup test
|
472 |
$rows = $result->all; |
test cleanup in progress
|
473 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}], "basic tag2"); |
cleanup test
|
474 | |
475 |
test 'DIB::Custom::SQLTemplate in tag'; |
|
added EXPERIMENTAL reuse_sth...
|
476 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
477 |
$dbi->execute($create_table1_2); |
test cleanup
|
478 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
479 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
cleanup test
|
480 | |
cleanup test
|
481 |
$source = "select * from $table1 where {in $key1 2}"; |
cleanup test
|
482 |
$query = $dbi->execute($source, {}, query => 1); |
test cleanup
|
483 |
$result = $dbi->execute($query, {$key1 => [9, 1]}); |
cleanup test
|
484 |
$rows = $result->all; |
test cleanup in progress
|
485 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}], "basic"); |
cleanup test
|
486 | |
487 |
test 'DBIx::Custom::SQLTemplate insert tag'; |
|
test cleanup in progress
|
488 |
$dbi->delete_all(table => $table1); |
489 |
$insert_source = "insert into $table1 {insert_param $key1 $key2 $key3 $key4 $key5}"; |
|
test cleanup
|
490 |
$dbi->execute($insert_source, {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
cleanup test
|
491 | |
cleanup test
|
492 |
$result = $dbi->execute("select * from $table1"); |
cleanup test
|
493 |
$rows = $result->all; |
test cleanup in progress
|
494 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}], "basic"); |
cleanup test
|
495 | |
496 |
test 'DBIx::Custom::SQLTemplate update tag'; |
|
test cleanup in progress
|
497 |
$dbi->delete_all(table => $table1); |
498 |
$insert_source = "insert into $table1 {insert_param $key1 $key2 $key3 $key4 $key5}"; |
|
test cleanup
|
499 |
$dbi->execute($insert_source, {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
500 |
$dbi->execute($insert_source, {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
cleanup test
|
501 | |
test cleanup in progress
|
502 |
$update_source = "update $table1 {update_param $key1 $key2 $key3 $key4} where {= $key5}"; |
test cleanup
|
503 |
$dbi->execute($update_source, {$key1 => 1, $key2 => 1, $key3 => 1, $key4 => 1, $key5 => 5}); |
cleanup test
|
504 | |
cleanup test
|
505 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
cleanup test
|
506 |
$rows = $result->all; |
test cleanup in progress
|
507 |
is_deeply($rows, [{$key1 => 1, $key2 => 1, $key3 => 1, $key4 => 1, $key5 => 5}, |
cleanup
|
508 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], "basic"); |
cleanup test
|
509 | |
cleanup test
|
510 |
test 'Named placeholder'; |
added EXPERIMENTAL reuse_sth...
|
511 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
512 |
$dbi->execute($create_table1_2); |
test cleanup
|
513 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
514 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
cleanup test
|
515 | |
test cleanup in progress
|
516 |
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2"; |
test cleanup
|
517 |
$result = $dbi->execute($source, {$key1 => 1, $key2 => 2}); |
cleanup test
|
518 |
$rows = $result->all; |
test cleanup in progress
|
519 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]); |
cleanup test
|
520 | |
test cleanup in progress
|
521 |
$source = "select * from $table1 where $key1 = \n:$key1\n and $key2 = :$key2"; |
test cleanup
|
522 |
$result = $dbi->execute($source, {$key1 => 1, $key2 => 2}); |
cleanup test
|
523 |
$rows = $result->all; |
test cleanup in progress
|
524 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]); |
cleanup test
|
525 | |
test cleanup in progress
|
526 |
$source = "select * from $table1 where $key1 = :$key1 or $key1 = :$key1"; |
test cleanup
|
527 |
$result = $dbi->execute($source, {$key1 => [1, 2]}); |
cleanup test
|
528 |
$rows = $result->all; |
test cleanup in progress
|
529 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]); |
cleanup test
|
530 | |
test cleanup in progress
|
531 |
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2"; |
cleanup test
|
532 |
$result = $dbi->execute( |
cleanup
|
533 |
$source, |
534 |
{"$table1.$key1" => 1, "$table1.$key2" => 1}, |
|
535 |
filter => {"$table1.$key2" => sub { $_[0] * 2 }} |
|
cleanup test
|
536 |
); |
537 |
$rows = $result->all; |
|
test cleanup in progress
|
538 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]); |
cleanup test
|
539 | |
added EXPERIMENTAL reuse_sth...
|
540 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
541 |
$dbi->execute($create_table1); |
test cleanup
|
542 |
$dbi->insert({$key1 => '2011-10-14 12:19:18', $key2 => 2}, table => $table1); |
test cleanup in progress
|
543 |
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2"; |
cleanup test
|
544 |
$result = $dbi->execute( |
cleanup
|
545 |
$source, |
546 |
{$key2 => 2}, |
|
cleanup test
|
547 |
); |
548 | ||
549 |
$rows = $result->all; |
|
test cleanup in progress
|
550 |
like($rows->[0]->{$key1}, qr/2011-10-14 12:19:18/); |
551 |
is($rows->[0]->{$key2}, 2); |
|
cleanup test
|
552 | |
test cleanup in progress
|
553 |
$dbi->delete_all(table => $table1); |
test cleanup
|
554 |
$dbi->insert({$key1 => 'a:b c:d', $key2 => 2}, table => $table1); |
test cleanup in progress
|
555 |
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2"; |
cleanup test
|
556 |
$result = $dbi->execute( |
cleanup
|
557 |
$source, |
558 |
{$key2 => 2}, |
|
cleanup test
|
559 |
); |
560 |
$rows = $result->all; |
|
test cleanup in progress
|
561 |
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]); |
cleanup test
|
562 | |
test cleanup
|
563 |
test 'Error case'; |
564 |
eval {DBIx::Custom->connect(dsn => 'dbi:SQLit')}; |
|
565 |
ok($@, "connect error"); |
|
566 | ||
567 |
eval{$dbi->execute("{p }", {}, query => 1)}; |
|
568 |
ok($@, "create_query invalid SQL template"); |
|
added EXPERIMENTAL DBIx::Cus...
|
569 | |
cleanup test
|
570 |
test 'insert'; |
finishied sqlite test cleanu...
|
571 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
572 |
$dbi->execute($create_table1); |
test cleanup
|
573 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
574 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
cleanup test
|
575 |
$result = $dbi->execute("select * from $table1"); |
cleanup test
|
576 |
$rows = $result->all; |
test cleanup in progress
|
577 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic"); |
cleanup test
|
578 | |
added tests
|
579 |
eval { $dbi->execute("drop table $table1") }; |
580 |
$dbi->execute($create_table1); |
|
581 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
|
582 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
583 |
$result = $dbi->execute("select * from $table1"); |
|
584 |
$rows = $result->all; |
|
585 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic"); |
|
586 | ||
finishied sqlite test cleanu...
|
587 |
$dbi->execute("delete from $table1"); |
cleanup test
|
588 |
$dbi->register_filter( |
cleanup
|
589 |
twice => sub { $_[0] * 2 }, |
590 |
three_times => sub { $_[0] * 3 } |
|
cleanup test
|
591 |
); |
592 |
$dbi->default_bind_filter('twice'); |
|
test cleanup
|
593 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'}); |
cleanup test
|
594 |
$result = $dbi->execute("select * from $table1"); |
cleanup test
|
595 |
$rows = $result->all; |
test cleanup in progress
|
596 |
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter"); |
- fixed bug that DBIx::Custo...
|
597 |
$dbi->delete_all(table => $table1); |
598 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
|
599 |
$result = $dbi->execute("select * from $table1"); |
|
600 |
$rows = $result->all; |
|
601 |
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter"); |
|
cleanup test
|
602 |
$dbi->default_bind_filter(undef); |
603 | ||
- fixed bug that DBIx::Custo...
|
604 | |
added EXPERIMENTAL reuse_sth...
|
605 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
606 |
$dbi->execute($create_table1); |
test cleanup
|
607 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, append => ' '); |
test cleanup in progress
|
608 |
$rows = $dbi->select(table => $table1)->all; |
609 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}], 'insert append'); |
|
cleanup test
|
610 | |
test cleanup
|
611 |
eval{$dbi->insert({';' => 1}, table => 'table')}; |
cleanup test
|
612 |
like($@, qr/safety/); |
613 | ||
cleanup test
|
614 |
eval { $dbi->execute("drop table ${q}table$p") }; |
test cleanup
|
615 |
$dbi->execute($create_table_reserved); |
cleanup test
|
616 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
test cleanup
|
617 |
$dbi->insert({select => 1}, table => 'table'); |
cleanup test
|
618 |
$result = $dbi->execute("select * from ${q}table$p"); |
cleanup test
|
619 |
$rows = $result->all; |
test cleanup
|
620 |
is_deeply($rows, [{select => 2, update => undef}], "reserved word"); |
cleanup test
|
621 | |
finishied sqlite test cleanu...
|
622 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
623 |
$dbi->execute($create_table1); |
test cleanup in progress
|
624 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
625 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
cleanup test
|
626 |
$result = $dbi->execute("select * from $table1"); |
cleanup test
|
627 |
$rows = $result->all; |
test cleanup in progress
|
628 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic"); |
cleanup test
|
629 | |
finishied sqlite test cleanu...
|
630 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
631 |
$dbi->execute($create_table1); |
test cleanup
|
632 |
$dbi->insert({$key1 => \"'1'", $key2 => 2}, table => $table1); |
633 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
cleanup test
|
634 |
$result = $dbi->execute("select * from $table1"); |
cleanup test
|
635 |
$rows = $result->all; |
test cleanup in progress
|
636 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic"); |
cleanup test
|
637 | |
updated pod
|
638 |
eval { $dbi->execute("drop table $table1") }; |
639 |
$dbi->execute($create_table1); |
|
test cleanup
|
640 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, |
cleanup
|
641 |
wrap => {$key1 => sub { "$_[0] - 1" }}); |
test cleanup
|
642 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
updated pod
|
643 |
$result = $dbi->execute("select * from $table1"); |
644 |
$rows = $result->all; |
|
645 |
is_deeply($rows, [{$key1 => 0, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic"); |
|
646 | ||
- added EXPERIMENTAL timesta...
|
647 |
eval { $dbi->execute("drop table $table1") }; |
648 |
$dbi->execute($create_table1); |
|
- added EXPERIMENTAL update_...
|
649 |
$dbi->insert_timestamp( |
cleanup
|
650 |
$key1 => '5' |
- added EXPERIMENTAL update_...
|
651 |
); |
test cleanup
|
652 |
$dbi->insert({$key2 => 2}, table => $table1, timestamp => 1); |
- added EXPERIMENTAL timesta...
|
653 |
$result = $dbi->execute("select * from $table1"); |
654 |
$rows = $result->all; |
|
655 |
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic"); |
|
656 | ||
- added EXPERIMENTAL update_...
|
657 |
eval { $dbi->execute("drop table $table1") }; |
658 |
$dbi->execute($create_table1); |
|
659 |
$dbi->insert_timestamp( |
|
cleanup
|
660 |
[$key1, $key2] => sub { 5 } |
- added EXPERIMENTAL update_...
|
661 |
); |
662 |
$dbi->insert(table => $table1, timestamp => 1); |
|
663 |
$result = $dbi->execute("select * from $table1"); |
|
664 |
$rows = $result->all; |
|
665 |
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic"); |
|
666 | ||
667 |
eval { $dbi->execute("drop table $table1") }; |
|
668 |
$dbi->execute($create_table1); |
|
669 |
$dbi->insert_timestamp( |
|
cleanup
|
670 |
[$key1, $key2] => sub { "" . DBIx::Custom->new } |
- added EXPERIMENTAL update_...
|
671 |
); |
672 |
$dbi->insert(table => $table1, timestamp => 1); |
|
673 |
$result = $dbi->execute("select * from $table1"); |
|
674 |
$rows = $result->all; |
|
675 |
is($rows->[0]->{$key1}, $rows->[0]->{$key2}); |
|
676 | ||
added EXPERIMENTAL insert cr...
|
677 |
eval { $dbi->execute("drop table $table1") }; |
678 |
$dbi->execute($create_table1_2); |
|
679 |
$param = {$key1 => 1}; |
|
test cleanup
|
680 |
$dbi->insert($param, table => $table1, created_at => $key2); |
added EXPERIMENTAL insert cr...
|
681 |
$result = $dbi->select(table => $table1); |
682 |
is_deeply($param, {$key1 => 1}); |
|
683 |
$row = $result->one; |
|
684 |
is($row->{$key1}, 1); |
|
685 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
686 | ||
- "created_at" option is ren...
|
687 |
eval { $dbi->execute("drop table $table1") }; |
688 |
$dbi->execute($create_table1_2); |
|
689 |
$param = {$key1 => 1}; |
|
690 |
$dbi->insert($param, table => $table1, ctime => $key2); |
|
691 |
$result = $dbi->select(table => $table1); |
|
692 |
is_deeply($param, {$key1 => 1}); |
|
693 |
$row = $result->one; |
|
694 |
is($row->{$key1}, 1); |
|
695 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
696 | ||
added EXPERIMENTAL insert cr...
|
697 |
eval { $dbi->execute("drop table $table1") }; |
698 |
$dbi->execute($create_table1_2); |
|
699 |
$param = {$key1 => 1}; |
|
test cleanup
|
700 |
$dbi->insert($param, table => $table1, updated_at => $key3); |
added EXPERIMENTAL insert cr...
|
701 |
$result = $dbi->select(table => $table1); |
702 |
is_deeply($param, {$key1 => 1}); |
|
703 |
$row = $result->one; |
|
704 |
is($row->{$key1}, 1); |
|
705 |
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
706 | ||
- "created_at" option is ren...
|
707 |
eval { $dbi->execute("drop table $table1") }; |
708 |
$dbi->execute($create_table1_2); |
|
709 |
$param = {$key1 => 1}; |
|
710 |
$dbi->insert($param, table => $table1, mtime => $key3); |
|
711 |
$result = $dbi->select(table => $table1); |
|
712 |
is_deeply($param, {$key1 => 1}); |
|
713 |
$row = $result->one; |
|
714 |
is($row->{$key1}, 1); |
|
715 |
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
716 | ||
added EXPERIMENTAL insert cr...
|
717 |
eval { $dbi->execute("drop table $table1") }; |
718 |
$dbi->execute($create_table1_2); |
|
719 |
$param = {$key1 => 1}; |
|
test cleanup
|
720 |
$dbi->insert($param, table => $table1, created_at => $key2, updated_at => $key3); |
added EXPERIMENTAL insert cr...
|
721 |
$result = $dbi->select(table => $table1); |
722 |
is_deeply($param, {$key1 => 1}); |
|
723 |
$row = $result->one; |
|
724 |
is($row->{$key1}, 1); |
|
725 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
726 |
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
727 |
is($row->{$key2}, $row->{$key3}); |
|
728 | ||
- "created_at" option is ren...
|
729 |
eval { $dbi->execute("drop table $table1") }; |
730 |
$dbi->execute($create_table1_2); |
|
731 |
$param = {$key1 => 1}; |
|
732 |
$dbi->insert($param, table => $table1, created_at => $key2, mtime => $key3); |
|
733 |
$result = $dbi->select(table => $table1); |
|
734 |
is_deeply($param, {$key1 => 1}); |
|
735 |
$row = $result->one; |
|
736 |
is($row->{$key1}, 1); |
|
737 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
738 |
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
739 |
is($row->{$key2}, $row->{$key3}); |
|
740 | ||
741 |
eval { $dbi->execute("drop table $table1") }; |
|
742 |
$dbi->execute($create_table1_2); |
|
743 |
$param = {$key1 => 1}; |
|
744 |
$dbi->insert($param, table => $table1, ctime => $key2, updated_at => $key3); |
|
745 |
$result = $dbi->select(table => $table1); |
|
746 |
is_deeply($param, {$key1 => 1}); |
|
747 |
$row = $result->one; |
|
748 |
is($row->{$key1}, 1); |
|
749 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
750 |
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
751 |
is($row->{$key2}, $row->{$key3}); |
|
752 | ||
753 |
eval { $dbi->execute("drop table $table1") }; |
|
754 |
$dbi->execute($create_table1_2); |
|
755 |
$param = {$key1 => 1}; |
|
756 |
$dbi->insert($param, table => $table1, ctime => $key2, mtime => $key3); |
|
757 |
$result = $dbi->select(table => $table1); |
|
758 |
is_deeply($param, {$key1 => 1}); |
|
759 |
$row = $result->one; |
|
760 |
is($row->{$key1}, 1); |
|
761 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
762 |
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
763 |
is($row->{$key2}, $row->{$key3}); |
|
764 | ||
added EXPERIMENTAL DBIx::Cus...
|
765 |
eval { $dbi->execute("drop table $table1") }; |
766 |
$dbi->execute($create_table1_2); |
|
767 |
$model = $dbi->create_model(table => $table1, created_at => $key2); |
|
768 |
$param = {$key1 => 1}; |
|
769 |
$model->insert($param); |
|
770 |
$result = $dbi->select(table => $table1); |
|
771 |
is_deeply($param, {$key1 => 1}); |
|
772 |
$row = $result->one; |
|
773 |
is($row->{$key1}, 1); |
|
774 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
775 | ||
- "created_at" option is ren...
|
776 |
eval { $dbi->execute("drop table $table1") }; |
777 |
$dbi->execute($create_table1_2); |
|
778 |
$model = $dbi->create_model(table => $table1, ctime => $key2); |
|
779 |
$param = {$key1 => 1}; |
|
780 |
$model->insert($param); |
|
781 |
$result = $dbi->select(table => $table1); |
|
782 |
is_deeply($param, {$key1 => 1}); |
|
783 |
$row = $result->one; |
|
784 |
is($row->{$key1}, 1); |
|
785 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
786 | ||
added EXPERIMENTAL DBIx::Cus...
|
787 |
eval { $dbi->execute("drop table $table1") }; |
788 |
$dbi->execute($create_table1_2); |
|
789 |
$param = {$key1 => 1}; |
|
790 |
$model = $dbi->create_model(table => $table1, updated_at => $key3); |
|
791 |
$model->insert($param); |
|
792 |
$result = $dbi->select(table => $table1); |
|
793 |
is_deeply($param, {$key1 => 1}); |
|
794 |
$row = $result->one; |
|
795 |
is($row->{$key1}, 1); |
|
796 |
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
797 | ||
- "created_at" option is ren...
|
798 |
eval { $dbi->execute("drop table $table1") }; |
799 |
$dbi->execute($create_table1_2); |
|
800 |
$param = {$key1 => 1}; |
|
801 |
$model = $dbi->create_model(table => $table1, mtime => $key3); |
|
802 |
$model->insert($param); |
|
803 |
$result = $dbi->select(table => $table1); |
|
804 |
is_deeply($param, {$key1 => 1}); |
|
805 |
$row = $result->one; |
|
806 |
is($row->{$key1}, 1); |
|
807 |
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
808 | ||
added EXPERIMENTAL DBIx::Cus...
|
809 |
eval { $dbi->execute("drop table $table1") }; |
810 |
$dbi->execute($create_table1_2); |
|
811 |
$param = {$key1 => 1}; |
|
812 |
$model = $dbi->create_model(table => $table1, created_at => $key2, updated_at => $key3); |
|
813 |
$model->insert($param); |
|
814 |
$result = $dbi->select(table => $table1); |
|
815 |
is_deeply($param, {$key1 => 1}); |
|
816 |
$row = $result->one; |
|
817 |
is($row->{$key1}, 1); |
|
818 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
819 |
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
820 |
is($row->{$key2}, $row->{$key3}); |
|
821 | ||
- "created_at" option is ren...
|
822 |
eval { $dbi->execute("drop table $table1") }; |
823 |
$dbi->execute($create_table1_2); |
|
824 |
$param = {$key1 => 1}; |
|
825 |
$model = $dbi->create_model(table => $table1, created_at => $key2, mtime => $key3); |
|
826 |
$model->insert($param); |
|
827 |
$result = $dbi->select(table => $table1); |
|
828 |
is_deeply($param, {$key1 => 1}); |
|
829 |
$row = $result->one; |
|
830 |
is($row->{$key1}, 1); |
|
831 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
832 |
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
833 |
is($row->{$key2}, $row->{$key3}); |
|
834 | ||
835 |
eval { $dbi->execute("drop table $table1") }; |
|
836 |
$dbi->execute($create_table1_2); |
|
837 |
$param = {$key1 => 1}; |
|
838 |
$model = $dbi->create_model(table => $table1, ctime=> $key2, updated_at => $key3); |
|
839 |
$model->insert($param); |
|
840 |
$result = $dbi->select(table => $table1); |
|
841 |
is_deeply($param, {$key1 => 1}); |
|
842 |
$row = $result->one; |
|
843 |
is($row->{$key1}, 1); |
|
844 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
845 |
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
846 |
is($row->{$key2}, $row->{$key3}); |
|
847 | ||
848 |
eval { $dbi->execute("drop table $table1") }; |
|
849 |
$dbi->execute($create_table1_2); |
|
850 |
$param = {$key1 => 1}; |
|
851 |
$model = $dbi->create_model(table => $table1, ctime=> $key2, mtime => $key3); |
|
852 |
$model->insert($param); |
|
853 |
$result = $dbi->select(table => $table1); |
|
854 |
is_deeply($param, {$key1 => 1}); |
|
855 |
$row = $result->one; |
|
856 |
is($row->{$key1}, 1); |
|
857 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
858 |
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
859 |
is($row->{$key2}, $row->{$key3}); |
|
860 | ||
- insert method can receive ...
|
861 |
eval { $dbi->execute("drop table $table1") }; |
862 |
$dbi->execute($create_table1); |
|
863 |
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] , table => $table1); |
|
864 |
$result = $dbi->execute("select * from $table1"); |
|
865 |
$rows = $result->all; |
|
866 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic"); |
|
867 | ||
868 |
eval { $dbi->execute("drop table $table1") }; |
|
869 |
$dbi->execute($create_table1_2); |
|
870 |
$dbi->insert([{$key1 => 1}, {$key1 => 3}] , |
|
- "created_at" option is ren...
|
871 |
table => $table1, |
872 |
updated_at => $key2, |
|
873 |
created_at => $key3 |
|
874 |
); |
|
875 |
$result = $dbi->execute("select * from $table1"); |
|
876 |
$rows = $result->all; |
|
877 |
is($rows->[0]->{$key1}, 1); |
|
878 |
is($rows->[1]->{$key1}, 3); |
|
879 |
like($rows->[0]->{$key2}, qr/\d{2}:/); |
|
880 |
like($rows->[1]->{$key2}, qr/\d{2}:/); |
|
881 |
like($rows->[0]->{$key3}, qr/\d{2}:/); |
|
882 |
like($rows->[1]->{$key3}, qr/\d{2}:/); |
|
883 | ||
884 |
eval { $dbi->execute("drop table $table1") }; |
|
885 |
$dbi->execute($create_table1_2); |
|
886 |
$dbi->insert([{$key1 => 1}, {$key1 => 3}] , |
|
887 |
table => $table1, |
|
888 |
mtime => $key2, |
|
889 |
ctime => $key3 |
|
- insert method can receive ...
|
890 |
); |
891 |
$result = $dbi->execute("select * from $table1"); |
|
892 |
$rows = $result->all; |
|
893 |
is($rows->[0]->{$key1}, 1); |
|
894 |
is($rows->[1]->{$key1}, 3); |
|
895 |
like($rows->[0]->{$key2}, qr/\d{2}:/); |
|
896 |
like($rows->[1]->{$key2}, qr/\d{2}:/); |
|
897 |
like($rows->[0]->{$key3}, qr/\d{2}:/); |
|
898 |
like($rows->[1]->{$key3}, qr/\d{2}:/); |
|
899 | ||
900 |
eval { $dbi->execute("drop table $table1") }; |
|
901 |
$dbi->execute($create_table1); |
|
902 |
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] , |
|
cleanup
|
903 |
table => $table1, filter => {$key1 => sub { $_[0] * 2 }}); |
- insert method can receive ...
|
904 |
$result = $dbi->execute("select * from $table1"); |
905 |
$rows = $result->all; |
|
906 |
is_deeply($rows, [{$key1 => 2, $key2 => 2}, {$key1 => 6, $key2 => 4}], "basic"); |
|
907 | ||
- removed DEPRECATED status ...
|
908 |
test 'update_or_insert'; |
909 |
eval { $dbi->execute("drop table $table1") }; |
|
910 |
$dbi->execute($create_table1); |
|
911 |
$dbi->update_or_insert( |
|
cleanup
|
912 |
{$key2 => 2}, |
913 |
table => $table1, |
|
914 |
primary_key => $key1, |
|
915 |
id => 1 |
|
- removed DEPRECATED status ...
|
916 |
); |
917 |
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one; |
|
918 |
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic"); |
|
919 | ||
920 |
$dbi->update_or_insert( |
|
cleanup
|
921 |
{$key2 => 3}, |
922 |
table => $table1, |
|
923 |
primary_key => $key1, |
|
924 |
id => 1 |
|
- removed DEPRECATED status ...
|
925 |
); |
926 |
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all; |
|
927 |
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic"); |
|
928 | ||
- EXPERIMENTAL update_or_ins...
|
929 |
eval { |
cleanup
|
930 |
$dbi->update_or_insert( |
931 |
{$key2 => 3}, |
|
932 |
table => $table1, |
|
933 |
); |
|
- EXPERIMENTAL update_or_ins...
|
934 |
}; |
935 | ||
936 |
like($@, qr/primary_key/); |
|
- removed DEPRECATED status ...
|
937 | |
- id option work if id count...
|
938 |
eval { |
cleanup
|
939 |
$dbi->insert({$key1 => 1}, table => $table1); |
940 |
$dbi->update_or_insert( |
|
941 |
{$key2 => 3}, |
|
942 |
table => $table1, |
|
943 |
primary_key => $key1, |
|
944 |
id => 1 |
|
945 |
); |
|
- id option work if id count...
|
946 |
}; |
947 |
like($@, qr/one/); |
|
948 | ||
- fixed update_or_insert bug...
|
949 |
eval { $dbi->execute("drop table $table1") }; |
950 |
$dbi->execute($create_table1); |
|
951 |
$dbi->update_or_insert( |
|
cleanup
|
952 |
{}, |
953 |
table => $table1, |
|
954 |
primary_key => $key1, |
|
955 |
id => 1 |
|
- fixed update_or_insert bug...
|
956 |
); |
957 |
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one; |
|
958 |
is($row->{$key1}, 1); |
|
959 | ||
960 |
eval { |
|
cleanup
|
961 |
$affected = $dbi->update_or_insert( |
962 |
{}, |
|
963 |
table => $table1, |
|
964 |
primary_key => $key1, |
|
965 |
id => 1 |
|
966 |
); |
|
- fixed update_or_insert bug...
|
967 |
}; |
968 |
is($affected, 0); |
|
969 | ||
micro optimization
|
970 |
test 'model update_or_insert'; |
971 |
eval { $dbi->execute("drop table $table1") }; |
|
972 |
$dbi->execute($create_table1); |
|
973 |
$model = $dbi->create_model( |
|
cleanup
|
974 |
table => $table1, |
975 |
primary_key => $key1 |
|
micro optimization
|
976 |
); |
977 |
$model->update_or_insert({$key2 => 2}, id => 1); |
|
978 |
$row = $model->select(id => 1)->one; |
|
979 |
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic"); |
|
980 | ||
- id option work if id count...
|
981 |
eval { |
cleanup
|
982 |
$model->insert({$key1 => 1}); |
983 |
$model->update_or_insert( |
|
984 |
{$key2 => 3}, |
|
985 |
id => 1 |
|
986 |
); |
|
- id option work if id count...
|
987 |
}; |
988 |
like($@, qr/one/); |
|
989 | ||
- removed DEPRECATED status ...
|
990 |
test 'default_bind_filter'; |
991 |
$dbi->execute("delete from $table1"); |
|
992 |
$dbi->register_filter( |
|
cleanup
|
993 |
twice => sub { $_[0] * 2 }, |
994 |
three_times => sub { $_[0] * 3 } |
|
- removed DEPRECATED status ...
|
995 |
); |
996 |
$dbi->default_bind_filter('twice'); |
|
cleanup
|
997 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'}); |
- removed DEPRECATED status ...
|
998 |
$result = $dbi->execute("select * from $table1"); |
999 |
$rows = $result->all; |
|
1000 |
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter"); |
|
1001 |
$dbi->default_bind_filter(undef); |
|
1002 | ||
test cleanup
|
1003 |
test 'update'; |
finishied sqlite test cleanu...
|
1004 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1005 |
$dbi->execute($create_table1_2); |
test cleanup
|
1006 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
1007 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
cleanup
|
1008 |
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1}); |
cleanup test
|
1009 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
test cleanup
|
1010 |
$rows = $result->all; |
test cleanup in progress
|
1011 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
cleanup
|
1012 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
1013 |
"basic"); |
|
added tests
|
1014 | |
1015 |
eval { $dbi->execute("drop table $table1") }; |
|
1016 |
$dbi->execute($create_table1_2); |
|
1017 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
|
1018 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
1019 |
$dbi->update(param => {$key2 => 11}, table => $table1, where => {$key1 => 1}); |
|
1020 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
|
1021 |
$rows = $result->all; |
|
1022 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
|
cleanup
|
1023 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
1024 |
"basic"); |
|
1025 |
|
|
test cleanup in progress
|
1026 |
$dbi->execute("delete from $table1"); |
test cleanup
|
1027 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
1028 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
cleanup
|
1029 |
$dbi->update({$key2 => 12}, table => $table1, where => {$key2 => 2, $key3 => 3}); |
cleanup test
|
1030 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
test cleanup
|
1031 |
$rows = $result->all; |
test cleanup in progress
|
1032 |
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5}, |
cleanup
|
1033 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
1034 |
"update key same as search key"); |
|
test cleanup
|
1035 | |
cleanup
|
1036 |
$dbi->update({$key2 => [12]}, table => $table1, where => {$key2 => 2, $key3 => 3}); |
cleanup test
|
1037 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
test cleanup
|
1038 |
$rows = $result->all; |
test cleanup in progress
|
1039 |
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5}, |
cleanup
|
1040 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
1041 |
"update key same as search key : param is array ref"); |
|
test cleanup
|
1042 | |
test cleanup in progress
|
1043 |
$dbi->execute("delete from $table1"); |
test cleanup
|
1044 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
1045 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
test cleanup
|
1046 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
cleanup
|
1047 |
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1}, |
cleanup
|
1048 |
filter => {$key2 => sub { $_[0] * 2 }}); |
cleanup test
|
1049 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
test cleanup
|
1050 |
$rows = $result->all; |
test cleanup in progress
|
1051 |
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5}, |
cleanup
|
1052 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
1053 |
"filter"); |
|
test cleanup
|
1054 | |
cleanup
|
1055 |
$result = $dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1}, append => ' '); |
test cleanup
|
1056 | |
test cleanup in progress
|
1057 |
eval{$dbi->update(table => $table1)}; |
test cleanup
|
1058 |
like($@, qr/where/, "not contain where"); |
1059 | ||
finishied sqlite test cleanu...
|
1060 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1061 |
$dbi->execute($create_table1); |
test cleanup
|
1062 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
test cleanup
|
1063 |
$where = $dbi->where; |
test cleanup in progress
|
1064 |
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]); |
1065 |
$where->param({$key1 => 1, $key2 => 2}); |
|
cleanup
|
1066 |
$dbi->update({$key1 => 3}, table => $table1, where => $where); |
test cleanup in progress
|
1067 |
$result = $dbi->select(table => $table1); |
1068 |
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where'); |
|
test cleanup
|
1069 | |
finishied sqlite test cleanu...
|
1070 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1071 |
$dbi->execute($create_table1); |
test cleanup
|
1072 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
test cleanup
|
1073 |
$dbi->update( |
cleanup
|
1074 |
{$key1 => 3}, |
1075 |
table => $table1, |
|
1076 |
where => [ |
|
1077 |
['and', "$key1 = :$key1", "$key2 = :$key2"], |
|
1078 |
{$key1 => 1, $key2 => 2} |
|
1079 |
] |
|
test cleanup
|
1080 |
); |
test cleanup in progress
|
1081 |
$result = $dbi->select(table => $table1); |
1082 |
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where'); |
|
test cleanup
|
1083 | |
finishied sqlite test cleanu...
|
1084 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1085 |
$dbi->execute($create_table1); |
test cleanup
|
1086 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
test cleanup
|
1087 |
$where = $dbi->where; |
test cleanup in progress
|
1088 |
$where->clause(['and', "$key2 = :$key2"]); |
1089 |
$where->param({$key2 => 2}); |
|
cleanup
|
1090 |
$dbi->update({$key1 => 3}, table => $table1, where => $where); |
test cleanup in progress
|
1091 |
$result = $dbi->select(table => $table1); |
1092 |
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where'); |
|
test cleanup
|
1093 | |
cleanup
|
1094 |
eval{$dbi->update({';' => 1}, table => $table1, where => {$key1 => 1})}; |
test cleanup
|
1095 |
like($@, qr/safety/); |
1096 | ||
cleanup
|
1097 |
eval{$dbi->update({$key1 => 1}, table => $table1, where => {';' => 1})}; |
test cleanup
|
1098 |
like($@, qr/safety/); |
1099 | ||
finishied sqlite test cleanu...
|
1100 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1101 |
eval { $dbi->execute("drop table ${q}table$p") }; |
test cleanup
|
1102 |
$dbi->execute($create_table_reserved); |
test cleanup
|
1103 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
1104 |
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}}); |
|
cleanup
|
1105 |
$dbi->insert({select => 1}, table => 'table'); |
1106 |
$dbi->update({update => 2}, table => 'table', where => {select => 1}); |
|
test cleanup
|
1107 |
$result = $dbi->execute("select * from ${q}table$p"); |
1108 |
$rows = $result->all; |
|
1109 |
is_deeply($rows, [{select => 2, update => 6}], "reserved word"); |
|
1110 | ||
cleanup
|
1111 |
eval {$dbi->update_all({';' => 2}, table => 'table') }; |
test cleanup
|
1112 |
like($@, qr/safety/); |
1113 | ||
1114 |
eval { $dbi->execute("drop table ${q}table$p") }; |
|
test cleanup
|
1115 |
$dbi->execute($create_table_reserved); |
test cleanup
|
1116 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
1117 |
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}}); |
|
cleanup
|
1118 |
$dbi->insert({select => 1}, table => 'table'); |
1119 |
$dbi->update({update => 2}, table => 'table', where => {'table.select' => 1}); |
|
test cleanup
|
1120 |
$result = $dbi->execute("select * from ${q}table$p"); |
1121 |
$rows = $result->all; |
|
1122 |
is_deeply($rows, [{select => 2, update => 6}], "reserved word"); |
|
1123 | ||
finishied sqlite test cleanu...
|
1124 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1125 |
$dbi->execute($create_table1_2); |
test cleanup
|
1126 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
1127 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
test cleanup in progress
|
1128 |
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1}); |
cleanup test
|
1129 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
test cleanup
|
1130 |
$rows = $result->all; |
test cleanup in progress
|
1131 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
cleanup
|
1132 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
1133 |
"basic"); |
|
test cleanup
|
1134 | |
updated pod
|
1135 |
eval { $dbi->execute("drop table $table1") }; |
1136 |
$dbi->execute($create_table1_2); |
|
test cleanup
|
1137 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
1138 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
cleanup
|
1139 |
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1}, |
updated pod
|
1140 |
wrap => {$key2 => sub { "$_[0] - 1" }}); |
1141 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
|
1142 |
$rows = $result->all; |
|
1143 |
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5}, |
|
cleanup
|
1144 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
1145 |
"basic"); |
|
updated pod
|
1146 | |
finishied sqlite test cleanu...
|
1147 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1148 |
$dbi->execute($create_table1_2); |
test cleanup
|
1149 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
1150 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
cleanup
|
1151 |
$dbi->update({$key2 => \"'11'"}, table => $table1, where => {$key1 => 1}); |
cleanup test
|
1152 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
test cleanup
|
1153 |
$rows = $result->all; |
test cleanup in progress
|
1154 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
cleanup
|
1155 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
1156 |
"basic"); |
|
test cleanup
|
1157 | |
- added EXPERIMENTAL timesta...
|
1158 |
eval { $dbi->execute("drop table $table1") }; |
1159 |
$dbi->execute($create_table1); |
|
- added EXPERIMENTAL update_...
|
1160 |
$dbi->update_timestamp( |
cleanup
|
1161 |
$key1 => '5' |
- added EXPERIMENTAL update_...
|
1162 |
); |
test cleanup
|
1163 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
- added EXPERIMENTAL timesta...
|
1164 |
$dbi->update(table => $table1, timestamp => 1, where => {$key2 => 2}); |
1165 |
$result = $dbi->execute("select * from $table1"); |
|
1166 |
$rows = $result->all; |
|
1167 |
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic"); |
|
1168 | ||
- added EXPERIMENTAL update_...
|
1169 |
eval { $dbi->execute("drop table $table1") }; |
1170 |
$dbi->execute($create_table1); |
|
1171 |
$dbi->update_timestamp( |
|
cleanup
|
1172 |
[$key1, $key2] => sub { '5' } |
- added EXPERIMENTAL update_...
|
1173 |
); |
test cleanup
|
1174 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
- added EXPERIMENTAL update_...
|
1175 |
$dbi->update_all(table => $table1, timestamp => 1); |
1176 |
$result = $dbi->execute("select * from $table1"); |
|
1177 |
$rows = $result->all; |
|
1178 |
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic"); |
|
1179 | ||
1180 |
eval { $dbi->execute("drop table $table1") }; |
|
1181 |
$dbi->execute($create_table1); |
|
1182 |
$dbi->update_timestamp( |
|
cleanup
|
1183 |
[$key1, $key2] => sub { "" . DBIx::Custom->new } |
- added EXPERIMENTAL update_...
|
1184 |
); |
test cleanup
|
1185 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
- added EXPERIMENTAL update_...
|
1186 |
$dbi->update_all(table => $table1, timestamp => 1); |
1187 |
$result = $dbi->execute("select * from $table1"); |
|
1188 |
$rows = $result->all; |
|
1189 |
is($rows->[0]->{$key1}, $rows->[0]->{$key2}); |
|
1190 | ||
micro optimization and
|
1191 |
eval { $dbi->execute("drop table $table1") }; |
1192 |
$dbi->execute($create_table1_2); |
|
test cleanup
|
1193 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
1194 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
micro optimization and
|
1195 |
$param = {$key2 => 11}; |
1196 |
$dbi->update($param, table => $table1, where => {$key1 => 1}); |
|
1197 |
is_deeply($param, {$key2 => 11}); |
|
1198 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
|
1199 |
$rows = $result->all; |
|
1200 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
|
cleanup
|
1201 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
1202 |
"basic"); |
|
micro optimization and
|
1203 | |
1204 |
eval { $dbi->execute("drop table $table1") }; |
|
1205 |
$dbi->execute($create_table1_2); |
|
test cleanup
|
1206 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
1207 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
micro optimization and
|
1208 |
$param = {$key2 => 11}; |
1209 |
$dbi->update($param, table => $table1, where => {$key2 => 2}); |
|
1210 |
is_deeply($param, {$key2 => 11}); |
|
1211 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
|
1212 |
$rows = $result->all; |
|
1213 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
|
cleanup
|
1214 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
1215 |
"basic"); |
|
micro optimization and
|
1216 | |
added EXPERIMENTAL insert cr...
|
1217 |
eval { $dbi->execute("drop table $table1") }; |
1218 |
$dbi->execute($create_table1_2); |
|
1219 |
$param = {$key3 => 4}; |
|
cleanup
|
1220 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
1221 |
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key1 => 1}); |
|
added EXPERIMENTAL insert cr...
|
1222 |
$result = $dbi->select(table => $table1); |
1223 |
is_deeply($param, {$key3 => 4}); |
|
1224 |
$row = $result->one; |
|
1225 |
is($row->{$key3}, 4); |
|
1226 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
1227 | ||
- "created_at" option is ren...
|
1228 |
eval { $dbi->execute("drop table $table1") }; |
1229 |
$dbi->execute($create_table1_2); |
|
1230 |
$param = {$key3 => 4}; |
|
1231 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
|
1232 |
$dbi->update($param, table => $table1, mtime => $key2, where => {$key1 => 1}); |
|
1233 |
$result = $dbi->select(table => $table1); |
|
1234 |
is_deeply($param, {$key3 => 4}); |
|
1235 |
$row = $result->one; |
|
1236 |
is($row->{$key3}, 4); |
|
1237 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
1238 | ||
added EXPERIMENTAL insert cr...
|
1239 |
eval { $dbi->execute("drop table $table1") }; |
1240 |
$dbi->execute($create_table1_2); |
|
1241 |
$param = {$key3 => 4}; |
|
cleanup
|
1242 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
1243 |
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key3 => 3}); |
|
added EXPERIMENTAL insert cr...
|
1244 |
$result = $dbi->select(table => $table1); |
1245 |
is_deeply($param, {$key3 => 4}); |
|
1246 |
$row = $result->one; |
|
1247 |
is($row->{$key3}, 4); |
|
1248 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
1249 | ||
- "created_at" option is ren...
|
1250 |
eval { $dbi->execute("drop table $table1") }; |
1251 |
$dbi->execute($create_table1_2); |
|
1252 |
$param = {$key3 => 4}; |
|
1253 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
|
1254 |
$dbi->update($param, table => $table1, mtime => $key2, where => {$key3 => 3}); |
|
1255 |
$result = $dbi->select(table => $table1); |
|
1256 |
is_deeply($param, {$key3 => 4}); |
|
1257 |
$row = $result->one; |
|
1258 |
is($row->{$key3}, 4); |
|
1259 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
1260 | ||
added EXPERIMENTAL DBIx::Cus...
|
1261 |
eval { $dbi->execute("drop table $table1") }; |
1262 |
$dbi->execute($create_table1_2); |
|
1263 |
$model = $dbi->create_model(table => $table1, updated_at => $key2); |
|
1264 |
$param = {$key3 => 4}; |
|
cleanup
|
1265 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
added EXPERIMENTAL DBIx::Cus...
|
1266 |
$model->update($param, where => {$key1 => 1}); |
1267 |
$result = $dbi->select(table => $table1); |
|
1268 |
is_deeply($param, {$key3 => 4}); |
|
1269 |
$row = $result->one; |
|
1270 |
is($row->{$key3}, 4); |
|
1271 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
1272 | ||
- "created_at" option is ren...
|
1273 |
eval { $dbi->execute("drop table $table1") }; |
1274 |
$dbi->execute($create_table1_2); |
|
1275 |
$model = $dbi->create_model(table => $table1, mtime => $key2); |
|
1276 |
$param = {$key3 => 4}; |
|
1277 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
|
1278 |
$model->update($param, where => {$key1 => 1}); |
|
1279 |
$result = $dbi->select(table => $table1); |
|
1280 |
is_deeply($param, {$key3 => 4}); |
|
1281 |
$row = $result->one; |
|
1282 |
is($row->{$key3}, 4); |
|
1283 |
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); |
|
1284 | ||
test cleanup
|
1285 |
test 'update_all'; |
finishied sqlite test cleanu...
|
1286 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1287 |
$dbi->execute($create_table1_2); |
test cleanup
|
1288 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
1289 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
test cleanup
|
1290 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
cleanup
|
1291 |
$dbi->update_all({$key2 => 10}, table => $table1, filter => {$key2 => 'twice'}); |
cleanup test
|
1292 |
$result = $dbi->execute("select * from $table1"); |
test cleanup
|
1293 |
$rows = $result->all; |
test cleanup in progress
|
1294 |
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5}, |
cleanup
|
1295 |
{$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}], |
1296 |
"filter"); |
|
test cleanup
|
1297 | |
1298 |
test 'delete'; |
|
finishied sqlite test cleanu...
|
1299 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1300 |
$dbi->execute($create_table1); |
test cleanup
|
1301 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
1302 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup in progress
|
1303 |
$dbi->delete(table => $table1, where => {$key1 => 1}); |
cleanup test
|
1304 |
$result = $dbi->execute("select * from $table1"); |
test cleanup
|
1305 |
$rows = $result->all; |
test cleanup in progress
|
1306 |
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic"); |
test cleanup
|
1307 | |
cleanup test
|
1308 |
$dbi->execute("delete from $table1"); |
test cleanup
|
1309 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
1310 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup
|
1311 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
test cleanup in progress
|
1312 |
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'}); |
cleanup test
|
1313 |
$result = $dbi->execute("select * from $table1"); |
test cleanup
|
1314 |
$rows = $result->all; |
test cleanup in progress
|
1315 |
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter"); |
test cleanup
|
1316 | |
test cleanup in progress
|
1317 |
$dbi->delete(table => $table1, where => {$key1 => 1}, append => ' '); |
test cleanup
|
1318 | |
test cleanup in progress
|
1319 |
$dbi->delete_all(table => $table1); |
test cleanup
|
1320 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
1321 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup in progress
|
1322 |
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2}); |
1323 |
$rows = $dbi->select(table => $table1)->all; |
|
1324 |
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key"); |
|
test cleanup
|
1325 | |
finishied sqlite test cleanu...
|
1326 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1327 |
$dbi->execute($create_table1); |
test cleanup
|
1328 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
1329 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup
|
1330 |
$where = $dbi->where; |
test cleanup in progress
|
1331 |
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]); |
1332 |
$where->param({ke1 => 1, $key2 => 2}); |
|
1333 |
$dbi->delete(table => $table1, where => $where); |
|
1334 |
$result = $dbi->select(table => $table1); |
|
1335 |
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where'); |
|
test cleanup
|
1336 | |
finishied sqlite test cleanu...
|
1337 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1338 |
$dbi->execute($create_table1); |
test cleanup
|
1339 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
1340 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup
|
1341 |
$dbi->delete( |
cleanup
|
1342 |
table => $table1, |
1343 |
where => [ |
|
1344 |
['and', "$key1 = :$key1", "$key2 = :$key2"], |
|
1345 |
{ke1 => 1, $key2 => 2} |
|
1346 |
] |
|
test cleanup
|
1347 |
); |
test cleanup in progress
|
1348 |
$result = $dbi->select(table => $table1); |
1349 |
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where'); |
|
test cleanup
|
1350 | |
finishied sqlite test cleanu...
|
1351 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1352 |
$dbi->execute($create_table1); |
test cleanup
|
1353 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
test cleanup in progress
|
1354 |
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => ' '); |
cleanup test
|
1355 |
$result = $dbi->execute("select * from $table1"); |
test cleanup
|
1356 |
$rows = $result->all; |
1357 |
is_deeply($rows, [], "basic"); |
|
1358 | ||
1359 |
test 'delete error'; |
|
finishied sqlite test cleanu...
|
1360 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1361 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1362 |
eval{$dbi->delete(table => $table1)}; |
cleanup
|
1363 |
like($@, qr/where/, "where key-value pairs not specified"); |
test cleanup
|
1364 | |
test cleanup in progress
|
1365 |
eval{$dbi->delete(table => $table1, where => {';' => 1})}; |
test cleanup
|
1366 |
like($@, qr/safety/); |
1367 | ||
test cleanup
|
1368 |
$dbi = undef; |
test cleanup
|
1369 |
$dbi = DBIx::Custom->connect; |
1370 |
eval { $dbi->execute("drop table ${q}table$p") }; |
|
test cleanup
|
1371 |
$dbi->execute($create_table_reserved); |
test cleanup
|
1372 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
cleanup
|
1373 |
$dbi->insert({select => 1}, table => 'table'); |
test cleanup
|
1374 |
$dbi->delete(table => 'table', where => {select => 1}); |
1375 |
$result = $dbi->execute("select * from ${q}table$p"); |
|
1376 |
$rows = $result->all; |
|
1377 |
is_deeply($rows, [], "reserved word"); |
|
1378 | ||
1379 |
test 'delete_all'; |
|
finishied sqlite test cleanu...
|
1380 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1381 |
$dbi->execute($create_table1); |
test cleanup
|
1382 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
1383 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup in progress
|
1384 |
$dbi->delete_all(table => $table1); |
cleanup test
|
1385 |
$result = $dbi->execute("select * from $table1"); |
test cleanup
|
1386 |
$rows = $result->all; |
1387 |
is_deeply($rows, [], "basic"); |
|
1388 | ||
1389 |
test 'select'; |
|
finishied sqlite test cleanu...
|
1390 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1391 |
$dbi->execute($create_table1); |
test cleanup
|
1392 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
1393 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup in progress
|
1394 |
$rows = $dbi->select(table => $table1)->all; |
1395 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, |
|
cleanup
|
1396 |
{$key1 => 3, $key2 => 4}], "table"); |
test cleanup
|
1397 | |
test cleanup in progress
|
1398 |
$rows = $dbi->select(table => $table1, column => [$key1])->all; |
1399 |
is_deeply($rows, [{$key1 => 1}, {$key1 => 3}], "table and columns and where key"); |
|
test cleanup
|
1400 | |
test cleanup in progress
|
1401 |
$rows = $dbi->select(table => $table1, where => {$key1 => 1})->all; |
1402 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table and columns and where key"); |
|
test cleanup
|
1403 | |
test cleanup in progress
|
1404 |
$rows = $dbi->select(table => $table1, column => [$key1], where => {$key1 => 3})->all; |
1405 |
is_deeply($rows, [{$key1 => 3}], "table and columns and where key"); |
|
test cleanup
|
1406 | |
1407 |
$dbi->register_filter(decrement => sub { $_[0] - 1 }); |
|
test cleanup in progress
|
1408 |
$rows = $dbi->select(table => $table1, where => {$key1 => 2}, filter => {$key1 => 'decrement'}) |
cleanup
|
1409 |
->all; |
test cleanup in progress
|
1410 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "filter"); |
test cleanup
|
1411 | |
test cleanup in progress
|
1412 |
eval { $dbi->execute("drop table $table2") }; |
test cleanup
|
1413 |
$dbi->execute($create_table2); |
cleanup
|
1414 |
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2); |
test cleanup
|
1415 |
$rows = $dbi->select( |
cleanup
|
1416 |
table => [$table1, $table2], |
fixed test
|
1417 |
column => "$table1.$key1 as " . u("${table1}_$key1") |
1418 |
. ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3", |
|
cleanup
|
1419 |
where => {"$table1.$key2" => 2}, |
1420 |
relation => {"$table1.$key1" => "$table2.$key1"} |
|
test cleanup
|
1421 |
)->all; |
fixed test
|
1422 |
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], "relation : exists where"); |
test cleanup
|
1423 | |
1424 |
$rows = $dbi->select( |
|
cleanup
|
1425 |
table => [$table1, $table2], |
fixed test
|
1426 |
column => ["$table1.$key1 as " . u("${table1}_$key1") . ", ${table2}.$key1 as " . u("${table2}_$key1"), $key2, $key3], |
cleanup
|
1427 |
relation => {"$table1.$key1" => "$table2.$key1"} |
test cleanup
|
1428 |
)->all; |
fixed test
|
1429 |
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], "relation : no exists where"); |
test cleanup
|
1430 | |
1431 |
$dbi = DBIx::Custom->connect; |
|
test cleanup
|
1432 |
eval { $dbi->execute("drop table ${q}table$p") }; |
1433 |
$dbi->execute($create_table_reserved); |
|
test cleanup
|
1434 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
cleanup
|
1435 |
$dbi->insert({select => 1, update => 2}, table => 'table'); |
test cleanup
|
1436 |
$result = $dbi->select(table => 'table', where => {select => 1}); |
1437 |
$rows = $result->all; |
|
1438 |
is_deeply($rows, [{select => 2, update => 2}], "reserved word"); |
|
1439 | ||
- select method can receive ...
|
1440 |
eval { $dbi->execute("drop table $table1") }; |
1441 |
$dbi->execute($create_table1); |
|
1442 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
|
1443 |
$row = $dbi->select($key1, table => $table1)->one; |
|
1444 |
is_deeply($row, {$key1 => 1}); |
|
1445 | ||
added tests
|
1446 |
eval { $dbi->select(table => $table1, where => {';' => 1}) }; |
1447 |
like($@, qr/safety/); |
|
1448 | ||
- added where => {name => [v...
|
1449 |
eval { $dbi->execute("drop table $table1") }; |
1450 |
$dbi->execute($create_table1); |
|
1451 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
|
1452 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
1453 |
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1); |
|
1454 | ||
1455 |
$rows = $dbi->select(table => $table1, where => {$key1 => [1, 5]})->all; |
|
1456 |
is_deeply($rows, [ |
|
1457 |
{$key1 => 1, $key2 => 2}, |
|
1458 |
{$key1 => 5, $key2 => 6} |
|
1459 |
], "table"); |
|
1460 | ||
1461 |
$rows = $dbi->select(table => $table1, where => {$key1 => []})->all; |
|
1462 |
is_deeply($rows, [], "table"); |
|
1463 | ||
test cleanup
|
1464 |
test 'fetch filter'; |
finishied sqlite test cleanu...
|
1465 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1466 |
$dbi->register_filter( |
cleanup
|
1467 |
twice => sub { $_[0] * 2 }, |
1468 |
three_times => sub { $_[0] * 3 } |
|
test cleanup
|
1469 |
); |
1470 |
$dbi->default_fetch_filter('twice'); |
|
1471 |
$dbi->execute($create_table1); |
|
test cleanup
|
1472 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
test cleanup in progress
|
1473 |
$result = $dbi->select(table => $table1); |
1474 |
$result->filter({$key1 => 'three_times'}); |
|
test cleanup
|
1475 |
$row = $result->one; |
test cleanup in progress
|
1476 |
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter"); |
test cleanup
|
1477 | |
- fixed bug DBIx::Custom::Re...
|
1478 |
$dbi->default_fetch_filter('twice'); |
1479 |
eval { $dbi->execute("drop table $table1") }; |
|
1480 |
$dbi->execute($create_table1); |
|
1481 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
|
1482 |
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1); |
|
1483 |
$result->filter({$key1 => 'three_times'}); |
|
- renamed DBIx::Custom::Resu...
|
1484 |
$row = $result->fetch_one; |
1485 |
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter"); |
|
1486 | ||
1487 |
test 'fetch_first DEPRECATED!'; |
|
1488 |
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1); |
|
1489 |
$result->filter({$key1 => 'three_times'}); |
|
- fixed bug DBIx::Custom::Re...
|
1490 |
$row = $result->fetch_first; |
1491 |
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter"); |
|
1492 | ||
test cleanup
|
1493 |
test 'filters'; |
1494 |
$dbi = DBIx::Custom->new; |
|
1495 | ||
1496 |
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')), |
|
cleanup
|
1497 |
'あ', "decode_utf8"); |
test cleanup
|
1498 | |
1499 |
is($dbi->filters->{encode_utf8}->('あ'), |
|
cleanup
|
1500 |
encode_utf8('あ'), "encode_utf8"); |
test cleanup
|
1501 | |
cleanup test
|
1502 |
test 'transaction1'; |
test cleanup
|
1503 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
1504 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1505 |
$dbi->execute($create_table1); |
fixed transaction test
|
1506 |
$dbi->begin_work; |
1507 |
$dbi->dbh->{AutoCommit} = 0; |
|
test cleanup
|
1508 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
fixed transaction test
|
1509 |
$dbi->rollback; |
1510 |
$dbi->dbh->{AutoCommit} = 1; |
|
1511 | ||
test cleanup in progress
|
1512 |
$result = $dbi->select(table => $table1); |
- renamed DBIx::Custom::Resu...
|
1513 |
ok(! $result->fetch_one, "rollback"); |
fixed transaction test
|
1514 | |
test cleanup
|
1515 | |
1516 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
1517 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1518 |
$dbi->execute($create_table1); |
fixed transaction test
|
1519 |
$dbi->begin_work; |
1520 |
$dbi->dbh->{AutoCommit} = 0; |
|
test cleanup
|
1521 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
1522 |
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1); |
fixed transaction test
|
1523 |
$dbi->commit; |
1524 |
$dbi->dbh->{AutoCommit} = 1; |
|
test cleanup in progress
|
1525 |
$result = $dbi->select(table => $table1); |
1526 |
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}], |
|
cleanup
|
1527 |
"commit"); |
test cleanup
|
1528 | |
1529 |
test 'execute'; |
|
finishied sqlite test cleanu...
|
1530 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1531 |
$dbi->execute($create_table1); |
1532 |
{ |
|
cleanup
|
1533 |
local $Carp::Verbose = 0; |
1534 |
eval{$dbi->execute("select * frm $table1")}; |
|
1535 |
like($@, qr/\Qselect * frm $table1/, "fail prepare"); |
|
1536 |
like($@, qr/\.t /, "fail : not verbose"); |
|
test cleanup
|
1537 |
} |
1538 |
{ |
|
cleanup
|
1539 |
local $Carp::Verbose = 1; |
1540 |
eval{$dbi->execute("select * frm $table1")}; |
|
1541 |
like($@, qr/Custom.*\.t /s, "fail : verbose"); |
|
test cleanup
|
1542 |
} |
1543 | ||
test cleanup in progress
|
1544 |
$query = $dbi->execute("select * from $table1 where $key1 = :$key1", {}, query => 1); |
test cleanup
|
1545 |
$dbi->dbh->disconnect; |
cleanup
|
1546 |
eval{$dbi->execute($query, {$key1 => {a => 1}})}; |
test cleanup
|
1547 |
ok($@, "execute fail"); |
1548 | ||
1549 |
{ |
|
cleanup
|
1550 |
local $Carp::Verbose = 0; |
1551 |
eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)}; |
|
1552 |
like($@, qr/\Q.t /, "caller spec : not vebose"); |
|
test cleanup
|
1553 |
} |
1554 |
{ |
|
cleanup
|
1555 |
local $Carp::Verbose = 1; |
1556 |
eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)}; |
|
1557 |
like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose"); |
|
test cleanup
|
1558 |
} |
1559 | ||
1560 | ||
cleanup test
|
1561 |
test 'transaction2'; |
test cleanup
|
1562 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
1563 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1564 |
$dbi->execute($create_table1); |
1565 | ||
1566 |
$dbi->begin_work; |
|
1567 | ||
1568 |
eval { |
|
cleanup
|
1569 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
1570 |
die "Error"; |
|
1571 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup
|
1572 |
}; |
1573 | ||
1574 |
$dbi->rollback if $@; |
|
1575 | ||
test cleanup in progress
|
1576 |
$result = $dbi->select(table => $table1); |
test cleanup
|
1577 |
$rows = $result->all; |
1578 |
is_deeply($rows, [], "rollback"); |
|
1579 | ||
1580 |
$dbi->begin_work; |
|
1581 | ||
1582 |
eval { |
|
cleanup
|
1583 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
1584 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup
|
1585 |
}; |
1586 | ||
1587 |
$dbi->commit unless $@; |
|
1588 | ||
test cleanup in progress
|
1589 |
$result = $dbi->select(table => $table1); |
test cleanup
|
1590 |
$rows = $result->all; |
test cleanup in progress
|
1591 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "commit"); |
test cleanup
|
1592 | |
1593 |
$dbi->dbh->{AutoCommit} = 0; |
|
1594 |
eval{ $dbi->begin_work }; |
|
1595 |
ok($@, "exception"); |
|
1596 |
$dbi->dbh->{AutoCommit} = 1; |
|
added EXPERIMENTAL DBIx::Cus...
|
1597 | |
test cleanup
|
1598 |
test 'cache'; |
finishied sqlite test cleanu...
|
1599 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1600 |
$dbi->cache(1); |
1601 |
$dbi->execute($create_table1); |
|
cleanup test
|
1602 |
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2"; |
test cleanup
|
1603 |
$dbi->execute($source, {}, query => 1); |
1604 |
is_deeply($dbi->{_cached}->{$source}, |
|
cleanup
|
1605 |
{sql => " select * from $table1 where $key1 = ? and $key2 = ? ", columns => [$key1, $key2], tables => []}, "cache"); |
test cleanup
|
1606 | |
finishied sqlite test cleanu...
|
1607 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1608 |
$dbi->execute($create_table1); |
1609 |
$dbi->{_cached} = {}; |
|
1610 |
$dbi->cache(0); |
|
test cleanup
|
1611 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
test cleanup
|
1612 |
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache'); |
1613 | ||
1614 |
test 'execute'; |
|
finishied sqlite test cleanu...
|
1615 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1616 |
$dbi->execute($create_table1); |
1617 |
{ |
|
cleanup
|
1618 |
local $Carp::Verbose = 0; |
1619 |
eval{$dbi->execute("select * frm $table1")}; |
|
1620 |
like($@, qr/\Qselect * frm $table1/, "fail prepare"); |
|
1621 |
like($@, qr/\.t /, "fail : not verbose"); |
|
test cleanup
|
1622 |
} |
1623 |
{ |
|
cleanup
|
1624 |
local $Carp::Verbose = 1; |
1625 |
eval{$dbi->execute("select * frm $table1")}; |
|
1626 |
like($@, qr/Custom.*\.t /s, "fail : verbose"); |
|
test cleanup
|
1627 |
} |
1628 | ||
test cleanup in progress
|
1629 |
$query = $dbi->execute("select * from $table1 where $key1 = :$key1", {}, query => 1); |
test cleanup
|
1630 |
$dbi->dbh->disconnect; |
cleanup
|
1631 |
eval{$dbi->execute($query, {$key1 => {a => 1}})}; |
test cleanup
|
1632 |
ok($@, "execute fail"); |
1633 | ||
1634 |
{ |
|
cleanup
|
1635 |
local $Carp::Verbose = 0; |
1636 |
eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)}; |
|
1637 |
like($@, qr/\Q.t /, "caller spec : not vebose"); |
|
test cleanup
|
1638 |
} |
1639 |
{ |
|
cleanup
|
1640 |
local $Carp::Verbose = 1; |
1641 |
eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)}; |
|
1642 |
like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose"); |
|
test cleanup
|
1643 |
} |
1644 | ||
1645 |
test 'method'; |
|
- method method of DBIx::Cus...
|
1646 |
$dbi->helper( |
cleanup
|
1647 |
one => sub { 1 } |
test cleanup
|
1648 |
); |
- method method of DBIx::Cus...
|
1649 |
$dbi->helper( |
cleanup
|
1650 |
two => sub { 2 } |
test cleanup
|
1651 |
); |
1652 |
$dbi->method({ |
|
cleanup
|
1653 |
twice => sub { |
1654 |
my $self = shift; |
|
1655 |
return $_[0] * 2; |
|
1656 |
} |
|
test cleanup
|
1657 |
}); |
1658 | ||
1659 |
is($dbi->one, 1, "first"); |
|
1660 |
is($dbi->two, 2, "second"); |
|
1661 |
is($dbi->twice(5), 10 , "second"); |
|
1662 | ||
1663 |
eval {$dbi->XXXXXX}; |
|
1664 |
ok($@, "not exists"); |
|
1665 | ||
1666 |
test 'out filter'; |
|
1667 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
1668 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1669 |
$dbi->execute($create_table1); |
1670 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1671 |
$dbi->register_filter(three_times => sub { $_[0] * 3}); |
|
1672 |
$dbi->apply_filter( |
|
cleanup
|
1673 |
$table1, $key1 => {out => 'twice', in => 'three_times'}, |
1674 |
$key2 => {out => 'three_times', in => 'twice'}); |
|
test cleanup
|
1675 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup test
|
1676 |
$result = $dbi->execute("select * from $table1"); |
- renamed DBIx::Custom::Resu...
|
1677 |
$row = $result->fetch_hash_one; |
test cleanup in progress
|
1678 |
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert"); |
1679 |
$result = $dbi->select(table => $table1); |
|
test cleanup
|
1680 |
$row = $result->one; |
test cleanup in progress
|
1681 |
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert"); |
test cleanup
|
1682 | |
- renamed DBIx::Custom::Resu...
|
1683 |
test 'fetch_hash_first DEPRECATED!'; |
1684 |
$result = $dbi->execute("select * from $table1"); |
|
1685 |
$row = $result->fetch_hash_first; |
|
1686 |
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert"); |
|
1687 | ||
test cleanup
|
1688 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
1689 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1690 |
$dbi->execute($create_table1); |
1691 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1692 |
$dbi->register_filter(three_times => sub { $_[0] * 3}); |
|
1693 |
$dbi->apply_filter( |
|
cleanup
|
1694 |
$table1, $key1 => {out => 'twice', in => 'three_times'}, |
1695 |
$key2 => {out => 'three_times', in => 'twice'}); |
|
test cleanup
|
1696 |
$dbi->apply_filter( |
cleanup
|
1697 |
$table1, $key1 => {out => undef} |
test cleanup
|
1698 |
); |
test cleanup
|
1699 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup test
|
1700 |
$result = $dbi->execute("select * from $table1"); |
test cleanup
|
1701 |
$row = $result->one; |
test cleanup in progress
|
1702 |
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert"); |
test cleanup
|
1703 | |
1704 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
1705 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1706 |
$dbi->execute($create_table1); |
1707 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1708 |
$dbi->apply_filter( |
|
cleanup
|
1709 |
$table1, $key1 => {out => 'twice', in => 'twice'} |
test cleanup
|
1710 |
); |
cleanup
|
1711 |
$dbi->insert({$key1 => 1, $key2 => 2},table => $table1, filter => {$key1 => undef}); |
1712 |
$dbi->update({$key1 => 2}, table => $table1, where => {$key2 => 2}); |
|
cleanup test
|
1713 |
$result = $dbi->execute("select * from $table1"); |
test cleanup
|
1714 |
$row = $result->one; |
test cleanup in progress
|
1715 |
is_deeply($row, {$key1 => 4, $key2 => 2}, "update"); |
test cleanup
|
1716 | |
1717 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
1718 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1719 |
$dbi->execute($create_table1); |
1720 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1721 |
$dbi->apply_filter( |
|
cleanup
|
1722 |
$table1, $key1 => {out => 'twice', in => 'twice'} |
test cleanup
|
1723 |
); |
cleanup
|
1724 |
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1=> undef}); |
test cleanup in progress
|
1725 |
$dbi->delete(table => $table1, where => {$key1 => 1}); |
cleanup test
|
1726 |
$result = $dbi->execute("select * from $table1"); |
test cleanup
|
1727 |
$rows = $result->all; |
1728 |
is_deeply($rows, [], "delete"); |
|
1729 | ||
1730 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
1731 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1732 |
$dbi->execute($create_table1); |
1733 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1734 |
$dbi->apply_filter( |
|
cleanup
|
1735 |
$table1, $key1 => {out => 'twice', in => 'twice'} |
test cleanup
|
1736 |
); |
cleanup
|
1737 |
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef}); |
test cleanup in progress
|
1738 |
$result = $dbi->select(table => $table1, where => {$key1 => 1}); |
1739 |
$result->filter({$key2 => 'twice'}); |
|
test cleanup
|
1740 |
$rows = $result->all; |
test cleanup in progress
|
1741 |
is_deeply($rows, [{$key1 => 4, $key2 => 4}], "select"); |
test cleanup
|
1742 | |
1743 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
1744 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1745 |
$dbi->execute($create_table1); |
1746 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1747 |
$dbi->apply_filter( |
|
cleanup
|
1748 |
$table1, $key1 => {out => 'twice', in => 'twice'} |
test cleanup
|
1749 |
); |
cleanup
|
1750 |
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef}); |
cleanup test
|
1751 |
$result = $dbi->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2", |
cleanup
|
1752 |
{$key1 => 1, $key2 => 2}, |
1753 |
table => [$table1]); |
|
test cleanup
|
1754 |
$rows = $result->all; |
test cleanup in progress
|
1755 |
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute"); |
test cleanup
|
1756 | |
1757 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
1758 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1759 |
$dbi->execute($create_table1); |
1760 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1761 |
$dbi->apply_filter( |
|
cleanup
|
1762 |
$table1, $key1 => {out => 'twice', in => 'twice'} |
test cleanup
|
1763 |
); |
cleanup
|
1764 |
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef}); |
cleanup test
|
1765 |
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2", |
cleanup
|
1766 |
{$key1 => 1, $key2 => 2}); |
test cleanup
|
1767 |
$rows = $result->all; |
test cleanup in progress
|
1768 |
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag"); |
test cleanup
|
1769 | |
1770 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
1771 |
eval { $dbi->execute("drop table $table1") }; |
1772 |
eval { $dbi->execute("drop table $table2") }; |
|
test cleanup
|
1773 |
$dbi->execute($create_table1); |
1774 |
$dbi->execute($create_table2); |
|
1775 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1776 |
$dbi->register_filter(three_times => sub { $_[0] * 3 }); |
|
1777 |
$dbi->apply_filter( |
|
cleanup
|
1778 |
$table1, $key2 => {out => 'twice', in => 'twice'} |
cleanup test
|
1779 |
); |
1780 |
$dbi->apply_filter( |
|
cleanup
|
1781 |
$table2, $key3 => {out => 'three_times', in => 'three_times'} |
test cleanup
|
1782 |
); |
cleanup
|
1783 |
$dbi->insert({$key1 => 5, $key2 => 2}, table => $table1, filter => {$key2 => undef}); |
1784 |
$dbi->insert({$key1 => 5, $key3 => 6}, table => $table2, filter => {$key3 => undef}); |
|
cleanup test
|
1785 |
$result = $dbi->select( |
cleanup
|
1786 |
table => [$table1, $table2], |
1787 |
column => [$key2, $key3], |
|
1788 |
where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"}); |
|
cleanup test
|
1789 | |
1790 |
$result->filter({$key2 => 'twice'}); |
|
1791 |
$rows = $result->all; |
|
1792 |
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join"); |
|
1793 | ||
1794 |
$result = $dbi->select( |
|
cleanup
|
1795 |
table => [$table1, $table2], |
1796 |
column => [$key2, $key3], |
|
1797 |
where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"}); |
|
cleanup test
|
1798 | |
1799 |
$result->filter({$key2 => 'twice'}); |
|
1800 |
$rows = $result->all; |
|
1801 |
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join : omit"); |
|
test cleanup
|
1802 | |
1803 |
test 'connect super'; |
|
test cleanup
|
1804 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
1805 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1806 |
$dbi->execute($create_table1); |
test cleanup
|
1807 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
test cleanup in progress
|
1808 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
test cleanup
|
1809 | |
test cleanup
|
1810 |
$dbi = DBIx::Custom->new; |
test cleanup
|
1811 |
$dbi->connect; |
finishied sqlite test cleanu...
|
1812 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1813 |
$dbi->execute($create_table1); |
test cleanup
|
1814 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
test cleanup in progress
|
1815 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
test cleanup
|
1816 | |
test cleanup
|
1817 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
1818 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1819 |
$dbi->execute($create_table1); |
test cleanup
|
1820 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
test cleanup in progress
|
1821 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
test cleanup
|
1822 | |
1823 |
test 'end_filter'; |
|
1824 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
1825 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1826 |
$dbi->execute($create_table1); |
test cleanup
|
1827 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
test cleanup in progress
|
1828 |
$result = $dbi->select(table => $table1); |
1829 |
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 }); |
|
1830 |
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 }); |
|
- renamed DBIx::Custom::Resu...
|
1831 |
$row = $result->fetch_one; |
test cleanup
|
1832 |
is_deeply($row, [6, 40]); |
1833 | ||
- fixed bug DBIx::Custom::Re...
|
1834 |
$dbi = DBIx::Custom->connect; |
1835 |
eval { $dbi->execute("drop table $table1") }; |
|
1836 |
$dbi->execute($create_table1); |
|
1837 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
|
1838 |
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1); |
|
1839 |
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 }); |
|
1840 |
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 }); |
|
- renamed DBIx::Custom::Resu...
|
1841 |
$row = $result->fetch_one; |
- fixed bug DBIx::Custom::Re...
|
1842 |
is_deeply($row, [6, 6, 40]); |
1843 | ||
test cleanup
|
1844 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
1845 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1846 |
$dbi->execute($create_table1); |
test cleanup
|
1847 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
test cleanup in progress
|
1848 |
$result = $dbi->select(table => $table1); |
finishied sqlite test cleanu...
|
1849 |
$result->filter([$key1, $key2] => sub { $_[0] * 2 }); |
1850 |
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]); |
|
- renamed DBIx::Custom::Resu...
|
1851 |
$row = $result->fetch_one; |
test cleanup
|
1852 |
is_deeply($row, [6, 12]); |
1853 | ||
1854 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
1855 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1856 |
$dbi->execute($create_table1); |
test cleanup
|
1857 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
test cleanup in progress
|
1858 |
$result = $dbi->select(table => $table1); |
finishied sqlite test cleanu...
|
1859 |
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]); |
1860 |
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 }); |
|
- renamed DBIx::Custom::Resu...
|
1861 |
$row = $result->fetch_one; |
test cleanup
|
1862 |
is_deeply($row, [6, 12]); |
1863 | ||
1864 |
$dbi->register_filter(five_times => sub { $_[0] * 5 }); |
|
test cleanup in progress
|
1865 |
$result = $dbi->select(table => $table1); |
1866 |
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 }); |
|
1867 |
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' }); |
|
test cleanup
|
1868 |
$row = $result->one; |
test cleanup in progress
|
1869 |
is_deeply($row, {$key1 => 6, $key2 => 40}); |
test cleanup
|
1870 | |
1871 |
$dbi->register_filter(five_times => sub { $_[0] * 5 }); |
|
test cleanup in progress
|
1872 |
$dbi->apply_filter($table1, |
cleanup
|
1873 |
$key1 => {end => sub { $_[0] * 3 } }, |
1874 |
$key2 => {end => 'five_times'} |
|
test cleanup
|
1875 |
); |
test cleanup in progress
|
1876 |
$result = $dbi->select(table => $table1); |
1877 |
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 }); |
|
test cleanup
|
1878 |
$row = $result->one; |
test cleanup in progress
|
1879 |
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter'); |
test cleanup
|
1880 | |
1881 |
$dbi->register_filter(five_times => sub { $_[0] * 5 }); |
|
test cleanup in progress
|
1882 |
$dbi->apply_filter($table1, |
cleanup
|
1883 |
$key1 => {end => sub { $_[0] * 3 } }, |
1884 |
$key2 => {end => 'five_times'} |
|
test cleanup in progress
|
1885 |
); |
1886 |
$result = $dbi->select(table => $table1); |
|
1887 |
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 }); |
|
1888 |
$result->filter($key1 => undef); |
|
1889 |
$result->end_filter($key1 => undef); |
|
test cleanup
|
1890 |
$row = $result->one; |
test cleanup in progress
|
1891 |
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite'); |
test cleanup
|
1892 | |
- fixed bug DBIx::Custom::Re...
|
1893 |
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1); |
1894 |
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 }); |
|
1895 |
$result->filter($key1 => undef); |
|
1896 |
$result->end_filter($key1 => undef); |
|
1897 |
$row = $result->fetch; |
|
1898 |
is_deeply($row, [1, 1, 40], 'apply_filter overwrite'); |
|
1899 | ||
test cleanup
|
1900 |
test 'remove_end_filter and remove_filter'; |
1901 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
1902 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1903 |
$dbi->execute($create_table1); |
test cleanup
|
1904 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
test cleanup in progress
|
1905 |
$result = $dbi->select(table => $table1); |
test cleanup
|
1906 |
$row = $result |
cleanup
|
1907 |
->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 }) |
1908 |
->remove_filter |
|
1909 |
->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 }) |
|
1910 |
->remove_end_filter |
|
1911 |
->fetch_one; |
|
test cleanup
|
1912 |
is_deeply($row, [1, 2]); |
1913 | ||
1914 |
test 'empty where select'; |
|
1915 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
1916 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1917 |
$dbi->execute($create_table1); |
test cleanup
|
1918 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
test cleanup in progress
|
1919 |
$result = $dbi->select(table => $table1, where => {}); |
test cleanup
|
1920 |
$row = $result->one; |
test cleanup in progress
|
1921 |
is_deeply($row, {$key1 => 1, $key2 => 2}); |
test cleanup
|
1922 | |
1923 |
test 'select query option'; |
|
1924 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
1925 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1926 |
$dbi->execute($create_table1); |
cleanup
|
1927 |
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1); |
micro optimization
|
1928 |
ok(ref $query); |
cleanup
|
1929 |
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1); |
micro optimization
|
1930 |
ok(ref $query); |
test cleanup in progress
|
1931 |
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1); |
micro optimization
|
1932 |
ok(ref $query); |
test cleanup in progress
|
1933 |
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1); |
micro optimization
|
1934 |
ok(ref $query); |
test cleanup
|
1935 | |
1936 |
test 'where'; |
|
1937 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
1938 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
1939 |
$dbi->execute($create_table1); |
test cleanup
|
1940 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
1941 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup in progress
|
1942 |
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]); |
1943 |
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param'); |
|
test cleanup
|
1944 | |
1945 |
$where = $dbi->where |
|
cleanup
|
1946 |
->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]) |
1947 |
->param({$key1 => 1}); |
|
test cleanup
|
1948 | |
1949 |
$result = $dbi->select( |
|
cleanup
|
1950 |
table => $table1, |
1951 |
where => $where |
|
test cleanup
|
1952 |
); |
1953 |
$row = $result->all; |
|
test cleanup in progress
|
1954 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
1955 | |
1956 |
$result = $dbi->select( |
|
cleanup
|
1957 |
table => $table1, |
1958 |
where => [ |
|
1959 |
['and', "$key1 = :$key1", "$key2 = :$key2"], |
|
1960 |
{$key1 => 1} |
|
1961 |
] |
|
test cleanup
|
1962 |
); |
1963 |
$row = $result->all; |
|
test cleanup in progress
|
1964 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
1965 | |
1966 |
$where = $dbi->where |
|
cleanup
|
1967 |
->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]) |
1968 |
->param({$key1 => 1, $key2 => 2}); |
|
test cleanup
|
1969 |
$result = $dbi->select( |
cleanup
|
1970 |
table => $table1, |
1971 |
where => $where |
|
test cleanup
|
1972 |
); |
1973 |
$row = $result->all; |
|
test cleanup in progress
|
1974 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
1975 | |
1976 |
$where = $dbi->where |
|
cleanup
|
1977 |
->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]) |
1978 |
->param({}); |
|
test cleanup
|
1979 |
$result = $dbi->select( |
cleanup
|
1980 |
table => $table1, |
1981 |
where => $where, |
|
test cleanup
|
1982 |
); |
1983 |
$row = $result->all; |
|
test cleanup in progress
|
1984 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
1985 | |
1986 |
$where = $dbi->where |
|
cleanup
|
1987 |
->clause(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"]) |
1988 |
->param({$key1 => [0, 3], $key2 => 2}); |
|
test cleanup
|
1989 |
$result = $dbi->select( |
cleanup
|
1990 |
table => $table1, |
1991 |
where => $where, |
|
test cleanup
|
1992 |
); |
1993 |
$row = $result->all; |
|
test cleanup in progress
|
1994 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
1995 | |
1996 |
$where = $dbi->where; |
|
1997 |
$result = $dbi->select( |
|
cleanup
|
1998 |
table => $table1, |
1999 |
where => $where |
|
test cleanup
|
2000 |
); |
2001 |
$row = $result->all; |
|
test cleanup in progress
|
2002 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
2003 | |
2004 |
eval { |
|
2005 |
$where = $dbi->where |
|
cleanup
|
2006 |
->clause(['uuu']); |
test cleanup
|
2007 |
$result = $dbi->select( |
cleanup
|
2008 |
table => $table1, |
2009 |
where => $where |
|
test cleanup
|
2010 |
); |
2011 |
}; |
|
2012 |
ok($@); |
|
2013 | ||
2014 |
$where = $dbi->where; |
|
2015 |
is("$where", ''); |
|
2016 | ||
2017 |
$where = $dbi->where |
|
cleanup
|
2018 |
->clause(['or', ("$key1 = :$key1") x 2]) |
2019 |
->param({$key1 => [1, 3]}); |
|
test cleanup
|
2020 |
$result = $dbi->select( |
cleanup
|
2021 |
table => $table1, |
2022 |
where => $where, |
|
test cleanup
|
2023 |
); |
2024 |
$row = $result->all; |
|
test cleanup in progress
|
2025 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
2026 | |
2027 |
$where = $dbi->where |
|
cleanup
|
2028 |
->clause(['or', ("$key1 = :$key1") x 2]) |
2029 |
->param({$key1 => [1]}); |
|
test cleanup
|
2030 |
$result = $dbi->select( |
cleanup
|
2031 |
table => $table1, |
2032 |
where => $where, |
|
test cleanup
|
2033 |
); |
2034 |
$row = $result->all; |
|
test cleanup in progress
|
2035 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
2036 | |
2037 |
$where = $dbi->where |
|
cleanup
|
2038 |
->clause(['or', ("$key1 = :$key1") x 2]) |
2039 |
->param({$key1 => 1}); |
|
test cleanup
|
2040 |
$result = $dbi->select( |
cleanup
|
2041 |
table => $table1, |
2042 |
where => $where, |
|
test cleanup
|
2043 |
); |
2044 |
$row = $result->all; |
|
test cleanup in progress
|
2045 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
2046 | |
2047 |
$where = $dbi->where |
|
cleanup
|
2048 |
->clause("$key1 = :$key1") |
2049 |
->param({$key1 => 1}); |
|
test cleanup
|
2050 |
$result = $dbi->select( |
cleanup
|
2051 |
table => $table1, |
2052 |
where => $where, |
|
test cleanup
|
2053 |
); |
2054 |
$row = $result->all; |
|
test cleanup in progress
|
2055 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
2056 | |
2057 |
$where = $dbi->where |
|
cleanup
|
2058 |
->clause(['or', ("$key1 = :$key1") x 3]) |
2059 |
->param({$key1 => [$dbi->not_exists, 1, 3]}); |
|
test cleanup
|
2060 |
$result = $dbi->select( |
cleanup
|
2061 |
table => $table1, |
2062 |
where => $where, |
|
test cleanup
|
2063 |
); |
2064 |
$row = $result->all; |
|
test cleanup in progress
|
2065 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists'); |
test cleanup
|
2066 | |
2067 |
$where = $dbi->where |
|
cleanup
|
2068 |
->clause(['or', ("$key1 = :$key1") x 3]) |
2069 |
->param({$key1 => [1, $dbi->not_exists, 3]}); |
|
test cleanup
|
2070 |
$result = $dbi->select( |
cleanup
|
2071 |
table => $table1, |
2072 |
where => $where, |
|
test cleanup
|
2073 |
); |
2074 |
$row = $result->all; |
|
test cleanup in progress
|
2075 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists'); |
test cleanup
|
2076 | |
2077 |
$where = $dbi->where |
|
cleanup
|
2078 |
->clause(['or', ("$key1 = :$key1") x 3]) |
2079 |
->param({$key1 => [1, 3, $dbi->not_exists]}); |
|
test cleanup
|
2080 |
$result = $dbi->select( |
cleanup
|
2081 |
table => $table1, |
2082 |
where => $where, |
|
test cleanup
|
2083 |
); |
2084 |
$row = $result->all; |
|
test cleanup in progress
|
2085 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists'); |
test cleanup
|
2086 | |
2087 |
$where = $dbi->where |
|
cleanup
|
2088 |
->clause(['or', ("$key1 = :$key1") x 3]) |
2089 |
->param({$key1 => [1, $dbi->not_exists, $dbi->not_exists]}); |
|
test cleanup
|
2090 |
$result = $dbi->select( |
cleanup
|
2091 |
table => $table1, |
2092 |
where => $where, |
|
test cleanup
|
2093 |
); |
2094 |
$row = $result->all; |
|
test cleanup in progress
|
2095 |
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists'); |
test cleanup
|
2096 | |
2097 |
$where = $dbi->where |
|
cleanup
|
2098 |
->clause(['or', ("$key1 = :$key1") x 3]) |
2099 |
->param({$key1 => [$dbi->not_exists, 1, $dbi->not_exists]}); |
|
test cleanup
|
2100 |
$result = $dbi->select( |
cleanup
|
2101 |
table => $table1, |
2102 |
where => $where, |
|
test cleanup
|
2103 |
); |
2104 |
$row = $result->all; |
|
test cleanup in progress
|
2105 |
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists'); |
test cleanup
|
2106 | |
2107 |
$where = $dbi->where |
|
cleanup
|
2108 |
->clause(['or', ("$key1 = :$key1") x 3]) |
2109 |
->param({$key1 => [$dbi->not_exists, $dbi->not_exists, 1]}); |
|
test cleanup
|
2110 |
$result = $dbi->select( |
cleanup
|
2111 |
table => $table1, |
2112 |
where => $where, |
|
test cleanup
|
2113 |
); |
2114 |
$row = $result->all; |
|
test cleanup in progress
|
2115 |
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists'); |
test cleanup
|
2116 | |
2117 |
$where = $dbi->where |
|
cleanup
|
2118 |
->clause(['or', ("$key1 = :$key1") x 3]) |
2119 |
->param({$key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]}); |
|
test cleanup
|
2120 |
$result = $dbi->select( |
cleanup
|
2121 |
table => $table1, |
2122 |
where => $where, |
|
test cleanup
|
2123 |
); |
2124 |
$row = $result->all; |
|
test cleanup in progress
|
2125 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists'); |
test cleanup
|
2126 | |
2127 |
$where = $dbi->where |
|
cleanup
|
2128 |
->clause(['or', ("$key1 = :$key1") x 3]) |
2129 |
->param({$key1 => []}); |
|
test cleanup
|
2130 |
$result = $dbi->select( |
cleanup
|
2131 |
table => $table1, |
2132 |
where => $where, |
|
test cleanup
|
2133 |
); |
2134 |
$row = $result->all; |
|
test cleanup in progress
|
2135 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists'); |
test cleanup
|
2136 | |
2137 |
$where = $dbi->where |
|
cleanup
|
2138 |
->clause(['and', "{> $key1}", "{< $key1}" ]) |
2139 |
->param({$key1 => [2, $dbi->not_exists]}); |
|
test cleanup
|
2140 |
$result = $dbi->select( |
cleanup
|
2141 |
table => $table1, |
2142 |
where => $where, |
|
test cleanup
|
2143 |
); |
2144 |
$row = $result->all; |
|
test cleanup in progress
|
2145 |
is_deeply($row, [{$key1 => 3, $key2 => 4}], 'not_exists'); |
test cleanup
|
2146 | |
2147 |
$where = $dbi->where |
|
cleanup
|
2148 |
->clause(['and', "{> $key1}", "{< $key1}" ]) |
2149 |
->param({$key1 => [$dbi->not_exists, 2]}); |
|
test cleanup
|
2150 |
$result = $dbi->select( |
cleanup
|
2151 |
table => $table1, |
2152 |
where => $where, |
|
test cleanup
|
2153 |
); |
2154 |
$row = $result->all; |
|
test cleanup in progress
|
2155 |
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists'); |
test cleanup
|
2156 | |
2157 |
$where = $dbi->where |
|
cleanup
|
2158 |
->clause(['and', "{> $key1}", "{< $key1}" ]) |
2159 |
->param({$key1 => [$dbi->not_exists, $dbi->not_exists]}); |
|
test cleanup
|
2160 |
$result = $dbi->select( |
cleanup
|
2161 |
table => $table1, |
2162 |
where => $where, |
|
test cleanup
|
2163 |
); |
2164 |
$row = $result->all; |
|
test cleanup in progress
|
2165 |
is_deeply($row, [{$key1 => 1, $key2 => 2},{$key1 => 3, $key2 => 4}], 'not_exists'); |
test cleanup
|
2166 | |
2167 |
$where = $dbi->where |
|
cleanup
|
2168 |
->clause(['and', "{> $key1}", "{< $key1}" ]) |
2169 |
->param({$key1 => [0, 2]}); |
|
test cleanup
|
2170 |
$result = $dbi->select( |
cleanup
|
2171 |
table => $table1, |
2172 |
where => $where, |
|
test cleanup
|
2173 |
); |
2174 |
$row = $result->all; |
|
test cleanup in progress
|
2175 |
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists'); |
test cleanup
|
2176 | |
2177 |
$where = $dbi->where |
|
cleanup
|
2178 |
->clause(['and',"$key1 is not null", "$key2 is not null" ]); |
test cleanup
|
2179 |
$result = $dbi->select( |
cleanup
|
2180 |
table => $table1, |
2181 |
where => $where, |
|
test cleanup
|
2182 |
); |
2183 |
$row = $result->all; |
|
test cleanup in progress
|
2184 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists'); |
test cleanup
|
2185 | |
2186 |
eval {$dbi->where(ppp => 1) }; |
|
2187 |
like($@, qr/invalid/); |
|
2188 | ||
2189 |
$where = $dbi->where( |
|
cleanup
|
2190 |
clause => ['and', ['or'], ['and', "$key1 = :$key1", "$key2 = :$key2"]], |
2191 |
param => {$key1 => 1, $key2 => 2} |
|
test cleanup
|
2192 |
); |
2193 |
$result = $dbi->select( |
|
cleanup
|
2194 |
table => $table1, |
2195 |
where => $where, |
|
test cleanup
|
2196 |
); |
2197 |
$row = $result->all; |
|
test cleanup in progress
|
2198 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
2199 | |
2200 | ||
2201 |
$where = $dbi->where( |
|
cleanup
|
2202 |
clause => ['and', ['or'], ['or', ":$key1", ":$key2"]], |
2203 |
param => {} |
|
test cleanup
|
2204 |
); |
2205 |
$result = $dbi->select( |
|
cleanup
|
2206 |
table => $table1, |
2207 |
where => $where, |
|
test cleanup
|
2208 |
); |
2209 |
$row = $result->all; |
|
test cleanup in progress
|
2210 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
2211 | |
2212 |
$where = $dbi->where; |
|
test cleanup in progress
|
2213 |
$where->clause(['and', ":${key1}{=}"]); |
2214 |
$where->param({$key1 => undef}); |
|
2215 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1}); |
|
test cleanup
|
2216 |
$row = $result->all; |
test cleanup in progress
|
2217 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
2218 | |
2219 |
$where = $dbi->where; |
|
test cleanup in progress
|
2220 |
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]); |
2221 |
$where->param({$key1 => [undef, undef]}); |
|
2222 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]}); |
|
test cleanup
|
2223 |
$row = $result->all; |
test cleanup in progress
|
2224 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
2225 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]}); |
|
test cleanup
|
2226 |
$row = $result->all; |
test cleanup in progress
|
2227 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
2228 | |
fixed where clause parsing b...
|
2229 | |
2230 |
$dbi = DBIx::Custom->connect; |
|
2231 |
eval { $dbi->execute("drop table $table1") }; |
|
2232 |
$dbi->execute($create_table1); |
|
cleanup
|
2233 |
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1); |
2234 |
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1); |
|
fixed where clause parsing b...
|
2235 |
$where = $dbi->where |
cleanup
|
2236 |
->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"]) |
2237 |
->param({$key1 => 1}); |
|
fixed where clause parsing b...
|
2238 | |
2239 |
$result = $dbi->select( |
|
cleanup
|
2240 |
table => $table1, |
2241 |
where => $where |
|
fixed where clause parsing b...
|
2242 |
); |
2243 |
$row = $result->all; |
|
2244 |
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]); |
|
2245 | ||
test cleanup
|
2246 |
test 'register_tag_processor'; |
2247 |
$dbi = DBIx::Custom->connect; |
|
2248 |
$dbi->register_tag_processor( |
|
cleanup
|
2249 |
a => sub { 1 } |
test cleanup
|
2250 |
); |
test cleanup
|
2251 |
is($dbi->{_tags}->{a}->(), 1); |
test cleanup
|
2252 | |
2253 |
test 'register_tag'; |
|
2254 |
$dbi = DBIx::Custom->connect; |
|
2255 |
$dbi->register_tag( |
|
cleanup
|
2256 |
b => sub { 2 } |
test cleanup
|
2257 |
); |
test cleanup
|
2258 |
is($dbi->{_tags}->{b}->(), 2); |
test cleanup
|
2259 | |
2260 |
test 'table not specify exception'; |
|
2261 |
$dbi = DBIx::Custom->connect; |
|
select method can be called ...
|
2262 |
eval {$dbi->select($key1)}; |
2263 |
ok($@); |
|
test cleanup
|
2264 | |
test cleanup
|
2265 |
test 'more tests'; |
2266 |
$dbi = DBIx::Custom->connect; |
|
2267 |
eval{$dbi->apply_filter('table', 'column', [])}; |
|
2268 |
like($@, qr/apply_filter/); |
|
2269 | ||
2270 |
eval{$dbi->apply_filter('table', 'column', {outer => 2})}; |
|
2271 |
like($@, qr/apply_filter/); |
|
2272 | ||
2273 |
$dbi->apply_filter( |
|
2274 | ||
2275 |
); |
|
2276 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2277 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
2278 |
$dbi->execute($create_table1); |
test cleanup
|
2279 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
2280 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup in progress
|
2281 |
$dbi->apply_filter($table1, $key2, |
cleanup
|
2282 |
{in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }}); |
test cleanup in progress
|
2283 |
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all; |
2284 |
is_deeply($rows, [{$key1 => 1, $key2 => 6}]); |
|
test cleanup
|
2285 | |
2286 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2287 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
2288 |
$dbi->execute($create_table1); |
test cleanup
|
2289 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
2290 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup in progress
|
2291 |
$dbi->apply_filter($table1, $key2, {}); |
2292 |
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all; |
|
2293 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
|
test cleanup
|
2294 | |
2295 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2296 |
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})}; |
test cleanup
|
2297 |
like($@, qr/not registered/); |
test cleanup in progress
|
2298 |
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})}; |
test cleanup
|
2299 |
like($@, qr/not registered/); |
2300 |
$dbi->method({one => sub { 1 }}); |
|
2301 |
is($dbi->one, 1); |
|
2302 | ||
2303 |
eval{DBIx::Custom->connect(dsn => undef)}; |
|
2304 |
like($@, qr/_connect/); |
|
2305 | ||
2306 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2307 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
2308 |
$dbi->execute($create_table1); |
2309 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
cleanup
|
2310 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, |
cleanup
|
2311 |
filter => {$key1 => 'twice'}); |
test cleanup in progress
|
2312 |
$row = $dbi->select(table => $table1)->one; |
2313 |
is_deeply($row, {$key1 => 2, $key2 => 2}); |
|
cleanup
|
2314 |
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, |
cleanup
|
2315 |
filter => {$key1 => 'no'}) }; |
test cleanup
|
2316 |
like($@, qr//); |
2317 | ||
2318 |
$dbi->register_filter(one => sub { }); |
|
2319 |
$dbi->default_fetch_filter('one'); |
|
2320 |
ok($dbi->default_fetch_filter); |
|
2321 |
$dbi->default_bind_filter('one'); |
|
2322 |
ok($dbi->default_bind_filter); |
|
2323 |
eval{$dbi->default_fetch_filter('no')}; |
|
2324 |
like($@, qr/not registered/); |
|
2325 |
eval{$dbi->default_bind_filter('no')}; |
|
2326 |
like($@, qr/not registered/); |
|
2327 |
$dbi->default_bind_filter(undef); |
|
2328 |
ok(!defined $dbi->default_bind_filter); |
|
2329 |
$dbi->default_fetch_filter(undef); |
|
2330 |
ok(!defined $dbi->default_fetch_filter); |
|
test cleanup in progress
|
2331 |
eval {$dbi->execute("select * from $table1 {} {= author") }; |
test cleanup
|
2332 |
like($@, qr/Tag not finished/); |
2333 | ||
2334 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2335 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
2336 |
$dbi->execute($create_table1); |
2337 |
$dbi->register_filter(one => sub { 1 }); |
|
test cleanup in progress
|
2338 |
$result = $dbi->select(table => $table1); |
2339 |
eval {$result->filter($key1 => 'no')}; |
|
test cleanup
|
2340 |
like($@, qr/not registered/); |
test cleanup in progress
|
2341 |
eval {$result->end_filter($key1 => 'no')}; |
test cleanup
|
2342 |
like($@, qr/not registered/); |
2343 |
$result->default_filter(undef); |
|
2344 |
ok(!defined $result->default_filter); |
|
2345 |
$result->default_filter('one'); |
|
2346 |
is($result->default_filter->(), 1); |
|
2347 | ||
- dbi_option attribute is re...
|
2348 |
test 'option'; |
2349 |
$dbi = DBIx::Custom->connect(option => {PrintError => 1}); |
|
2350 |
ok($dbi->dbh->{PrintError}); |
|
test cleanup
|
2351 |
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1}); |
2352 |
ok($dbi->dbh->{PrintError}); |
|
2353 |
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1}); |
|
2354 |
ok($dbi->dbh->{PrintError}); |
|
2355 | ||
2356 |
test 'DBIx::Custom::Result stash()'; |
|
2357 |
$result = DBIx::Custom::Result->new; |
|
2358 |
is_deeply($result->stash, {}, 'default'); |
|
2359 |
$result->stash->{foo} = 1; |
|
2360 |
is($result->stash->{foo}, 1, 'get and set'); |
|
test cleanup
|
2361 | |
cleanup test
|
2362 |
test 'delete_at'; |
2363 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2364 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2365 |
$dbi->execute($create_table1_2); |
cleanup
|
2366 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
2367 |
$dbi->delete_at( |
cleanup
|
2368 |
table => $table1, |
2369 |
primary_key => [$key1, $key2], |
|
2370 |
where => [1, 2], |
|
cleanup test
|
2371 |
); |
test cleanup in progress
|
2372 |
is_deeply($dbi->select(table => $table1)->all, []); |
cleanup test
|
2373 | |
cleanup
|
2374 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
2375 |
$dbi->delete_at( |
cleanup
|
2376 |
table => $table1, |
2377 |
primary_key => $key1, |
|
2378 |
where => 1, |
|
cleanup test
|
2379 |
); |
test cleanup in progress
|
2380 |
is_deeply($dbi->select(table => $table1)->all, []); |
cleanup test
|
2381 | |
2382 |
test 'insert_at'; |
|
2383 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2384 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2385 |
$dbi->execute($create_table1_2); |
2386 |
$dbi->insert_at( |
|
cleanup
|
2387 |
{$key3 => 3}, |
2388 |
primary_key => [$key1, $key2], |
|
2389 |
table => $table1, |
|
2390 |
where => [1, 2], |
|
cleanup test
|
2391 |
); |
test cleanup in progress
|
2392 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2393 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2394 |
is($dbi->select(table => $table1)->one->{$key3}, 3); |
|
cleanup test
|
2395 | |
test cleanup in progress
|
2396 |
$dbi->delete_all(table => $table1); |
test cleanup
|
2397 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
2398 |
$dbi->insert_at( |
cleanup
|
2399 |
{$key2 => 2, $key3 => 3}, |
2400 |
primary_key => $key1, |
|
2401 |
table => $table1, |
|
2402 |
where => 1, |
|
cleanup test
|
2403 |
); |
2404 | ||
test cleanup in progress
|
2405 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2406 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2407 |
is($dbi->select(table => $table1)->one->{$key3}, 3); |
|
cleanup test
|
2408 | |
2409 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2410 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2411 |
$dbi->execute($create_table1_2); |
2412 |
$dbi->insert_at( |
|
cleanup
|
2413 |
{$key3 => 3}, |
2414 |
primary_key => [$key1, $key2], |
|
2415 |
table => $table1, |
|
2416 |
where => [1, 2], |
|
cleanup test
|
2417 |
); |
test cleanup in progress
|
2418 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2419 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2420 |
is($dbi->select(table => $table1)->one->{$key3}, 3); |
|
cleanup test
|
2421 | |
2422 |
test 'update_at'; |
|
2423 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2424 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2425 |
$dbi->execute($create_table1_2); |
test cleanup
|
2426 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
2427 |
$dbi->update_at( |
cleanup
|
2428 |
{$key3 => 4}, |
2429 |
table => $table1, |
|
2430 |
primary_key => [$key1, $key2], |
|
2431 |
where => [1, 2], |
|
cleanup test
|
2432 |
); |
test cleanup in progress
|
2433 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2434 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2435 |
is($dbi->select(table => $table1)->one->{$key3}, 4); |
|
cleanup test
|
2436 | |
test cleanup in progress
|
2437 |
$dbi->delete_all(table => $table1); |
test cleanup
|
2438 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
2439 |
$dbi->update_at( |
cleanup
|
2440 |
{$key3 => 4}, |
2441 |
table => $table1, |
|
2442 |
primary_key => $key1, |
|
2443 |
where => 1, |
|
cleanup test
|
2444 |
); |
test cleanup in progress
|
2445 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2446 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2447 |
is($dbi->select(table => $table1)->one->{$key3}, 4); |
|
cleanup test
|
2448 | |
2449 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2450 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2451 |
$dbi->execute($create_table1_2); |
test cleanup
|
2452 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
2453 |
$dbi->update_at( |
cleanup
|
2454 |
{$key3 => 4}, |
2455 |
table => $table1, |
|
2456 |
primary_key => [$key1, $key2], |
|
2457 |
where => [1, 2] |
|
cleanup test
|
2458 |
); |
test cleanup in progress
|
2459 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2460 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2461 |
is($dbi->select(table => $table1)->one->{$key3}, 4); |
|
cleanup test
|
2462 | |
2463 |
test 'select_at'; |
|
2464 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2465 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2466 |
$dbi->execute($create_table1_2); |
test cleanup
|
2467 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
2468 |
$result = $dbi->select_at( |
cleanup
|
2469 |
table => $table1, |
2470 |
primary_key => [$key1, $key2], |
|
2471 |
where => [1, 2] |
|
cleanup test
|
2472 |
); |
2473 |
$row = $result->one; |
|
test cleanup in progress
|
2474 |
is($row->{$key1}, 1); |
2475 |
is($row->{$key2}, 2); |
|
2476 |
is($row->{$key3}, 3); |
|
cleanup test
|
2477 | |
test cleanup in progress
|
2478 |
$dbi->delete_all(table => $table1); |
test cleanup
|
2479 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
2480 |
$result = $dbi->select_at( |
cleanup
|
2481 |
table => $table1, |
2482 |
primary_key => $key1, |
|
2483 |
where => 1, |
|
cleanup test
|
2484 |
); |
2485 |
$row = $result->one; |
|
test cleanup in progress
|
2486 |
is($row->{$key1}, 1); |
2487 |
is($row->{$key2}, 2); |
|
2488 |
is($row->{$key3}, 3); |
|
cleanup test
|
2489 | |
test cleanup in progress
|
2490 |
$dbi->delete_all(table => $table1); |
test cleanup
|
2491 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
2492 |
$result = $dbi->select_at( |
cleanup
|
2493 |
table => $table1, |
2494 |
primary_key => [$key1, $key2], |
|
2495 |
where => [1, 2] |
|
cleanup test
|
2496 |
); |
2497 |
$row = $result->one; |
|
test cleanup in progress
|
2498 |
is($row->{$key1}, 1); |
2499 |
is($row->{$key2}, 2); |
|
2500 |
is($row->{$key3}, 3); |
|
cleanup test
|
2501 | |
2502 |
test 'model delete_at'; |
|
2503 |
$dbi = MyDBI6->connect; |
|
finishied sqlite test cleanu...
|
2504 |
eval { $dbi->execute("drop table $table1") }; |
2505 |
eval { $dbi->execute("drop table $table2") }; |
|
2506 |
eval { $dbi->execute("drop table $table3") }; |
|
cleanup test
|
2507 |
$dbi->execute($create_table1_2); |
2508 |
$dbi->execute($create_table2_2); |
|
2509 |
$dbi->execute($create_table3); |
|
test cleanup
|
2510 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
test cleanup in progress
|
2511 |
$dbi->model($table1)->delete_at(where => [1, 2]); |
2512 |
is_deeply($dbi->select(table => $table1)->all, []); |
|
test cleanup
|
2513 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2); |
test cleanup in progress
|
2514 |
$dbi->model($table1)->delete_at(where => [1, 2]); |
2515 |
is_deeply($dbi->select(table => $table1)->all, []); |
|
test cleanup
|
2516 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3); |
test cleanup in progress
|
2517 |
$dbi->model($table3)->delete_at(where => [1, 2]); |
2518 |
is_deeply($dbi->select(table => $table3)->all, []); |
|
cleanup test
|
2519 | |
2520 |
test 'model insert_at'; |
|
2521 |
$dbi = MyDBI6->connect; |
|
finishied sqlite test cleanu...
|
2522 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2523 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2524 |
$dbi->model($table1)->insert_at( |
cleanup
|
2525 |
{$key3 => 3}, |
2526 |
where => [1, 2], |
|
cleanup test
|
2527 |
); |
test cleanup in progress
|
2528 |
$result = $dbi->model($table1)->select; |
cleanup test
|
2529 |
$row = $result->one; |
test cleanup in progress
|
2530 |
is($row->{$key1}, 1); |
2531 |
is($row->{$key2}, 2); |
|
2532 |
is($row->{$key3}, 3); |
|
cleanup test
|
2533 | |
2534 |
test 'model update_at'; |
|
2535 |
$dbi = MyDBI6->connect; |
|
finishied sqlite test cleanu...
|
2536 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2537 |
$dbi->execute($create_table1_2); |
test cleanup
|
2538 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
test cleanup in progress
|
2539 |
$dbi->model($table1)->update_at( |
cleanup
|
2540 |
{$key3 => 4}, |
2541 |
where => [1, 2], |
|
cleanup test
|
2542 |
); |
test cleanup in progress
|
2543 |
$result = $dbi->model($table1)->select; |
cleanup test
|
2544 |
$row = $result->one; |
test cleanup in progress
|
2545 |
is($row->{$key1}, 1); |
2546 |
is($row->{$key2}, 2); |
|
2547 |
is($row->{$key3}, 4); |
|
cleanup test
|
2548 | |
2549 |
test 'model select_at'; |
|
2550 |
$dbi = MyDBI6->connect; |
|
finishied sqlite test cleanu...
|
2551 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2552 |
$dbi->execute($create_table1_2); |
test cleanup
|
2553 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
test cleanup in progress
|
2554 |
$result = $dbi->model($table1)->select_at(where => [1, 2]); |
cleanup test
|
2555 |
$row = $result->one; |
test cleanup in progress
|
2556 |
is($row->{$key1}, 1); |
2557 |
is($row->{$key2}, 2); |
|
2558 |
is($row->{$key3}, 3); |
|
cleanup test
|
2559 | |
2560 | ||
2561 |
test 'mycolumn and column'; |
|
2562 |
$dbi = MyDBI7->connect; |
|
cleanup test
|
2563 |
$dbi->user_table_info($user_table_info); |
finishied sqlite test cleanu...
|
2564 |
eval { $dbi->execute("drop table $table1") }; |
2565 |
eval { $dbi->execute("drop table $table2") }; |
|
cleanup test
|
2566 |
$dbi->execute($create_table1); |
2567 |
$dbi->execute($create_table2); |
|
2568 |
$dbi->separator('__'); |
|
fixed setup method logic
|
2569 |
$dbi->setup_model; |
test cleanup
|
2570 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
2571 |
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2); |
|
test cleanup in progress
|
2572 |
$model = $dbi->model($table1); |
cleanup test
|
2573 |
$result = $model->select( |
cleanup
|
2574 |
column => [$model->mycolumn, $model->column($table2)], |
2575 |
where => {"$table1.$key1" => 1} |
|
cleanup test
|
2576 |
); |
2577 |
is_deeply($result->one, |
|
improved test
|
2578 |
{$key1 => 1, $key2 => 2, u2"${table2}__$key1" => 1, u2"${table2}__$key3" => 3}); |
test cleanup
|
2579 | |
- update_param is DEPRECATED...
|
2580 |
test 'values_clause'; |
test cleanup
|
2581 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
2582 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
2583 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2584 |
$param = {$key1 => 1, $key2 => 2}; |
- update_param is DEPRECATED...
|
2585 |
$values_clause = $dbi->values_clause($param); |
test cleanup
|
2586 |
$sql = <<"EOS"; |
- update_param is DEPRECATED...
|
2587 |
insert into $table1 $values_clause |
test cleanup
|
2588 |
EOS |
test cleanup
|
2589 |
$dbi->execute($sql, $param, table => $table1); |
test cleanup in progress
|
2590 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2591 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
test cleanup
|
2592 | |
2593 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2594 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
2595 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2596 |
$param = {$key1 => 1, $key2 => 2}; |
- update_param is DEPRECATED...
|
2597 |
$values_clause = $dbi->insert_param($param); |
test cleanup
|
2598 |
$sql = <<"EOS"; |
- update_param is DEPRECATED...
|
2599 |
insert into $table1 $values_clause |
test cleanup
|
2600 |
EOS |
test cleanup
|
2601 |
$dbi->execute($sql, $param, table => $table1); |
test cleanup in progress
|
2602 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2603 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
test cleanup
|
2604 | |
cleanup test
|
2605 |
test 'mycolumn'; |
2606 |
$dbi = MyDBI8->connect; |
|
cleanup test
|
2607 |
$dbi->user_table_info($user_table_info); |
finishied sqlite test cleanu...
|
2608 |
eval { $dbi->execute("drop table $table1") }; |
2609 |
eval { $dbi->execute("drop table $table2") }; |
|
cleanup test
|
2610 |
$dbi->execute($create_table1); |
2611 |
$dbi->execute($create_table2); |
|
fixed setup method logic
|
2612 |
$dbi->setup_model; |
test cleanup
|
2613 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
2614 |
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2); |
|
test cleanup in progress
|
2615 |
$model = $dbi->model($table1); |
cleanup test
|
2616 |
$result = $model->select_at( |
cleanup
|
2617 |
column => [ |
2618 |
$model->mycolumn, |
|
2619 |
$model->column($table2) |
|
2620 |
] |
|
cleanup test
|
2621 |
); |
2622 |
is_deeply($result->one, |
|
cleanup
|
2623 |
{$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3}); |
cleanup test
|
2624 | |
2625 |
$result = $model->select_at( |
|
cleanup
|
2626 |
column => [ |
2627 |
$model->mycolumn([$key1]), |
|
2628 |
$model->column($table2 => [$key1]) |
|
2629 |
] |
|
cleanup test
|
2630 |
); |
2631 |
is_deeply($result->one, |
|
cleanup
|
2632 |
{$key1 => 1, "$table2.$key1" => 1}); |
cleanup test
|
2633 |
$result = $model->select_at( |
cleanup
|
2634 |
column => [ |
2635 |
$model->mycolumn([$key1]), |
|
2636 |
{$table2 => [$key1]} |
|
2637 |
] |
|
cleanup test
|
2638 |
); |
2639 |
is_deeply($result->one, |
|
cleanup
|
2640 |
{$key1 => 1, "$table2.$key1" => 1}); |
cleanup test
|
2641 | |
2642 |
$result = $model->select_at( |
|
cleanup
|
2643 |
column => [ |
2644 |
$model->mycolumn([$key1]), |
|
2645 |
["$table2.$key1", as => "$table2.$key1"] |
|
2646 |
] |
|
cleanup test
|
2647 |
); |
2648 |
is_deeply($result->one, |
|
cleanup
|
2649 |
{$key1 => 1, "$table2.$key1" => 1}); |
cleanup test
|
2650 | |
2651 |
$result = $model->select_at( |
|
cleanup
|
2652 |
column => [ |
2653 |
$model->mycolumn([$key1]), |
|
2654 |
["$table2.$key1" => "$table2.$key1"] |
|
2655 |
] |
|
cleanup test
|
2656 |
); |
2657 |
is_deeply($result->one, |
|
cleanup
|
2658 |
{$key1 => 1, "$table2.$key1" => 1}); |
cleanup test
|
2659 | |
cleanup test
|
2660 |
test 'merge_param'; |
2661 |
$dbi = DBIx::Custom->new; |
|
2662 |
$params = [ |
|
cleanup
|
2663 |
{$key1 => 1, $key2 => 2, $key3 => 3}, |
2664 |
{$key1 => 1, $key2 => 2}, |
|
2665 |
{$key1 => 1} |
|
cleanup test
|
2666 |
]; |
2667 |
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]); |
|
test cleanup in progress
|
2668 |
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3}); |
cleanup test
|
2669 | |
2670 |
$params = [ |
|
cleanup
|
2671 |
{$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]}, |
2672 |
{$key1 => [3, 4], $key2 => [2, 3], $key3 => 3} |
|
cleanup test
|
2673 |
]; |
2674 |
$param = $dbi->merge_param($params->[0], $params->[1]); |
|
test cleanup in progress
|
2675 |
is_deeply($param, {$key1 => [1, 2, 3, 4], $key2 => [1, 2, 3], $key3 => [1, 2, 3]}); |
cleanup test
|
2676 | |
2677 |
test 'select() param option'; |
|
2678 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2679 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2680 |
$dbi->execute($create_table1); |
test cleanup
|
2681 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
2682 |
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1); |
|
finishied sqlite test cleanu...
|
2683 |
eval { $dbi->execute("drop table $table2") }; |
cleanup test
|
2684 |
$dbi->execute($create_table2); |
test cleanup
|
2685 |
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2); |
2686 |
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2); |
|
cleanup test
|
2687 |
$rows = $dbi->select( |
cleanup
|
2688 |
table => $table1, |
improved test
|
2689 |
column => "$table1.$key1 as " . u("${table1}_$key1") . ", $key2, $key3", |
cleanup
|
2690 |
where => {"$table1.$key2" => 3}, |
2691 |
join => ["inner join (select * from $table2 where {= $table2.$key3})" . |
|
improved test
|
2692 |
" $q$table2$p on $table1.$key1 = $q$table2$p.$key1"], |
cleanup
|
2693 |
param => {"$table2.$key3" => 5} |
cleanup test
|
2694 |
)->all; |
improved test
|
2695 |
is_deeply($rows, [{u"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]); |
cleanup test
|
2696 | |
cleanup
|
2697 |
$rows = $dbi->select( |
cleanup
|
2698 |
table => $table1, |
improved test
|
2699 |
column => "$table1.$key1 as " . u("${table1}_$key1") . ", $key2, $key3", |
cleanup
|
2700 |
where => {"$table1.$key2" => 3}, |
2701 |
join => "inner join (select * from $table2 where {= $table2.$key3})" . |
|
improved test
|
2702 |
" $q$table2$p on $table1.$key1 = $q$table2$p.$key1", |
cleanup
|
2703 |
param => {"$table2.$key3" => 5} |
cleanup
|
2704 |
)->all; |
improved test
|
2705 |
is_deeply($rows, [{u"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]); |
cleanup
|
2706 | |
cleanup test
|
2707 |
test 'select() string where'; |
2708 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2709 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2710 |
$dbi->execute($create_table1); |
test cleanup
|
2711 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
2712 |
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1); |
|
cleanup test
|
2713 |
$rows = $dbi->select( |
cleanup
|
2714 |
table => $table1, |
2715 |
where => "$key1 = :$key1 and $key2 = :$key2", |
|
2716 |
where_param => {$key1 => 1, $key2 => 2} |
|
cleanup test
|
2717 |
)->all; |
test cleanup in progress
|
2718 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
cleanup test
|
2719 | |
2720 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2721 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2722 |
$dbi->execute($create_table1); |
test cleanup
|
2723 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
2724 |
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1); |
|
cleanup test
|
2725 |
$rows = $dbi->select( |
cleanup
|
2726 |
table => $table1, |
2727 |
where => [ |
|
2728 |
"$key1 = :$key1 and $key2 = :$key2", |
|
2729 |
{$key1 => 1, $key2 => 2} |
|
2730 |
] |
|
cleanup test
|
2731 |
)->all; |
test cleanup in progress
|
2732 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
cleanup test
|
2733 | |
cleanup
|
2734 |
$dbi = DBIx::Custom->connect; |
2735 |
eval { $dbi->execute("drop table $table1") }; |
|
2736 |
$dbi->execute($create_table1); |
|
test cleanup
|
2737 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
2738 |
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1); |
|
cleanup
|
2739 |
$rows = $dbi->select( |
cleanup
|
2740 |
table => $table1, |
2741 |
where => [ |
|
2742 |
"$key1 = :$key1 and $key2 = :$key2", |
|
2743 |
{$key1 => 1, $key2 => 2} |
|
2744 |
] |
|
cleanup
|
2745 |
)->all; |
2746 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
|
2747 | ||
cleanup test
|
2748 |
test 'delete() string where'; |
2749 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2750 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2751 |
$dbi->execute($create_table1); |
test cleanup
|
2752 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
test cleanup in progress
|
2753 |
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3}); |
cleanup test
|
2754 |
$dbi->delete( |
cleanup
|
2755 |
table => $table1, |
2756 |
where => "$key1 = :$key1 and $key2 = :$key2", |
|
2757 |
where_param => {$key1 => 1, $key2 => 2} |
|
cleanup test
|
2758 |
); |
test cleanup in progress
|
2759 |
$rows = $dbi->select(table => $table1)->all; |
2760 |
is_deeply($rows, [{$key1 => 2, $key2 => 3}]); |
|
cleanup test
|
2761 | |
2762 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2763 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2764 |
$dbi->execute($create_table1); |
test cleanup
|
2765 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
2766 |
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1); |
cleanup test
|
2767 |
$dbi->delete( |
cleanup
|
2768 |
table => $table1, |
2769 |
where => [ |
|
2770 |
"$key1 = :$key1 and $key2 = :$key2", |
|
2771 |
{$key1 => 1, $key2 => 2} |
|
2772 |
] |
|
cleanup test
|
2773 |
); |
test cleanup in progress
|
2774 |
$rows = $dbi->select(table => $table1)->all; |
2775 |
is_deeply($rows, [{$key1 => 2, $key2 => 3}]); |
|
cleanup test
|
2776 | |
2777 | ||
2778 |
test 'update() string where'; |
|
2779 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2780 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2781 |
$dbi->execute($create_table1); |
test cleanup
|
2782 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup test
|
2783 |
$dbi->update( |
cleanup
|
2784 |
{$key1 => 5}, |
2785 |
table => $table1, |
|
2786 |
where => "$key1 = :$key1 and $key2 = :$key2", |
|
2787 |
where_param => {$key1 => 1, $key2 => 2} |
|
cleanup test
|
2788 |
); |
test cleanup in progress
|
2789 |
$rows = $dbi->select(table => $table1)->all; |
2790 |
is_deeply($rows, [{$key1 => 5, $key2 => 2}]); |
|
cleanup test
|
2791 | |
2792 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2793 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2794 |
$dbi->execute($create_table1); |
test cleanup
|
2795 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup test
|
2796 |
$dbi->update( |
cleanup
|
2797 |
{$key1 => 5}, |
2798 |
table => $table1, |
|
2799 |
where => [ |
|
2800 |
"$key1 = :$key1 and $key2 = :$key2", |
|
2801 |
{$key1 => 1, $key2 => 2} |
|
2802 |
] |
|
cleanup test
|
2803 |
); |
test cleanup in progress
|
2804 |
$rows = $dbi->select(table => $table1)->all; |
2805 |
is_deeply($rows, [{$key1 => 5, $key2 => 2}]); |
|
cleanup test
|
2806 | |
2807 |
test 'insert id and primary_key option'; |
|
2808 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2809 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2810 |
$dbi->execute($create_table1_2); |
2811 |
$dbi->insert( |
|
cleanup
|
2812 |
{$key3 => 3}, |
2813 |
primary_key => [$key1, $key2], |
|
2814 |
table => $table1, |
|
2815 |
id => [1, 2], |
|
cleanup test
|
2816 |
); |
test cleanup in progress
|
2817 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2818 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2819 |
is($dbi->select(table => $table1)->one->{$key3}, 3); |
|
cleanup test
|
2820 | |
fixed bug that when id optio...
|
2821 |
$dbi->insert( |
2822 |
{$key3 => 3}, |
|
2823 |
primary_key => [$key1, $key2], |
|
2824 |
table => $table1, |
|
2825 |
id => [1, 2], |
|
2826 |
); |
|
2827 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
|
2828 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2829 |
is($dbi->select(table => $table1)->one->{$key3}, 3); |
|
2830 | ||
test cleanup in progress
|
2831 |
$dbi->delete_all(table => $table1); |
cleanup test
|
2832 |
$dbi->insert( |
cleanup
|
2833 |
{$key2 => 2, $key3 => 3}, |
2834 |
primary_key => $key1, |
|
2835 |
table => $table1, |
|
2836 |
id => 0, |
|
cleanup test
|
2837 |
); |
2838 | ||
test cleanup in progress
|
2839 |
is($dbi->select(table => $table1)->one->{$key1}, 0); |
2840 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2841 |
is($dbi->select(table => $table1)->one->{$key3}, 3); |
|
cleanup test
|
2842 | |
fixed bug that when id optio...
|
2843 |
$dbi = DBIx::Custom->connect; |
2844 |
eval { $dbi->execute("drop table $table1") }; |
|
2845 |
$dbi->execute($create_table1_2); |
|
2846 |
$dbi->insert( |
|
2847 |
{$key3 => 3}, |
|
2848 |
primary_key => $key1, |
|
2849 |
table => $table1, |
|
2850 |
id => bless({value => 1}, 'AAAA'), |
|
2851 |
filter => {$key1 => sub { shift->{value} }} |
|
2852 |
); |
|
2853 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
|
2854 |
is($dbi->select(table => $table1)->one->{$key3}, 3); |
|
2855 | ||
- id option work if id count...
|
2856 |
$dbi = DBIx::Custom->connect; |
2857 |
eval { $dbi->execute("drop table $table1") }; |
|
2858 |
$dbi->execute($create_table1_2); |
|
2859 |
$dbi->insert( |
|
cleanup
|
2860 |
{$key3 => 3}, |
2861 |
primary_key => [$key1, $key2], |
|
2862 |
table => $table1, |
|
2863 |
id => 1, |
|
- id option work if id count...
|
2864 |
); |
2865 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
|
2866 |
ok(!$dbi->select(table => $table1)->one->{$key2}); |
|
2867 |
is($dbi->select(table => $table1)->one->{$key3}, 3); |
|
2868 | ||
cleanup test
|
2869 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
2870 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2871 |
$dbi->execute($create_table1_2); |
2872 |
$dbi->insert( |
|
cleanup
|
2873 |
{$key3 => 3}, |
2874 |
primary_key => [$key1, $key2], |
|
2875 |
table => $table1, |
|
2876 |
id => [1, 2], |
|
cleanup test
|
2877 |
); |
test cleanup in progress
|
2878 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2879 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2880 |
is($dbi->select(table => $table1)->one->{$key3}, 3); |
|
test cleanup
|
2881 | |
- insert method id value is ...
|
2882 |
$dbi = DBIx::Custom->connect; |
2883 |
eval { $dbi->execute("drop table $table1") }; |
|
2884 |
$dbi->execute($create_table1_2); |
|
2885 |
$param = {$key3 => 3, $key2 => 4}; |
|
2886 |
$dbi->insert( |
|
cleanup
|
2887 |
$param, |
2888 |
primary_key => [$key1, $key2], |
|
2889 |
table => $table1, |
|
2890 |
id => [1, 2], |
|
- insert method id value is ...
|
2891 |
); |
2892 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
|
2893 |
is($dbi->select(table => $table1)->one->{$key2}, 4); |
|
2894 |
is($dbi->select(table => $table1)->one->{$key3}, 3); |
|
2895 |
is_deeply($param, {$key3 => 3, $key2 => 4}); |
|
2896 | ||
added test
|
2897 |
$dbi = DBIx::Custom->connect; |
2898 |
eval { $dbi->execute("drop table $table1") }; |
|
2899 |
$dbi->execute($create_table1_2); |
|
2900 |
$param = {$key3 => 3, $key2 => 4}; |
|
2901 |
$query = $dbi->insert( |
|
cleanup
|
2902 |
$param, |
2903 |
primary_key => [$key1, $key2], |
|
2904 |
table => $table1, |
|
2905 |
id => [1, 2], |
|
2906 |
query => 1 |
|
added test
|
2907 |
); |
micro optimization
|
2908 |
ok(ref $query); |
added test
|
2909 |
is_deeply($param, {$key3 => 3, $key2 => 4}); |
2910 | ||
cleanup test
|
2911 |
test 'model insert id and primary_key option'; |
2912 |
$dbi = MyDBI6->connect; |
|
finishied sqlite test cleanu...
|
2913 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2914 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2915 |
$dbi->model($table1)->insert( |
cleanup
|
2916 |
{$key3 => 3}, |
2917 |
id => [1, 2], |
|
cleanup test
|
2918 |
); |
test cleanup in progress
|
2919 |
$result = $dbi->model($table1)->select; |
cleanup test
|
2920 |
$row = $result->one; |
test cleanup in progress
|
2921 |
is($row->{$key1}, 1); |
2922 |
is($row->{$key2}, 2); |
|
2923 |
is($row->{$key3}, 3); |
|
cleanup test
|
2924 | |
2925 |
$dbi = MyDBI6->connect; |
|
finishied sqlite test cleanu...
|
2926 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2927 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2928 |
$dbi->model($table1)->insert( |
cleanup
|
2929 |
{$key3 => 3}, |
2930 |
id => [1, 2] |
|
cleanup test
|
2931 |
); |
test cleanup in progress
|
2932 |
$result = $dbi->model($table1)->select; |
cleanup test
|
2933 |
$row = $result->one; |
test cleanup in progress
|
2934 |
is($row->{$key1}, 1); |
2935 |
is($row->{$key2}, 2); |
|
2936 |
is($row->{$key3}, 3); |
|
cleanup test
|
2937 | |
2938 |
test 'update and id option'; |
|
2939 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2940 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2941 |
$dbi->execute($create_table1_2); |
cleanup
|
2942 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
2943 |
$dbi->update( |
cleanup
|
2944 |
{$key3 => 4}, |
2945 |
table => $table1, |
|
2946 |
primary_key => [$key1, $key2], |
|
2947 |
id => [1, 2], |
|
cleanup test
|
2948 |
); |
test cleanup in progress
|
2949 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2950 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2951 |
is($dbi->select(table => $table1)->one->{$key3}, 4); |
|
cleanup test
|
2952 | |
test cleanup in progress
|
2953 |
$dbi->delete_all(table => $table1); |
cleanup
|
2954 |
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
2955 |
$dbi->update( |
cleanup
|
2956 |
{$key3 => 4}, |
2957 |
table => $table1, |
|
2958 |
primary_key => $key1, |
|
2959 |
id => 0, |
|
cleanup test
|
2960 |
); |
test cleanup in progress
|
2961 |
is($dbi->select(table => $table1)->one->{$key1}, 0); |
2962 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2963 |
is($dbi->select(table => $table1)->one->{$key3}, 4); |
|
cleanup test
|
2964 | |
2965 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2966 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2967 |
$dbi->execute($create_table1_2); |
cleanup
|
2968 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
2969 |
$dbi->update( |
cleanup
|
2970 |
{$key3 => 4}, |
2971 |
table => $table1, |
|
2972 |
primary_key => [$key1, $key2], |
|
2973 |
id => [1, 2] |
|
cleanup test
|
2974 |
); |
test cleanup in progress
|
2975 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2976 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2977 |
is($dbi->select(table => $table1)->one->{$key3}, 4); |
|
cleanup test
|
2978 | |
2979 | ||
2980 |
test 'model update and id option'; |
|
2981 |
$dbi = MyDBI6->connect; |
|
finishied sqlite test cleanu...
|
2982 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2983 |
$dbi->execute($create_table1_2); |
cleanup
|
2984 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
test cleanup in progress
|
2985 |
$dbi->model($table1)->update( |
cleanup
|
2986 |
{$key3 => 4}, |
2987 |
id => [1, 2], |
|
cleanup test
|
2988 |
); |
test cleanup in progress
|
2989 |
$result = $dbi->model($table1)->select; |
cleanup test
|
2990 |
$row = $result->one; |
test cleanup in progress
|
2991 |
is($row->{$key1}, 1); |
2992 |
is($row->{$key2}, 2); |
|
2993 |
is($row->{$key3}, 4); |
|
cleanup test
|
2994 | |
2995 | ||
2996 |
test 'delete and id option'; |
|
2997 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
2998 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
2999 |
$dbi->execute($create_table1_2); |
cleanup
|
3000 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
3001 |
$dbi->delete( |
cleanup
|
3002 |
table => $table1, |
3003 |
primary_key => [$key1, $key2], |
|
3004 |
id => [1, 2], |
|
cleanup test
|
3005 |
); |
test cleanup in progress
|
3006 |
is_deeply($dbi->select(table => $table1)->all, []); |
cleanup test
|
3007 | |
cleanup
|
3008 |
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
3009 |
$dbi->delete( |
cleanup
|
3010 |
table => $table1, |
3011 |
primary_key => $key1, |
|
3012 |
id => 0, |
|
cleanup test
|
3013 |
); |
test cleanup in progress
|
3014 |
is_deeply($dbi->select(table => $table1)->all, []); |
cleanup test
|
3015 | |
3016 | ||
3017 |
test 'model delete and id option'; |
|
3018 |
$dbi = MyDBI6->connect; |
|
finishied sqlite test cleanu...
|
3019 |
eval { $dbi->execute("drop table $table1") }; |
3020 |
eval { $dbi->execute("drop table $table2") }; |
|
3021 |
eval { $dbi->execute("drop table $table3") }; |
|
cleanup test
|
3022 |
$dbi->execute($create_table1_2); |
3023 |
$dbi->execute($create_table2_2); |
|
3024 |
$dbi->execute($create_table3); |
|
cleanup
|
3025 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
test cleanup in progress
|
3026 |
$dbi->model($table1)->delete(id => [1, 2]); |
3027 |
is_deeply($dbi->select(table => $table1)->all, []); |
|
cleanup
|
3028 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2); |
test cleanup in progress
|
3029 |
$dbi->model($table1)->delete(id => [1, 2]); |
3030 |
is_deeply($dbi->select(table => $table1)->all, []); |
|
cleanup
|
3031 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3); |
test cleanup in progress
|
3032 |
$dbi->model($table3)->delete(id => [1, 2]); |
3033 |
is_deeply($dbi->select(table => $table3)->all, []); |
|
cleanup test
|
3034 | |
3035 | ||
3036 |
test 'select and id option'; |
|
3037 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
3038 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3039 |
$dbi->execute($create_table1_2); |
cleanup
|
3040 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
3041 |
$result = $dbi->select( |
cleanup
|
3042 |
table => $table1, |
3043 |
primary_key => [$key1, $key2], |
|
3044 |
id => [1, 2] |
|
cleanup test
|
3045 |
); |
3046 |
$row = $result->one; |
|
test cleanup in progress
|
3047 |
is($row->{$key1}, 1); |
3048 |
is($row->{$key2}, 2); |
|
3049 |
is($row->{$key3}, 3); |
|
cleanup test
|
3050 | |
test cleanup in progress
|
3051 |
$dbi->delete_all(table => $table1); |
cleanup
|
3052 |
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
3053 |
$result = $dbi->select( |
cleanup
|
3054 |
table => $table1, |
3055 |
primary_key => $key1, |
|
3056 |
id => 0, |
|
cleanup test
|
3057 |
); |
3058 |
$row = $result->one; |
|
test cleanup in progress
|
3059 |
is($row->{$key1}, 0); |
3060 |
is($row->{$key2}, 2); |
|
3061 |
is($row->{$key3}, 3); |
|
cleanup test
|
3062 | |
test cleanup in progress
|
3063 |
$dbi->delete_all(table => $table1); |
cleanup
|
3064 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
cleanup test
|
3065 |
$result = $dbi->select( |
cleanup
|
3066 |
table => $table1, |
3067 |
primary_key => [$key1, $key2], |
|
3068 |
id => [1, 2] |
|
cleanup test
|
3069 |
); |
3070 |
$row = $result->one; |
|
test cleanup in progress
|
3071 |
is($row->{$key1}, 1); |
3072 |
is($row->{$key2}, 2); |
|
3073 |
is($row->{$key3}, 3); |
|
cleanup test
|
3074 | |
3075 | ||
3076 |
test 'model select_at'; |
|
3077 |
$dbi = MyDBI6->connect; |
|
finishied sqlite test cleanu...
|
3078 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3079 |
$dbi->execute($create_table1_2); |
cleanup
|
3080 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1); |
test cleanup in progress
|
3081 |
$result = $dbi->model($table1)->select(id => [1, 2]); |
cleanup test
|
3082 |
$row = $result->one; |
test cleanup in progress
|
3083 |
is($row->{$key1}, 1); |
3084 |
is($row->{$key2}, 2); |
|
3085 |
is($row->{$key3}, 3); |
|
cleanup test
|
3086 | |
3087 |
test 'column separator is default .'; |
|
3088 |
$dbi = MyDBI7->connect; |
|
cleanup test
|
3089 |
$dbi->user_table_info($user_table_info); |
finishied sqlite test cleanu...
|
3090 |
eval { $dbi->execute("drop table $table1") }; |
3091 |
eval { $dbi->execute("drop table $table2") }; |
|
cleanup test
|
3092 |
$dbi->execute($create_table1); |
3093 |
$dbi->execute($create_table2); |
|
fixed setup method logic
|
3094 |
$dbi->setup_model; |
test cleanup
|
3095 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
3096 |
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2); |
test cleanup in progress
|
3097 |
$model = $dbi->model($table1); |
cleanup test
|
3098 |
$result = $model->select( |
cleanup
|
3099 |
column => [$model->column($table2)], |
3100 |
where => {"$table1.$key1" => 1} |
|
cleanup test
|
3101 |
); |
3102 |
is_deeply($result->one, |
|
cleanup
|
3103 |
{"$table2.$key1" => 1, "$table2.$key3" => 3}); |
cleanup test
|
3104 | |
3105 |
$result = $model->select( |
|
cleanup
|
3106 |
column => [$model->column($table2 => [$key1, $key3])], |
3107 |
where => {"$table1.$key1" => 1} |
|
cleanup test
|
3108 |
); |
3109 |
is_deeply($result->one, |
|
cleanup
|
3110 |
{"$table2.$key1" => 1, "$table2.$key3" => 3}); |
test cleanup
|
3111 | |
cleanup test
|
3112 |
test 'separator'; |
3113 |
$dbi = DBIx::Custom->connect; |
|
cleanup test
|
3114 |
$dbi->user_table_info($user_table_info); |
finishied sqlite test cleanu...
|
3115 |
eval { $dbi->execute("drop table $table1") }; |
3116 |
eval { $dbi->execute("drop table $table2") }; |
|
cleanup test
|
3117 |
$dbi->execute($create_table1); |
3118 |
$dbi->execute($create_table2); |
|
test cleanup
|
3119 | |
cleanup test
|
3120 |
$dbi->create_model( |
cleanup
|
3121 |
table => $table1, |
3122 |
join => [ |
|
3123 |
"left outer join $table2 on $table1.$key1 = $table2.$key1" |
|
3124 |
], |
|
3125 |
primary_key => [$key1], |
|
cleanup test
|
3126 |
); |
3127 |
$model2 = $dbi->create_model( |
|
cleanup
|
3128 |
table => $table2, |
cleanup test
|
3129 |
); |
fixed setup method logic
|
3130 |
$dbi->setup_model; |
test cleanup
|
3131 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
3132 |
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2); |
test cleanup in progress
|
3133 |
$model = $dbi->model($table1); |
cleanup test
|
3134 |
$result = $model->select( |
cleanup
|
3135 |
column => [ |
3136 |
$model->mycolumn, |
|
3137 |
{$table2 => [$key1, $key3]} |
|
3138 |
], |
|
3139 |
where => {"$table1.$key1" => 1} |
|
cleanup test
|
3140 |
); |
3141 |
is_deeply($result->one, |
|
cleanup
|
3142 |
{$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3}); |
test cleanup in progress
|
3143 |
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3}); |
test cleanup
|
3144 | |
cleanup test
|
3145 |
$dbi->separator('__'); |
test cleanup in progress
|
3146 |
$model = $dbi->model($table1); |
cleanup test
|
3147 |
$result = $model->select( |
cleanup
|
3148 |
column => [ |
3149 |
$model->mycolumn, |
|
3150 |
{$table2 => [$key1, $key3]} |
|
3151 |
], |
|
3152 |
where => {"$table1.$key1" => 1} |
|
cleanup test
|
3153 |
); |
3154 |
is_deeply($result->one, |
|
improved test
|
3155 |
{$key1 => 1, $key2 => 2, u2"${table2}__$key1" => 1, u2"${table2}__$key3" => 3}); |
test cleanup in progress
|
3156 |
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3}); |
test cleanup
|
3157 | |
cleanup test
|
3158 |
$dbi->separator('-'); |
test cleanup in progress
|
3159 |
$model = $dbi->model($table1); |
cleanup test
|
3160 |
$result = $model->select( |
cleanup
|
3161 |
column => [ |
3162 |
$model->mycolumn, |
|
3163 |
{$table2 => [$key1, $key3]} |
|
3164 |
], |
|
3165 |
where => {"$table1.$key1" => 1} |
|
cleanup test
|
3166 |
); |
3167 |
is_deeply($result->one, |
|
improved test
|
3168 |
{$key1 => 1, $key2 => 2, hy"$table2-$key1" => 1, hy"$table2-$key3" => 3}); |
test cleanup in progress
|
3169 |
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3}); |
test cleanup
|
3170 | |
3171 | ||
cleanup test
|
3172 |
test 'filter_off'; |
3173 |
$dbi = DBIx::Custom->connect; |
|
cleanup test
|
3174 |
$dbi->user_table_info($user_table_info); |
finishied sqlite test cleanu...
|
3175 |
eval { $dbi->execute("drop table $table1") }; |
3176 |
eval { $dbi->execute("drop table $table2") }; |
|
cleanup test
|
3177 |
$dbi->execute($create_table1); |
3178 |
$dbi->execute($create_table2); |
|
test cleanup
|
3179 | |
cleanup test
|
3180 |
$dbi->create_model( |
cleanup
|
3181 |
table => $table1, |
3182 |
join => [ |
|
3183 |
"left outer join $table2 on $table1.$key1 = $table2.$key1" |
|
3184 |
], |
|
3185 |
primary_key => [$key1], |
|
cleanup test
|
3186 |
); |
fixed setup method logic
|
3187 |
$dbi->setup_model; |
test cleanup
|
3188 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
test cleanup in progress
|
3189 |
$model = $dbi->model($table1); |
3190 |
$result = $model->select(column => $key1); |
|
3191 |
$result->filter($key1 => sub { $_[0] * 2 }); |
|
3192 |
is_deeply($result->one, {$key1 => 2}); |
|
test cleanup
|
3193 | |
cleanup test
|
3194 |
test 'available_datetype'; |
3195 |
$dbi = DBIx::Custom->connect; |
|
3196 |
ok($dbi->can('available_datatype')); |
|
test cleanup
|
3197 | |
3198 | ||
cleanup test
|
3199 |
test 'select prefix option'; |
3200 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
3201 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3202 |
$dbi->execute($create_table1); |
test cleanup
|
3203 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
finishied sqlite test cleanu...
|
3204 |
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all; |
test cleanup in progress
|
3205 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table"); |
test cleanup
|
3206 | |
- added EXPERIMENTAL pass at...
|
3207 | |
added tests
|
3208 |
test 'mapper'; |
3209 |
$dbi = DBIx::Custom->connect; |
|
3210 |
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map( |
|
cleanup
|
3211 |
id => {key => "$table1.id"}, |
3212 |
author => ["$table1.author" => sub { '%' . $_[0] . '%' }], |
|
3213 |
price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }} |
|
added tests
|
3214 |
); |
3215 |
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%', |
|
cleanup
|
3216 |
"$table1.price" => 1900}); |
added tests
|
3217 | |
added EXPERIMENTAL like_valu...
|
3218 |
$dbi = DBIx::Custom->connect; |
3219 |
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map( |
|
cleanup
|
3220 |
id => {key => "$table1.id"}, |
3221 |
author => ["$table1.author" => $dbi->like_value], |
|
3222 |
price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }} |
|
added EXPERIMENTAL like_valu...
|
3223 |
); |
3224 |
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%', |
|
cleanup
|
3225 |
"$table1.price" => 1900}); |
added EXPERIMENTAL like_valu...
|
3226 | |
added tests
|
3227 |
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map( |
cleanup
|
3228 |
id => {key => "$table1.id"}, |
3229 |
author => ["$table1.author" => sub { '%' . $_[0] . '%' }], |
|
3230 |
price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }] |
|
added tests
|
3231 |
); |
3232 |
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'}); |
|
3233 | ||
3234 |
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map( |
|
cleanup
|
3235 |
id => {key => "$table1.id"}, |
3236 |
author => ["$table1.author" => sub { '%' . $_[0] . '%' }], |
|
3237 |
price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }] |
|
added tests
|
3238 |
); |
3239 |
is_deeply($param, {}); |
|
3240 | ||
3241 |
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map( |
|
cleanup
|
3242 |
id => {key => "$table1.id"}, |
3243 |
price => {key => "$table1.price", condition => 'exists'} |
|
added tests
|
3244 |
); |
3245 |
is_deeply($param, {"$table1.price" => undef}); |
|
3246 | ||
3247 |
$param = $dbi->mapper(param => {price => 'a'})->map( |
|
cleanup
|
3248 |
id => {key => "$table1.id", condition => 'exists'}, |
3249 |
price => ["$table1.price", sub { '%' . $_[0] }, 'exists'] |
|
added tests
|
3250 |
); |
3251 |
is_deeply($param, {"$table1.price" => '%a'}); |
|
3252 | ||
3253 |
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map( |
|
cleanup
|
3254 |
id => {key => "$table1.id"}, |
3255 |
price => ["$table1.price", sub { '%' . $_[0] }] |
|
added tests
|
3256 |
); |
3257 |
is_deeply($param, {"$table1.price" => '%a'}); |
|
3258 | ||
- added {key => ..., value =...
|
3259 |
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map( |
cleanup
|
3260 |
price => sub { '%' . $_[0] }, |
3261 |
author => 'book.author' |
|
- added {KEY => sub { VALUE ...
|
3262 |
); |
- added {key => ..., value =...
|
3263 |
is_deeply($param, {price => '%a', 'book.author' => 'b'}); |
- added {KEY => sub { VALUE ...
|
3264 | |
- added EXPERIMENTAL pass at...
|
3265 |
eval { $dbi->execute("drop table $table1") }; |
3266 |
$dbi->execute($create_table1); |
|
test cleanup
|
3267 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
3268 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
- added EXPERIMENTAL pass at...
|
3269 | |
3270 |
$where = $dbi->where; |
|
3271 |
$where->clause(['and', ":${key1}{=}"]); |
|
3272 |
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map; |
|
3273 |
$where->param($param); |
|
3274 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1}); |
|
3275 |
$row = $result->all; |
|
3276 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
|
3277 | ||
3278 |
$where = $dbi->where; |
|
3279 |
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]); |
|
3280 |
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map; |
|
3281 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]}); |
|
3282 |
$row = $result->all; |
|
3283 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
|
3284 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]}); |
|
3285 |
$row = $result->all; |
|
3286 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
|
3287 | ||
3288 |
$where = $dbi->where; |
|
3289 |
$where->clause(['and', ":${key1}{=}"]); |
|
3290 |
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map; |
|
3291 |
$where->param($param); |
|
3292 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]}); |
|
3293 |
$row = $result->all; |
|
3294 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
|
3295 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]}); |
|
3296 |
$row = $result->all; |
|
3297 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
|
3298 | ||
- added {key => ..., value =...
|
3299 | |
- added EXPERIMENTAL pass at...
|
3300 |
$where = $dbi->where; |
3301 |
$where->clause(['and', ":${key1}{=}"]); |
|
3302 |
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length') |
|
cleanup
|
3303 |
->pass([$key1, $key2])->map; |
- added EXPERIMENTAL pass at...
|
3304 |
$where->param($param); |
3305 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1}); |
|
3306 |
$row = $result->all; |
|
3307 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
|
3308 | ||
3309 |
$where = $dbi->where; |
|
3310 |
$where->clause(['and', ":${key1}{=}"]); |
|
3311 |
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map; |
|
3312 |
$where->param($param); |
|
3313 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1}); |
|
3314 |
$row = $result->all; |
|
3315 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
|
3316 | ||
3317 |
$where = $dbi->where; |
|
3318 |
$where->clause(['and', ":${key1}{=}"]); |
|
3319 |
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 }) |
|
cleanup
|
3320 |
->pass([$key1, $key2])->map; |
- added EXPERIMENTAL pass at...
|
3321 |
$where->param($param); |
3322 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1}); |
|
3323 |
$row = $result->all; |
|
3324 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
|
3325 | ||
- added {key => ..., value =...
|
3326 | |
- added EXPERIMENTAL pass at...
|
3327 |
$where = $dbi->where; |
3328 |
$where->clause(['and', ":${key1}{=}"]); |
|
3329 |
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map; |
|
3330 |
$where->param($param); |
|
3331 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1}); |
|
3332 |
$row = $result->all; |
|
3333 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
|
3334 | ||
3335 |
$where = $dbi->where; |
|
3336 |
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map( |
|
cleanup
|
3337 |
id => {key => "$table1.id"}, |
3338 |
author => ["$table1.author", sub { '%' . $_[0] . '%' }], |
|
3339 |
price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }} |
|
- added EXPERIMENTAL pass at...
|
3340 |
); |
3341 |
$where->param($param); |
|
3342 |
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%', |
|
cleanup
|
3343 |
"$table1.price" => 1900}); |
- added EXPERIMENTAL pass at...
|
3344 | |
3345 |
$where = $dbi->where; |
|
3346 |
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map( |
|
cleanup
|
3347 |
id => {key => "$table1.id"}, |
3348 |
author => ["$table1.author", sub { '%' . $_[0] . '%' }], |
|
3349 |
price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }] |
|
- added EXPERIMENTAL pass at...
|
3350 |
); |
3351 |
$where->param($param); |
|
3352 |
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'}); |
|
3353 | ||
3354 |
$where = $dbi->where; |
|
3355 |
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map( |
|
cleanup
|
3356 |
id => {key => "$table1.id"}, |
3357 |
author => ["$table1.author", sub { '%' . $_[0] . '%' }], |
|
3358 |
price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }] |
|
- added EXPERIMENTAL pass at...
|
3359 |
); |
3360 |
$where->param($param); |
|
3361 |
is_deeply($where->param, {}); |
|
3362 | ||
3363 |
$where = $dbi->where; |
|
3364 |
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map( |
|
cleanup
|
3365 |
id => {key => "$table1.id"}, |
3366 |
price => {key => "$table1.price", condition => 'exists'} |
|
- added EXPERIMENTAL pass at...
|
3367 |
); |
3368 |
is_deeply($param, {"$table1.id" => undef,"$table1.price" => undef}); |
|
3369 | ||
3370 |
$where = $dbi->where; |
|
3371 |
$param = $dbi->mapper(param => {price => 'a'})->map( |
|
cleanup
|
3372 |
id => {key => "$table1.id", condition => 'exists'}, |
3373 |
price => ["$table1.price", sub { '%' . $_[0] }, 'exists'] |
|
- added EXPERIMENTAL pass at...
|
3374 |
); |
3375 |
is_deeply($param, {"$table1.price" => '%a'}); |
|
3376 | ||
3377 |
$where = $dbi->where; |
|
3378 |
$param = $dbi->mapper(param => {id => [1, 2], author => 'Ken', price => 1900})->map( |
|
cleanup
|
3379 |
id => {key => "$table1.id"}, |
3380 |
author => ["$table1.author", sub { '%' . $_[0] . '%' }], |
|
3381 |
price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }} |
|
- added EXPERIMENTAL pass at...
|
3382 |
); |
3383 |
is_deeply($param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%', |
|
cleanup
|
3384 |
"$table1.price" => 1900}); |
- added EXPERIMENTAL pass at...
|
3385 | |
3386 |
$where = $dbi->where; |
|
3387 |
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900}, condition => 'length')->map( |
|
cleanup
|
3388 |
id => {key => "$table1.id"}, |
3389 |
author => ["$table1.author", sub { '%' . $_[0] . '%' }], |
|
3390 |
price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }} |
|
- added EXPERIMENTAL pass at...
|
3391 |
); |
3392 |
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%', |
|
cleanup
|
3393 |
"$table1.price" => 1900}); |
- added EXPERIMENTAL pass at...
|
3394 | |
3395 |
$where = $dbi->where; |
|
3396 |
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map( |
|
cleanup
|
3397 |
id => {key => "$table1.id", condition => 'length'}, |
3398 |
author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'], |
|
3399 |
price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }} |
|
- added EXPERIMENTAL pass at...
|
3400 |
); |
3401 |
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%', |
|
cleanup
|
3402 |
"$table1.price" => 1900}); |
- added EXPERIMENTAL pass at...
|
3403 | |
3404 |
$where = $dbi->where; |
|
3405 |
$param = $dbi->mapper(param => {id => 'a', author => 'b', price => 'c'}, pass => [qw/id author/]) |
|
cleanup
|
3406 |
->map(price => {key => 'book.price'}); |
- added EXPERIMENTAL pass at...
|
3407 |
is_deeply($param, {id => 'a', author => 'b', 'book.price' => 'c'}); |
3408 | ||
- DBIx::Custom::Mapper::map ...
|
3409 |
$param = $dbi->mapper(param => {author => 'Ken',})->map( |
3410 |
author => ["$table1.author" => '%<value>%'], |
|
3411 |
); |
|
3412 |
is_deeply($param, {"$table1.author" => '%Ken%'}); |
|
3413 | ||
3414 |
$param = $dbi->mapper(param => {author => 'Ken'})->map( |
|
3415 |
author => ["$table1.author" => 'p'], |
|
3416 |
); |
|
3417 |
is_deeply($param, {"$table1.author" => 'p'}); |
|
3418 | ||
3419 |
$param = $dbi->mapper(param => {author => 'Ken',})->map( |
|
3420 |
author => {value => '%<value>%'} |
|
3421 |
); |
|
3422 |
is_deeply($param, {"author" => '%Ken%'}); |
|
3423 | ||
test cleanup
|
3424 |
test 'order'; |
3425 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
3426 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
3427 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3428 |
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1); |
3429 |
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1); |
|
3430 |
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1); |
|
3431 |
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1); |
|
test cleanup
|
3432 |
my $order = $dbi->order; |
finishied sqlite test cleanu...
|
3433 |
$order->prepend($key1, "$key2 desc"); |
3434 |
$result = $dbi->select(table => $table1, append => $order); |
|
test cleanup in progress
|
3435 |
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}, |
cleanup
|
3436 |
{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]); |
finishied sqlite test cleanu...
|
3437 |
$order->prepend("$key1 desc"); |
3438 |
$result = $dbi->select(table => $table1, append => $order); |
|
test cleanup in progress
|
3439 |
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}, |
cleanup
|
3440 |
{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]); |
test cleanup
|
3441 | |
3442 |
$order = $dbi->order; |
|
finishied sqlite test cleanu...
|
3443 |
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']); |
test cleanup in progress
|
3444 |
$result = $dbi->select(table => $table1, |
cleanup
|
3445 |
column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]], |
3446 |
append => $order); |
|
test cleanup in progress
|
3447 |
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3}, |
cleanup
|
3448 |
{"$table1-$key1" => 1, "$table1-$key2" => 1}, |
3449 |
{"$table1-$key1" => 2, "$table1-$key2" => 4}, |
|
3450 |
{"$table1-$key1" => 2, "$table1-$key2" => 2}]); |
|
test cleanup
|
3451 | |
3452 |
test 'tag_parse'; |
|
3453 |
$dbi = DBIx::Custom->connect; |
|
3454 |
$dbi->tag_parse(0); |
|
finishied sqlite test cleanu...
|
3455 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
3456 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3457 |
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1); |
3458 |
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})}; |
|
test cleanup
|
3459 |
ok($@); |
3460 | ||
- DBIx::Custom::QueryBuilder...
|
3461 |
test 'DBIX_CUSTOM_TAG_PARSE environment variable'; |
3462 |
{ |
|
cleanup
|
3463 |
$ENV{DBIX_CUSTOM_TAG_PARSE} = 0; |
3464 |
$dbi = DBIx::Custom->connect; |
|
3465 |
eval { $dbi->execute("drop table $table1") }; |
|
3466 |
$dbi->execute($create_table1); |
|
3467 |
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1); |
|
3468 |
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})}; |
|
3469 |
ok($@); |
|
3470 |
eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) }; |
|
3471 |
ok($@); |
|
3472 |
delete$ENV{DBIX_CUSTOM_TAG_PARSE}; |
|
- DBIx::Custom::QueryBuilder...
|
3473 |
} |
3474 | ||
3475 |
{ |
|
cleanup
|
3476 |
$ENV{DBIX_CUSTOM_TAG_PARSE} = 0; |
3477 |
$dbi = DBIx::Custom->connect; |
|
3478 |
eval { $dbi->execute("drop table $table1") }; |
|
3479 |
$dbi->execute($create_table1); |
|
3480 |
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1); |
|
3481 |
is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1); |
|
3482 |
delete$ENV{DBIX_CUSTOM_TAG_PARSE}; |
|
- DBIx::Custom::QueryBuilder...
|
3483 |
} |
3484 | ||
test cleanup
|
3485 |
test 'last_sql'; |
3486 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
3487 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
3488 |
$dbi->execute($create_table1); |
finishied sqlite test cleanu...
|
3489 |
$dbi->execute("select * from $table1"); |
micro optimization
|
3490 |
is($dbi->last_sql, " select * from $table1"); |
test cleanup
|
3491 | |
3492 |
eval{$dbi->execute("aaa")}; |
|
micro optimization
|
3493 |
is($dbi->last_sql, ' aaa'); |
test cleanup
|
3494 | |
3495 |
test 'DBIx::Custom header'; |
|
3496 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
3497 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
3498 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3499 |
$result = $dbi->execute("select $key1 as h1, $key2 as h2 from $table1"); |
test cleanup
|
3500 |
is_deeply([map { lc } @{$result->header}], [qw/h1 h2/]); |
test cleanup
|
3501 | |
3502 |
test 'Named placeholder :name(operater) syntax'; |
|
fixed id option bug when col...
|
3503 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
3504 |
$dbi->execute($create_table1_2); |
test cleanup
|
3505 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
3506 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
test cleanup
|
3507 | |
test cleanup in progress
|
3508 |
$source = "select * from $table1 where :${key1}{=} and :${key2}{=}"; |
cleanup
|
3509 |
$result = $dbi->execute($source, {$key1 => 1, $key2 => 2}); |
test cleanup
|
3510 |
$rows = $result->all; |
test cleanup in progress
|
3511 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]); |
test cleanup
|
3512 | |
test cleanup in progress
|
3513 |
$source = "select * from $table1 where :${key1}{ = } and :${key2}{=}"; |
cleanup
|
3514 |
$result = $dbi->execute($source, {$key1 => 1, $key2 => 2}); |
test cleanup
|
3515 |
$rows = $result->all; |
test cleanup in progress
|
3516 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]); |
test cleanup
|
3517 | |
test cleanup in progress
|
3518 |
$source = "select * from $table1 where :${key1}{<} and :${key2}{=}"; |
cleanup
|
3519 |
$result = $dbi->execute($source, {$key1 => 5, $key2 => 2}); |
test cleanup
|
3520 |
$rows = $result->all; |
test cleanup in progress
|
3521 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]); |
test cleanup
|
3522 | |
test cleanup in progress
|
3523 |
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}"; |
test cleanup
|
3524 |
$result = $dbi->execute( |
cleanup
|
3525 |
$source, |
3526 |
{"$table1.$key1" => 1, "$table1.$key2" => 1}, |
|
3527 |
filter => {"$table1.$key2" => sub { $_[0] * 2 }} |
|
test cleanup
|
3528 |
); |
3529 |
$rows = $result->all; |
|
test cleanup in progress
|
3530 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]); |
test cleanup
|
3531 | |
3532 |
test 'high perfomance way'; |
|
fixed id option bug when col...
|
3533 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
3534 |
$dbi->execute($create_table1_highperformance); |
3535 |
$rows = [ |
|
cleanup
|
3536 |
{$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7}, |
3537 |
{$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8}, |
|
test cleanup
|
3538 |
]; |
3539 |
{ |
|
cleanup
|
3540 |
my $query; |
3541 |
for my $row (@$rows) { |
|
3542 |
$query ||= $dbi->insert($row, table => $table1, query => 1); |
|
3543 |
$dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }}); |
|
3544 |
} |
|
3545 |
is_deeply($dbi->select(table => $table1)->all, |
|
3546 |
[ |
|
3547 |
{$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7}, |
|
3548 |
{$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8}, |
|
3549 |
] |
|
3550 |
); |
|
test cleanup
|
3551 |
} |
3552 | ||
fixed id option bug when col...
|
3553 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
3554 |
$dbi->execute($create_table1_highperformance); |
3555 |
$rows = [ |
|
cleanup
|
3556 |
{$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7}, |
3557 |
{$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8}, |
|
test cleanup
|
3558 |
]; |
3559 |
{ |
|
cleanup
|
3560 |
my $query; |
3561 |
my $sth; |
|
3562 |
for my $row (@$rows) { |
|
3563 |
$query ||= $dbi->insert($row, table => $table1, query => 1); |
|
3564 |
$sth ||= $query->{sth}; |
|
3565 |
$sth->execute(map { $row->{$_} } sort keys %$row); |
|
3566 |
} |
|
3567 |
is_deeply($dbi->select(table => $table1)->all, |
|
3568 |
[ |
|
3569 |
{$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7}, |
|
3570 |
{$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8}, |
|
3571 |
] |
|
3572 |
); |
|
test cleanup
|
3573 |
} |
3574 | ||
fixed id option bug when col...
|
3575 |
eval { $dbi->execute("drop table $table1") }; |
- removed placeholder count ...
|
3576 |
$dbi->execute($create_table1_highperformance); |
3577 |
$rows = [ |
|
cleanup
|
3578 |
{$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5}, |
3579 |
{$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6}, |
|
- removed placeholder count ...
|
3580 |
]; |
3581 |
{ |
|
cleanup
|
3582 |
$model = $dbi->create_model(table => $table1, primary_key => $key1); |
3583 |
my $query; |
|
3584 |
for my $row (@$rows) { |
|
3585 |
$query ||= $model->insert($row, query => 1); |
|
3586 |
$model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }}); |
|
3587 |
} |
|
3588 |
is_deeply($dbi->select(table => $table1, append => 'order by key2')->all, |
|
3589 |
[ |
|
3590 |
{$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef}, |
|
3591 |
{$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef}, |
|
3592 |
] |
|
3593 |
); |
|
- removed placeholder count ...
|
3594 |
} |
3595 | ||
- DBIx::Custom::QueryBuilder...
|
3596 |
eval { $dbi->execute("drop table $table1") }; |
3597 |
$dbi->execute($create_table1); |
|
3598 |
{ |
|
cleanup
|
3599 |
$ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1; |
3600 |
$model = $dbi->create_model(table => $table1, primary_key => $key1); |
|
3601 |
eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)}; |
|
3602 |
like($@, qr/primary_key/); |
|
3603 |
delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE}; |
|
- DBIx::Custom::QueryBuilder...
|
3604 |
} |
3605 | ||
3606 |
{ |
|
cleanup
|
3607 |
$ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1; |
3608 |
$model = $dbi->create_model(table => $table1, primary_key => $key1); |
|
3609 |
$model->insert({$key1 => 1}); |
|
3610 |
$result = $model->execute("select * from $table1 where :${key1}{=}", id => 1, |
|
3611 |
table => $table1, primary_key => $key1); |
|
3612 |
is($result->one->{$key1}, 1); |
|
3613 |
delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE}; |
|
- DBIx::Custom::QueryBuilder...
|
3614 |
} |
3615 | ||
3616 |
eval { $dbi->execute("drop table $table1") }; |
|
3617 |
$dbi->execute($create_table1); |
|
3618 |
{ |
|
cleanup
|
3619 |
$model = $dbi->create_model(table => $table1, primary_key => $key1); |
3620 |
$model->insert({$key1 => 1}); |
|
3621 |
eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)}; |
|
3622 |
is($result->one->{$key1}, 1); |
|
- DBIx::Custom::QueryBuilder...
|
3623 |
} |
3624 | ||
fixed id option bug when col...
|
3625 |
test 'id option more'; |
3626 |
eval { $dbi->execute("drop table $table1") }; |
|
3627 |
$dbi->execute($create_table1_highperformance); |
|
3628 |
$row = { |
|
cleanup
|
3629 |
$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2 |
fixed id option bug when col...
|
3630 |
}; |
3631 |
$model = $dbi->create_model(table => $table1, primary_key => $key1); |
|
3632 |
$model->insert($row); |
|
3633 |
$query = $model->update({$key7 => 11}, id => 1, query => 1); |
|
3634 |
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }}); |
|
3635 |
is_deeply($dbi->select(table => $table1)->one, |
|
cleanup
|
3636 |
{$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2}, |
fixed id option bug when col...
|
3637 |
); |
3638 | ||
3639 |
eval { $dbi->execute("drop table $table1") }; |
|
3640 |
eval { $dbi->execute("drop table $table2") }; |
|
3641 |
$dbi->execute($create_table1); |
|
3642 |
$dbi->execute($create_table2); |
|
3643 |
$model = $dbi->create_model(table => $table1, primary_key => $key1); |
|
3644 |
$model->insert({$key1 => 1, $key2 => 2}); |
|
3645 |
$model = $dbi->create_model(table => $table2, primary_key => $key1, |
|
cleanup
|
3646 |
join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]); |
fixed id option bug when col...
|
3647 |
$model->insert({$key1 => 1, $key3 => 3}); |
3648 |
$result = $model->select( |
|
cleanup
|
3649 |
column => {$table1 => ["$key2"]}, |
3650 |
id => 1 |
|
fixed id option bug when col...
|
3651 |
); |
3652 |
is_deeply($result->all, [{"$table1.$key2" => 2}]); |
|
3653 | ||
3654 |
eval { $dbi->execute("drop table $table1") }; |
|
3655 |
$dbi->execute($create_table1_highperformance); |
|
3656 |
$row = { |
|
cleanup
|
3657 |
$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2 |
fixed id option bug when col...
|
3658 |
}; |
3659 |
$model = $dbi->create_model(table => $table1, primary_key => $key1); |
|
3660 |
$model->insert($row); |
|
3661 |
$query = $model->delete(id => 1, query => 1); |
|
3662 |
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }}); |
|
3663 |
is_deeply($dbi->select(table => $table1)->all, []); |
|
3664 | ||
3665 |
eval { $dbi->execute("drop table $table1") }; |
|
3666 |
eval { $dbi->execute($create_table1_highperformance) }; |
|
3667 |
$row = { |
|
cleanup
|
3668 |
$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2 |
fixed id option bug when col...
|
3669 |
}; |
3670 |
$model = $dbi->create_model(table => $table1, primary_key => $key1); |
|
3671 |
$model->insert($row); |
|
3672 |
$query = $model->select(id => 1, query => 1); |
|
3673 |
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }}); |
|
fixed sqlserver test bug
|
3674 |
$query = undef; |
fixed id option bug when col...
|
3675 |
is_deeply($dbi->select(table => $table1)->one, |
cleanup
|
3676 |
{$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2}, |
fixed id option bug when col...
|
3677 |
); |
3678 | ||
test cleanup
|
3679 |
test 'result'; |
3680 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
3681 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
3682 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3683 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
3684 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup
|
3685 | |
test cleanup in progress
|
3686 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3687 |
@rows = (); |
3688 |
while (my $row = $result->fetch) { |
|
cleanup
|
3689 |
push @rows, [@$row]; |
test cleanup
|
3690 |
} |
3691 |
is_deeply(\@rows, [[1, 2], [3, 4]]); |
|
3692 | ||
test cleanup in progress
|
3693 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3694 |
@rows = (); |
3695 |
while (my $row = $result->fetch_hash) { |
|
cleanup
|
3696 |
push @rows, {%$row}; |
test cleanup
|
3697 |
} |
test cleanup in progress
|
3698 |
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
3699 | |
3700 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
3701 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
3702 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3703 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
3704 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup
|
3705 | |
3706 |
test 'fetch_all'; |
|
test cleanup in progress
|
3707 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3708 |
$rows = $result->fetch_all; |
3709 |
is_deeply($rows, [[1, 2], [3, 4]]); |
|
3710 | ||
test cleanup in progress
|
3711 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3712 |
$rows = $result->fetch_hash_all; |
test cleanup in progress
|
3713 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
3714 | |
test cleanup in progress
|
3715 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3716 |
$result->dbi->filters({three_times => sub { $_[0] * 3}}); |
test cleanup in progress
|
3717 |
$result->filter({$key1 => 'three_times'}); |
test cleanup
|
3718 |
$rows = $result->fetch_all; |
3719 |
is_deeply($rows, [[3, 2], [9, 4]], "array"); |
|
3720 | ||
- fixed bug DBIx::Custom::Re...
|
3721 |
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1); |
3722 |
$result->dbi->filters({three_times => sub { $_[0] * 3}}); |
|
3723 |
$result->filter({$key1 => 'three_times'}); |
|
3724 |
$rows = $result->fetch_all; |
|
3725 |
is_deeply($rows, [[3, 3, 2], [9, 9, 4]], "array"); |
|
3726 | ||
test cleanup in progress
|
3727 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3728 |
$result->dbi->filters({three_times => sub { $_[0] * 3}}); |
test cleanup in progress
|
3729 |
$result->filter({$key1 => 'three_times'}); |
test cleanup
|
3730 |
$rows = $result->fetch_hash_all; |
test cleanup in progress
|
3731 |
is_deeply($rows, [{$key1 => 3, $key2 => 2}, {$key1 => 9, $key2 => 4}], "hash"); |
test cleanup
|
3732 | |
added EXPERIMENTAL DBIx::Cus...
|
3733 |
test 'flat'; |
3734 |
$result = $dbi->select(table => $table1); |
|
3735 |
$rows = [$result->flat]; |
|
3736 |
is_deeply($rows, [1, 2, 3, 4]); |
|
3737 | ||
added EXPERIMETAL DBIx::Cust...
|
3738 |
test 'kv'; |
3739 |
$dbi = DBIx::Custom->connect; |
|
3740 |
eval { $dbi->execute("drop table $table1") }; |
|
3741 |
$dbi->execute($create_table1); |
|
3742 |
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1); |
|
3743 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
3744 | ||
3745 |
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key1"); |
|
3746 |
$rows = $result->kv; |
|
3747 |
is_deeply($rows, {0 => {$key2 => 2}, 3 => {$key2 => 4}}); |
|
3748 | ||
3749 |
$dbi = DBIx::Custom->connect; |
|
3750 |
eval { $dbi->execute("drop table $table1") }; |
|
3751 |
$dbi->execute($create_table1); |
|
3752 |
$dbi->insert({$key1 => 0, $key2 => 1}, table => $table1); |
|
3753 |
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1); |
|
3754 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
3755 |
$dbi->insert({$key1 => 3, $key2 => 5}, table => $table1); |
|
3756 | ||
3757 |
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key2"); |
|
3758 |
$rows = $result->kv(multi => 1); |
|
3759 |
is_deeply($rows, { |
|
3760 |
0 => [ |
|
3761 |
{$key2 => 1}, |
|
3762 |
{$key2 => 2} |
|
3763 |
], |
|
3764 |
3 => [ |
|
3765 |
{$key2 => 4}, |
|
3766 |
{$key2 => 5} |
|
3767 |
] |
|
3768 |
}); |
|
3769 | ||
3770 | ||
- fixed bug DBIx::Custom::Re...
|
3771 |
test 'DBIx::Custom::Result fetch_multi'; |
3772 |
eval { $dbi->execute("drop table $table1") }; |
|
3773 |
$dbi->execute($create_table1); |
|
3774 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
|
3775 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
3776 |
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1); |
|
3777 |
$result = $dbi->select(table => $table1); |
|
3778 |
$rows = $result->fetch_multi(2); |
|
3779 |
is_deeply($rows, [[1, 2], [3, 4]]); |
|
3780 |
$rows = $result->fetch_multi(2); |
|
3781 |
is_deeply($rows, [[5, 6]]); |
|
3782 |
$rows = $result->fetch_multi(2); |
|
3783 |
ok(!$rows); |
|
3784 | ||
3785 |
test 'DBIx::Custom::Result fetch_hash_multi'; |
|
3786 |
eval { $dbi->execute("drop table $table1") }; |
|
3787 |
$dbi->execute($create_table1); |
|
3788 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
|
3789 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
3790 |
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1); |
|
3791 |
$result = $dbi->select(table => $table1); |
|
3792 |
$rows = $result->fetch_hash_multi(2); |
|
3793 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
|
3794 |
$rows = $result->fetch_hash_multi(2); |
|
3795 |
is_deeply($rows, [{$key1 => 5, $key2 => 6}]); |
|
3796 |
$rows = $result->fetch_hash_multi(2); |
|
3797 |
ok(!$rows); |
|
3798 | ||
test cleanup
|
3799 |
test "query_builder"; |
3800 |
$datas = [ |
|
cleanup
|
3801 |
# Basic tests |
3802 |
{ name => 'placeholder basic', |
|
3803 |
source => "a {? k1} b {= k2} {<> k3} {> k4} {< k5} {>= k6} {<= k7} {like k8}", , |
|
3804 |
sql_expected => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?", |
|
3805 |
columns_expected => [qw/k1 k2 k3 k4 k5 k6 k7 k8/] |
|
3806 |
}, |
|
3807 |
{ |
|
3808 |
name => 'placeholder in', |
|
3809 |
source => "{in k1 3}", |
|
3810 |
sql_expected => "k1 in (?, ?, ?)", |
|
3811 |
columns_expected => [qw/k1 k1 k1/] |
|
3812 |
}, |
|
3813 |
|
|
3814 |
# Table name |
|
3815 |
{ |
|
3816 |
name => 'placeholder with table name', |
|
3817 |
source => "{= a.k1} {= a.k2}", |
|
3818 |
sql_expected => "a.k1 = ? a.k2 = ?", |
|
3819 |
columns_expected => [qw/a.k1 a.k2/] |
|
3820 |
}, |
|
3821 |
{ |
|
3822 |
name => 'placeholder in with table name', |
|
3823 |
source => "{in a.k1 2} {in b.k2 2}", |
|
3824 |
sql_expected => "a.k1 in (?, ?) b.k2 in (?, ?)", |
|
3825 |
columns_expected => [qw/a.k1 a.k1 b.k2 b.k2/] |
|
3826 |
}, |
|
3827 |
{ |
|
3828 |
name => 'not contain tag', |
|
3829 |
source => "aaa", |
|
3830 |
sql_expected => "aaa", |
|
3831 |
columns_expected => [], |
|
3832 |
} |
|
test cleanup
|
3833 |
]; |
3834 | ||
3835 |
for (my $i = 0; $i < @$datas; $i++) { |
|
cleanup
|
3836 |
my $data = $datas->[$i]; |
3837 |
my $dbi = DBIx::Custom->new; |
|
3838 |
my $builder = $dbi->query_builder; |
|
3839 |
my $query = $builder->build_query($data->{source}); |
|
3840 |
is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql"); |
|
3841 |
is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns"); |
|
test cleanup
|
3842 |
} |
3843 | ||
cleanup
|
3844 |
$dbi = DBIx::Custom->new; |
3845 |
$builder = $dbi->query_builder; |
|
3846 |
$dbi->register_tag( |
|
cleanup
|
3847 |
p => sub { |
3848 |
my @args = @_; |
|
3849 |
|
|
3850 |
my $expand = "? $args[0] $args[1]"; |
|
3851 |
my $columns = [2]; |
|
3852 |
return [$expand, $columns]; |
|
3853 |
} |
|
test cleanup
|
3854 |
); |
3855 | ||
3856 |
$query = $builder->build_query("{p a b}"); |
|
cleanup test
|
3857 |
is($query->{sql}, "? a b", "register_tag sql"); |
test cleanup
|
3858 |
is_deeply($query->{columns}, [2], "register_tag columns"); |
3859 | ||
3860 |
eval{$builder->build_query('{? }')}; |
|
3861 |
like($@, qr/\QColumn name must be specified in tag "{? }"/, "? not arguments"); |
|
3862 | ||
3863 |
eval{$builder->build_query("{a }")}; |
|
3864 |
like($@, qr/\QTag "a" is not registered/, "tag not exist"); |
|
3865 | ||
cleanup
|
3866 |
$dbi->register_tag({ |
cleanup
|
3867 |
q => 'string' |
test cleanup
|
3868 |
}); |
3869 | ||
3870 |
eval{$builder->build_query("{q}", {})}; |
|
3871 |
like($@, qr/Tag "q" must be sub reference/, "tag not code ref"); |
|
3872 | ||
cleanup
|
3873 |
$dbi->register_tag({ |
cleanup
|
3874 |
r => sub {} |
test cleanup
|
3875 |
}); |
3876 | ||
3877 |
eval{$builder->build_query("{r}")}; |
|
3878 |
like($@, qr/\QTag "r" must return [STRING, ARRAY_REFERENCE]/, "tag return noting"); |
|
3879 | ||
cleanup
|
3880 |
$dbi->register_tag({ |
cleanup
|
3881 |
s => sub { return ["a", ""]} |
test cleanup
|
3882 |
}); |
3883 | ||
3884 |
eval{$builder->build_query("{s}")}; |
|
3885 |
like($@, qr/\QTag "s" must return [STRING, ARRAY_REFERENCE]/, "tag return not array columns"); |
|
3886 | ||
cleanup
|
3887 |
$dbi->register_tag( |
cleanup
|
3888 |
t => sub {return ["a", []]} |
test cleanup
|
3889 |
); |
3890 | ||
3891 | ||
cleanup test
|
3892 |
test 'Default tag Error case'; |
3893 |
eval{$builder->build_query("{= }")}; |
|
fixed bug that when id optio...
|
3894 |
like($@, qr/\QColumn name must be specified in tag "{= }"/, "basic '=' : key not exist"); |
cleanup test
|
3895 | |
3896 |
eval{$builder->build_query("{in }")}; |
|
fixed bug that when id optio...
|
3897 |
like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/, "in : key not exist"); |
cleanup test
|
3898 | |
3899 |
eval{$builder->build_query("{in a}")}; |
|
3900 |
like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/, |
|
cleanup
|
3901 |
"in : key not exist"); |
cleanup test
|
3902 | |
3903 |
eval{$builder->build_query("{in a r}")}; |
|
3904 |
like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/, |
|
cleanup
|
3905 |
"in : key not exist"); |
cleanup test
|
3906 | |
3907 |
test 'variouse source'; |
|
3908 |
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d"; |
|
3909 |
$query = $builder->build_query($source); |
|
3910 |
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1"); |
|
3911 | ||
3912 |
$source = "abc"; |
|
3913 |
$query = $builder->build_query($source); |
|
micro optimization
|
3914 |
is($query->{sql}, 'abc', "basic : 2"); |
cleanup test
|
3915 | |
3916 |
$source = "{= a}"; |
|
3917 |
$query = $builder->build_query($source); |
|
micro optimization
|
3918 |
is($query->{sql}, 'a = ?', "only tag"); |
cleanup test
|
3919 | |
3920 |
$source = "000"; |
|
3921 |
$query = $builder->build_query($source); |
|
micro optimization
|
3922 |
is($query->{sql}, '000', "contain 0 value"); |
cleanup test
|
3923 | |
3924 |
$source = "a {= b} }"; |
|
3925 |
eval{$builder->build_query($source)}; |
|
3926 |
like($@, qr/unexpected "}"/, "error : 1"); |
|
3927 | ||
3928 |
$source = "a {= {}"; |
|
3929 |
eval{$builder->build_query($source)}; |
|
fixed bug that when id optio...
|
3930 |
like($@, qr/\Qunexpected "{"/, "error : 2"); |
cleanup test
|
3931 | |
3932 |
test 'select() sqlfilter option'; |
|
3933 |
$dbi = DBIx::Custom->connect; |
|
cleanup test
|
3934 |
$dbi->user_table_info($user_table_info); |
cleanup test
|
3935 |
eval { $dbi->execute("drop table $table1") }; |
3936 |
$dbi->execute($create_table1); |
|
test cleanup
|
3937 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
3938 |
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1); |
cleanup test
|
3939 |
$rows = $dbi->select( |
cleanup
|
3940 |
table => $table1, |
3941 |
column => $key1, |
|
3942 |
sqlfilter => sub { |
|
3943 |
my $sql = shift; |
|
3944 |
$sql = "select * from ( $sql ) t where $key1 = 1"; |
|
3945 |
return $sql; |
|
3946 |
} |
|
cleanup test
|
3947 |
)->all; |
3948 |
is_deeply($rows, [{$key1 => 1}]); |
|
3949 | ||
sqlfilter option is renamed ...
|
3950 |
test 'select() after_build_sql option'; |
3951 |
$dbi = DBIx::Custom->connect; |
|
3952 |
$dbi->user_table_info($user_table_info); |
|
3953 |
eval { $dbi->execute("drop table $table1") }; |
|
3954 |
$dbi->execute($create_table1); |
|
test cleanup
|
3955 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
3956 |
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1); |
sqlfilter option is renamed ...
|
3957 |
$rows = $dbi->select( |
cleanup
|
3958 |
table => $table1, |
3959 |
column => $key1, |
|
3960 |
after_build_sql => sub { |
|
3961 |
my $sql = shift; |
|
3962 |
$sql = "select * from ( $sql ) t where $key1 = 1"; |
|
3963 |
return $sql; |
|
3964 |
} |
|
sqlfilter option is renamed ...
|
3965 |
)->all; |
3966 |
is_deeply($rows, [{$key1 => 1}]); |
|
3967 | ||
cleanup test
|
3968 |
test 'dbi method from model'; |
3969 |
$dbi = MyDBI9->connect; |
|
3970 |
eval { $dbi->execute("drop table $table1") }; |
|
3971 |
$dbi->execute($create_table1); |
|
fixed setup method logic
|
3972 |
$dbi->setup_model; |
cleanup test
|
3973 |
$model = $dbi->model($table1); |
3974 |
eval{$model->execute("select * from $table1")}; |
|
3975 |
ok(!$@); |
|
3976 | ||
3977 |
test 'column table option'; |
|
3978 |
$dbi = MyDBI9->connect; |
|
cleanup test
|
3979 |
$dbi->user_table_info($user_table_info); |
cleanup test
|
3980 |
eval { $dbi->execute("drop table $table1") }; |
3981 |
$dbi->execute($create_table1); |
|
3982 |
eval { $dbi->execute("drop table $table2") }; |
|
3983 |
$dbi->execute($create_table2); |
|
fixed setup method logic
|
3984 |
$dbi->setup_model; |
cleanup test
|
3985 |
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)"); |
3986 |
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)"); |
|
3987 |
$model = $dbi->model($table1); |
|
3988 |
$result = $model->select( |
|
cleanup
|
3989 |
column => [ |
improved test
|
3990 |
$model->column($table2, {alias => u$table2_alias}) |
cleanup
|
3991 |
], |
improved test
|
3992 |
where => {u($table2_alias) . ".$key3" => 4} |
cleanup test
|
3993 |
); |
3994 |
is_deeply($result->one, |
|
improved test
|
3995 |
{u($table2_alias) . ".$key1" => 1, u($table2_alias) . ".$key3" => 4}); |
cleanup test
|
3996 | |
3997 |
$dbi->separator('__'); |
|
3998 |
$result = $model->select( |
|
cleanup
|
3999 |
column => [ |
improved test
|
4000 |
$model->column($table2, {alias => u$table2_alias}) |
cleanup
|
4001 |
], |
improved test
|
4002 |
where => {u($table2_alias) . ".$key3" => 4} |
cleanup test
|
4003 |
); |
4004 |
is_deeply($result->one, |
|
improved test
|
4005 |
{u(${table2_alias}) . "__$key1" => 1, u(${table2_alias}) . "__$key3" => 4}); |
cleanup test
|
4006 | |
4007 |
$dbi->separator('-'); |
|
4008 |
$result = $model->select( |
|
cleanup
|
4009 |
column => [ |
improved test
|
4010 |
$model->column($table2, {alias => u$table2_alias}) |
cleanup
|
4011 |
], |
improved test
|
4012 |
where => {u($table2_alias) . ".$key3" => 4} |
cleanup test
|
4013 |
); |
4014 |
is_deeply($result->one, |
|
improved test
|
4015 |
{u(${table2_alias}) . "-$key1" => 1, u(${table2_alias}) . "-$key3" => 4}); |
cleanup test
|
4016 | |
4017 |
test 'create_model'; |
|
4018 |
$dbi = DBIx::Custom->connect; |
|
cleanup test
|
4019 |
$dbi->user_table_info($user_table_info); |
cleanup test
|
4020 |
eval { $dbi->execute("drop table $table1") }; |
4021 |
eval { $dbi->execute("drop table $table2") }; |
|
4022 |
$dbi->execute($create_table1); |
|
4023 |
$dbi->execute($create_table2); |
|
4024 | ||
4025 |
$dbi->create_model( |
|
cleanup
|
4026 |
table => $table1, |
4027 |
join => [ |
|
4028 |
"left outer join $table2 on $table1.$key1 = $table2.$key1" |
|
4029 |
], |
|
4030 |
primary_key => [$key1] |
|
cleanup test
|
4031 |
); |
4032 |
$model2 = $dbi->create_model( |
|
cleanup
|
4033 |
table => $table2 |
cleanup test
|
4034 |
); |
4035 |
$dbi->create_model( |
|
cleanup
|
4036 |
table => $table3, |
4037 |
filter => [ |
|
4038 |
$key1 => {in => sub { uc $_[0] }} |
|
4039 |
] |
|
cleanup test
|
4040 |
); |
fixed setup method logic
|
4041 |
$dbi->setup_model; |
test cleanup
|
4042 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
4043 |
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2); |
cleanup test
|
4044 |
$model = $dbi->model($table1); |
4045 |
$result = $model->select( |
|
cleanup
|
4046 |
column => [$model->mycolumn, $model->column($table2)], |
4047 |
where => {"$table1.$key1" => 1} |
|
cleanup test
|
4048 |
); |
4049 |
is_deeply($result->one, |
|
cleanup
|
4050 |
{$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3}); |
cleanup test
|
4051 |
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3}); |
4052 | ||
4053 |
test 'model method'; |
|
4054 |
$dbi = DBIx::Custom->connect; |
|
4055 |
eval { $dbi->execute("drop table $table2") }; |
|
4056 |
$dbi->execute($create_table2); |
|
cleanup
|
4057 |
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2); |
cleanup test
|
4058 |
$model = $dbi->create_model( |
cleanup
|
4059 |
table => $table2 |
cleanup test
|
4060 |
); |
4061 |
$model->method(foo => sub { shift->select(@_) }); |
|
4062 |
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3}); |
|
- method method of DBIx::Cus...
|
4063 | |
4064 |
test 'model helper'; |
|
4065 |
$dbi = DBIx::Custom->connect; |
|
4066 |
eval { $dbi->execute("drop table $table2") }; |
|
4067 |
$dbi->execute($create_table2); |
|
cleanup
|
4068 |
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2); |
- method method of DBIx::Cus...
|
4069 |
$model = $dbi->create_model( |
cleanup
|
4070 |
table => $table2 |
- method method of DBIx::Cus...
|
4071 |
); |
4072 |
$model->helper(foo => sub { shift->select(@_) }); |
|
4073 |
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3}); |
|
cleanup test
|
4074 | |
- update_param is DEPRECATED...
|
4075 |
test 'assign_clause'; |
cleanup test
|
4076 |
$dbi = DBIx::Custom->connect; |
4077 |
eval { $dbi->execute("drop table $table1") }; |
|
4078 |
$dbi->execute($create_table1_2); |
|
test cleanup
|
4079 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
4080 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
cleanup test
|
4081 | |
4082 |
$param = {$key2 => 11}; |
|
- update_param is DEPRECATED...
|
4083 |
$assign_clause = $dbi->assign_clause($param); |
cleanup test
|
4084 |
$sql = <<"EOS"; |
- update_param is DEPRECATED...
|
4085 |
update $table1 set $assign_clause |
cleanup test
|
4086 |
where $key1 = 1 |
4087 |
EOS |
|
cleanup
|
4088 |
$dbi->execute($sql, $param); |
cleanup test
|
4089 |
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1); |
4090 |
$rows = $result->all; |
|
4091 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
|
cleanup
|
4092 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
4093 |
"basic"); |
|
cleanup test
|
4094 | |
4095 | ||
4096 |
$dbi = DBIx::Custom->connect; |
|
4097 |
eval { $dbi->execute("drop table $table1") }; |
|
4098 |
$dbi->execute($create_table1_2); |
|
test cleanup
|
4099 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
4100 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
cleanup test
|
4101 | |
4102 |
$param = {$key2 => 11, $key3 => 33}; |
|
- update_param is DEPRECATED...
|
4103 |
$assign_clause = $dbi->assign_clause($param); |
cleanup test
|
4104 |
$sql = <<"EOS"; |
- update_param is DEPRECATED...
|
4105 |
update $table1 set $assign_clause |
cleanup test
|
4106 |
where $key1 = 1 |
4107 |
EOS |
|
cleanup
|
4108 |
$dbi->execute($sql, $param); |
cleanup test
|
4109 |
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1); |
4110 |
$rows = $result->all; |
|
4111 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5}, |
|
cleanup
|
4112 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
4113 |
"basic"); |
|
cleanup test
|
4114 | |
4115 |
$dbi = DBIx::Custom->connect; |
|
4116 |
eval { $dbi->execute("drop table $table1") }; |
|
4117 |
$dbi->execute($create_table1_2); |
|
test cleanup
|
4118 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
4119 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
cleanup test
|
4120 | |
4121 |
$param = {$key2 => 11, $key3 => 33}; |
|
- update_param is DEPRECATED...
|
4122 |
$assign_clause = $dbi->update_param($param, {no_set => 1}); |
cleanup test
|
4123 |
$sql = <<"EOS"; |
- update_param is DEPRECATED...
|
4124 |
update $table1 set $assign_clause |
cleanup test
|
4125 |
where $key1 = 1 |
4126 |
EOS |
|
cleanup
|
4127 |
$dbi->execute($sql, $param); |
cleanup test
|
4128 |
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1); |
4129 |
$rows = $result->all; |
|
4130 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5}, |
|
cleanup
|
4131 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
4132 |
"update param no_set"); |
|
cleanup test
|
4133 | |
cleanup
|
4134 |
|
cleanup test
|
4135 |
$dbi = DBIx::Custom->connect; |
4136 |
eval { $dbi->execute("drop table $table1") }; |
|
4137 |
$dbi->execute($create_table1_2); |
|
test cleanup
|
4138 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
4139 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
test cleanup
|
4140 | |
cleanup test
|
4141 |
$param = {$key2 => 11}; |
- update_param is DEPRECATED...
|
4142 |
$assign_clause = $dbi->assign_param($param); |
4143 |
$sql = <<"EOS"; |
|
4144 |
update $table1 set $assign_clause |
|
4145 |
where $key1 = 1 |
|
4146 |
EOS |
|
cleanup
|
4147 |
$dbi->execute($sql, $param, table => $table1); |
- update_param is DEPRECATED...
|
4148 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
4149 |
$rows = $result->all; |
|
4150 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
|
cleanup
|
4151 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
4152 |
"basic"); |
|
- update_param is DEPRECATED...
|
4153 | |
4154 |
$param = {$key2 => 11}; |
|
4155 |
$assign_clause = $dbi->assign_clause($param); |
|
cleanup test
|
4156 |
$sql = <<"EOS"; |
- update_param is DEPRECATED...
|
4157 |
update $table1 set $assign_clause |
cleanup test
|
4158 |
where $key1 = 1 |
4159 |
EOS |
|
cleanup
|
4160 |
$dbi->execute($sql, $param, table => $table1); |
cleanup test
|
4161 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
4162 |
$rows = $result->all; |
|
4163 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
|
cleanup
|
4164 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
4165 |
"basic"); |
|
test cleanup
|
4166 | |
cleanup test
|
4167 |
test 'Model class'; |
4168 |
$dbi = MyDBI1->connect; |
|
4169 |
eval { $dbi->execute("drop table $table1") }; |
|
4170 |
$dbi->execute($create_table1); |
|
4171 |
$model = $dbi->model($table1); |
|
4172 |
$model->insert({$key1 => 'a', $key2 => 'b'}); |
|
4173 |
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic'); |
|
4174 |
eval { $dbi->execute("drop table $table2") }; |
|
4175 |
$dbi->execute($create_table2); |
|
4176 |
$model = $dbi->model($table2); |
|
4177 |
$model->insert({$key1 => 'a'}); |
|
4178 |
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic'); |
|
4179 |
is($dbi->models->{$table1}, $dbi->model($table1)); |
|
4180 |
is($dbi->models->{$table2}, $dbi->model($table2)); |
|
4181 | ||
4182 |
$dbi = MyDBI4->connect; |
|
4183 |
eval { $dbi->execute("drop table $table1") }; |
|
4184 |
$dbi->execute($create_table1); |
|
4185 |
$model = $dbi->model($table1); |
|
4186 |
$model->insert({$key1 => 'a', $key2 => 'b'}); |
|
4187 |
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic'); |
|
4188 |
eval { $dbi->execute("drop table $table2") }; |
|
4189 |
$dbi->execute($create_table2); |
|
4190 |
$model = $dbi->model($table2); |
|
4191 |
$model->insert({$key1 => 'a'}); |
|
4192 |
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic'); |
|
4193 | ||
4194 |
$dbi = MyDBI5->connect; |
|
4195 |
eval { $dbi->execute("drop table $table1") }; |
|
4196 |
eval { $dbi->execute("drop table $table2") }; |
|
4197 |
$dbi->execute($create_table1); |
|
4198 |
$dbi->execute($create_table2); |
|
4199 |
$model = $dbi->model($table2); |
|
4200 |
$model->insert({$key1 => 'a'}); |
|
4201 |
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model'); |
|
cleanup
|
4202 |
$dbi->insert({$key1 => 1}, table => $table1); |
cleanup test
|
4203 |
$model = $dbi->model($table1); |
4204 |
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model'); |
|
4205 | ||
4206 |
test 'primary_key'; |
|
4207 |
$dbi = MyDBI1->connect; |
|
4208 |
$model = $dbi->model($table1); |
|
4209 |
$model->primary_key([$key1, $key2]); |
|
4210 |
is_deeply($model->primary_key, [$key1, $key2]); |
|
4211 | ||
4212 |
test 'columns'; |
|
4213 |
$dbi = MyDBI1->connect; |
|
4214 |
$model = $dbi->model($table1); |
|
4215 |
$model->columns([$key1, $key2]); |
|
4216 |
is_deeply($model->columns, [$key1, $key2]); |
|
cleanup test
|
4217 | |
- added DBIX_CUSTOM_SUPPRESS...
|
4218 |
test 'columns'; |
4219 |
$dbi = MyDBI1->connect; |
|
4220 |
$model = $dbi->model($table1); |
|
4221 |
$model->columns([$key1, $key2]); |
|
4222 |
is_deeply($model->columns, [$key1, $key2]); |
|
4223 | ||
cleanup test
|
4224 |
test 'setup_model'; |
4225 |
$dbi = MyDBI1->connect; |
|
cleanup test
|
4226 |
$dbi->user_table_info($user_table_info); |
finishied sqlite test cleanu...
|
4227 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4228 |
eval { $dbi->execute("drop table $table2") }; |
added EXPERIMENTAL execute m...
|
4229 | |
cleanup test
|
4230 |
$dbi->execute($create_table1); |
cleanup test
|
4231 |
$dbi->execute($create_table2); |
fixed setup method logic
|
4232 |
$dbi->setup_model; |
cleanup test
|
4233 |
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]); |
4234 |
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]); |
|
cleanup test
|
4235 | |
cleanup test
|
4236 |
test 'each_column'; |
4237 |
$dbi = DBIx::Custom->connect; |
|
4238 |
eval { $dbi->execute("drop table ${q}table$p") }; |
|
finishied sqlite test cleanu...
|
4239 |
eval { $dbi->execute("drop table $table1") }; |
4240 |
eval { $dbi->execute("drop table $table2") }; |
|
cleanup test
|
4241 |
eval { $dbi->execute("drop table $table3") }; |
4242 |
$dbi->execute($create_table1_type); |
|
cleanup test
|
4243 |
$dbi->execute($create_table2); |
cleanup test
|
4244 | |
4245 |
$infos = []; |
|
4246 |
$dbi->each_column(sub { |
|
cleanup
|
4247 |
my ($self, $table, $column, $cinfo) = @_; |
4248 |
|
|
4249 |
if ($table =~ /^table\d/i) { |
|
4250 |
my $info = [$table, $column, $cinfo->{COLUMN_NAME}]; |
|
4251 |
push @$infos, $info; |
|
4252 |
} |
|
cleanup test
|
4253 |
}); |
4254 |
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos]; |
|
4255 |
is_deeply($infos, |
|
cleanup
|
4256 |
[ |
improved tests
|
4257 |
[table_only($table1), $key1, $key1], |
4258 |
[table_only($table1), $key2, $key2], |
|
4259 |
[table_only($table2), $key1, $key1], |
|
4260 |
[table_only($table2), $key3, $key3] |
|
cleanup
|
4261 |
] |
4262 |
|
|
cleanup test
|
4263 |
); |
cleanup test
|
4264 | |
cleanup test
|
4265 |
test 'each_table'; |
4266 |
$dbi = DBIx::Custom->connect; |
|
4267 |
eval { $dbi->execute("drop table $table1") }; |
|
4268 |
eval { $dbi->execute("drop table $table2") }; |
|
4269 |
$dbi->execute($create_table2); |
|
4270 |
$dbi->execute($create_table1_type); |
|
cleanup test
|
4271 | |
cleanup test
|
4272 |
$infos = []; |
4273 |
$dbi->each_table(sub { |
|
cleanup
|
4274 |
my ($self, $table, $table_info) = @_; |
4275 |
|
|
4276 |
if ($table =~ /^table\d/i) { |
|
4277 |
my $info = [$table, $table_info->{TABLE_NAME}]; |
|
4278 |
push @$infos, $info; |
|
4279 |
} |
|
cleanup test
|
4280 |
}); |
4281 |
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos]; |
|
4282 |
is_deeply($infos, |
|
cleanup
|
4283 |
[ |
improved tests
|
4284 |
[table_only($table1), table_only($table1)], |
4285 |
[table_only($table2), table_only($table2)], |
|
cleanup
|
4286 |
] |
cleanup test
|
4287 |
); |
4288 | ||
cleanup test
|
4289 |
$dbi = DBIx::Custom->connect; |
4290 |
eval { $dbi->execute("drop table $table1") }; |
|
4291 |
eval { $dbi->execute("drop table $table2") }; |
|
4292 |
$dbi->execute($create_table2); |
|
4293 |
$dbi->execute($create_table1_type); |
|
4294 | ||
4295 |
$infos = []; |
|
4296 |
$dbi->user_table_info($user_table_info); |
|
4297 |
$dbi->each_table(sub { |
|
cleanup
|
4298 |
my ($self, $table, $table_info) = @_; |
4299 |
|
|
4300 |
if ($table =~ /^table\d/i) { |
|
4301 |
my $info = [$table, $table_info->{TABLE_NAME}]; |
|
4302 |
push @$infos, $info; |
|
4303 |
} |
|
cleanup test
|
4304 |
}); |
4305 |
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos]; |
|
4306 |
is_deeply($infos, |
|
cleanup
|
4307 |
[ |
improved tests
|
4308 |
[table_only($table1), table_only($table1)], |
4309 |
[table_only($table2), table_only($table2)], |
|
4310 |
[table_only($table3), table_only($table3)], |
|
cleanup
|
4311 |
] |
cleanup test
|
4312 |
); |
4313 | ||
cleanup test
|
4314 |
test 'type_rule into'; |
4315 |
eval { $dbi->execute("drop table $table1") }; |
|
4316 |
$dbi->execute($create_table1_type); |
|
cleanup
|
4317 |
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table); |
4318 | ||
4319 | ||
cleanup test
|
4320 |
$dbi = DBIx::Custom->connect; |
4321 |
eval { $dbi->execute("drop table $table1") }; |
|
4322 |
$dbi->execute($create_table1_type); |
|
4323 | ||
cleanup
|
4324 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4325 |
$dbi->type_rule( |
cleanup
|
4326 |
into1 => { |
4327 |
$date_typename => sub { '2010-' . $_[0] } |
|
4328 |
} |
|
cleanup test
|
4329 |
); |
cleanup test
|
4330 |
$dbi->insert({$key1 => '01-01'}, table => $table1); |
4331 |
$result = $dbi->select(table => $table1); |
|
4332 |
like($result->one->{$key1}, qr/^2010-01-01/); |
|
cleanup test
|
4333 | |
4334 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
4335 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4336 |
$dbi->execute($create_table1_type); |
cleanup
|
4337 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4338 |
$dbi->type_rule( |
cleanup
|
4339 |
into1 => [ |
4340 |
[$date_typename, $datetime_typename] => sub { |
|
4341 |
my $value = shift; |
|
4342 |
$value =~ s/02/03/g; |
|
4343 |
return $value; |
|
4344 |
} |
|
4345 |
] |
|
cleanup test
|
4346 |
); |
4347 |
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1); |
|
4348 |
$result = $dbi->select(table => $table1); |
|
4349 |
$row = $result->one; |
|
4350 |
like($row->{$key1}, qr/^2010-01-03/); |
|
4351 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
cleanup test
|
4352 | |
cleanup test
|
4353 |
$dbi = DBIx::Custom->connect; |
4354 |
eval { $dbi->execute("drop table $table1") }; |
|
4355 |
$dbi->execute($create_table1_type); |
|
4356 |
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1); |
|
cleanup
|
4357 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4358 |
$dbi->type_rule( |
cleanup
|
4359 |
into1 => [ |
4360 |
[$date_typename, $datetime_typename] => sub { |
|
4361 |
my $value = shift; |
|
4362 |
$value =~ s/02/03/g; |
|
4363 |
return $value; |
|
4364 |
} |
|
4365 |
] |
|
cleanup test
|
4366 |
); |
cleanup test
|
4367 |
$result = $dbi->execute( |
cleanup
|
4368 |
"select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2", |
4369 |
{$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'} |
|
cleanup test
|
4370 |
); |
cleanup test
|
4371 |
$row = $result->one; |
4372 |
like($row->{$key1}, qr/^2010-01-03/); |
|
4373 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
4374 | ||
4375 |
$dbi = DBIx::Custom->connect; |
|
4376 |
eval { $dbi->execute("drop table $table1") }; |
|
4377 |
$dbi->execute($create_table1_type); |
|
4378 |
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1); |
|
cleanup
|
4379 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4380 |
$dbi->type_rule( |
cleanup
|
4381 |
into1 => [ |
4382 |
[$date_typename, $datetime_typename] => sub { |
|
4383 |
my $value = shift; |
|
4384 |
$value =~ s/02/03/g; |
|
4385 |
return $value; |
|
4386 |
} |
|
4387 |
] |
|
cleanup test
|
4388 |
); |
cleanup test
|
4389 |
$result = $dbi->execute( |
cleanup
|
4390 |
"select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2", |
4391 |
{$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'}, |
|
4392 |
table => $table1 |
|
cleanup test
|
4393 |
); |
4394 |
$row = $result->one; |
|
4395 |
like($row->{$key1}, qr/^2010-01-03/); |
|
4396 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
|
4397 | ||
4398 |
$dbi = DBIx::Custom->connect; |
|
4399 |
eval { $dbi->execute("drop table $table1") }; |
|
4400 |
$dbi->execute($create_table1_type); |
|
4401 |
$dbi->register_filter(convert => sub { |
|
cleanup
|
4402 |
my $value = shift || ''; |
4403 |
$value =~ s/02/03/; |
|
4404 |
return $value; |
|
cleanup test
|
4405 |
}); |
cleanup
|
4406 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4407 |
$dbi->type_rule( |
cleanup
|
4408 |
from1 => { |
4409 |
$date_datatype => 'convert', |
|
4410 |
}, |
|
4411 |
into1 => { |
|
4412 |
$date_typename => 'convert', |
|
4413 |
} |
|
cleanup test
|
4414 |
); |
4415 |
$dbi->insert({$key1 => '2010-02-02'}, table => $table1); |
|
4416 |
$result = $dbi->select(table => $table1); |
|
4417 |
like($result->fetch->[0], qr/^2010-03-03/); |
|
- fixed bug DBIx::Custom::Re...
|
4418 |
$result = $dbi->select(column => [$key1, $key1], table => $table1); |
4419 |
$row = $result->fetch; |
|
4420 |
like($row->[0], qr/^2010-03-03/); |
|
4421 |
like($row->[1], qr/^2010-03-03/); |
|
cleanup test
|
4422 | |
4423 |
test 'type_rule and filter order'; |
|
4424 |
$dbi = DBIx::Custom->connect; |
|
4425 |
eval { $dbi->execute("drop table $table1") }; |
|
4426 |
$dbi->execute($create_table1_type); |
|
cleanup
|
4427 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4428 |
$dbi->type_rule( |
cleanup
|
4429 |
into1 => { |
4430 |
$date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
|
4431 |
}, |
|
4432 |
into2 => { |
|
4433 |
$date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v } |
|
4434 |
}, |
|
4435 |
from1 => { |
|
4436 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v } |
|
4437 |
}, |
|
4438 |
from2 => { |
|
4439 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v } |
|
4440 |
} |
|
cleanup test
|
4441 |
); |
4442 |
$dbi->insert({$key1 => '2010-01-03'}, |
|
cleanup
|
4443 |
table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }}); |
cleanup test
|
4444 |
$result = $dbi->select(table => $table1); |
4445 |
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v }); |
|
- renamed DBIx::Custom::Resu...
|
4446 |
like($result->fetch_one->[0], qr/^2010-01-09/); |
cleanup test
|
4447 | |
4448 | ||
4449 |
$dbi = DBIx::Custom->connect; |
|
4450 |
eval { $dbi->execute("drop table $table1") }; |
|
4451 |
$dbi->execute($create_table1_type); |
|
cleanup
|
4452 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4453 |
$dbi->type_rule( |
cleanup
|
4454 |
from1 => { |
4455 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4456 |
}, |
|
4457 |
from2 => { |
|
4458 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
|
4459 |
}, |
|
cleanup test
|
4460 |
); |
4461 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
4462 |
$result = $dbi->select(table => $table1); |
|
cleanup
|
4463 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4464 |
$result->type_rule( |
cleanup
|
4465 |
from1 => { |
4466 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v } |
|
4467 |
}, |
|
4468 |
from2 => { |
|
4469 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v } |
|
4470 |
} |
|
cleanup test
|
4471 |
); |
cleanup test
|
4472 |
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v }); |
- renamed DBIx::Custom::Resu...
|
4473 |
like($result->fetch_one->[0], qr/^2010-01-09/); |
cleanup test
|
4474 | |
cleanup test
|
4475 |
test 'type_rule_off'; |
cleanup test
|
4476 |
$dbi = DBIx::Custom->connect; |
cleanup test
|
4477 |
eval { $dbi->execute("drop table $table1") }; |
4478 |
$dbi->execute($create_table1_type); |
|
cleanup
|
4479 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4480 |
$dbi->type_rule( |
cleanup
|
4481 |
from1 => { |
4482 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4483 |
}, |
|
4484 |
into1 => { |
|
4485 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4486 |
} |
|
cleanup test
|
4487 |
); |
cleanup test
|
4488 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1); |
4489 |
$result = $dbi->select(table => $table1, type_rule_off => 1); |
|
4490 |
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/); |
|
cleanup test
|
4491 | |
cleanup test
|
4492 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
4493 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4494 |
$dbi->execute($create_table1_type); |
cleanup
|
4495 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4496 |
$dbi->type_rule( |
cleanup
|
4497 |
from1 => { |
4498 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4499 |
}, |
|
4500 |
into1 => { |
|
4501 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4502 |
} |
|
cleanup test
|
4503 |
); |
4504 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1); |
|
4505 |
$result = $dbi->select(table => $table1, type_rule_off => 1); |
|
4506 |
like($result->one->{$key1}, qr/^2010-01-04/); |
|
cleanup test
|
4507 | |
4508 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
4509 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4510 |
$dbi->execute($create_table1_type); |
cleanup
|
4511 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4512 |
$dbi->type_rule( |
cleanup
|
4513 |
from1 => { |
4514 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
|
4515 |
}, |
|
4516 |
into1 => { |
|
4517 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4518 |
} |
|
cleanup test
|
4519 |
); |
4520 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
4521 |
$result = $dbi->select(table => $table1); |
|
4522 |
like($result->one->{$key1}, qr/^2010-01-05/); |
|
cleanup test
|
4523 | |
4524 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
4525 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4526 |
$dbi->execute($create_table1_type); |
cleanup
|
4527 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4528 |
$dbi->type_rule( |
cleanup
|
4529 |
from1 => { |
4530 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
|
4531 |
}, |
|
4532 |
into1 => { |
|
4533 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4534 |
} |
|
cleanup test
|
4535 |
); |
4536 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
4537 |
$result = $dbi->select(table => $table1); |
|
4538 |
like($result->fetch->[0], qr/2010-01-05/); |
|
cleanup test
|
4539 | |
4540 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
4541 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4542 |
$dbi->execute($create_table1_type); |
4543 |
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }); |
|
cleanup
|
4544 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4545 |
$dbi->type_rule( |
cleanup
|
4546 |
into1 => { |
4547 |
$date_typename => 'ppp' |
|
4548 |
} |
|
cleanup test
|
4549 |
); |
4550 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
4551 |
$result = $dbi->select(table => $table1); |
|
4552 |
like($result->one->{$key1}, qr/^2010-01-04/); |
|
cleanup test
|
4553 | |
cleanup test
|
4554 |
eval{$dbi->type_rule( |
cleanup
|
4555 |
into1 => { |
4556 |
$date_typename => 'pp' |
|
4557 |
} |
|
cleanup test
|
4558 |
)}; |
4559 |
like($@, qr/not registered/); |
|
cleanup test
|
4560 | |
cleanup test
|
4561 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
4562 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4563 |
$dbi->execute($create_table1_type); |
cleanup test
|
4564 |
eval { |
cleanup
|
4565 |
$dbi->type_rule( |
4566 |
from1 => { |
|
4567 |
Date => sub { $_[0] * 2 }, |
|
4568 |
} |
|
4569 |
); |
|
cleanup test
|
4570 |
}; |
cleanup test
|
4571 |
like($@, qr/lower/); |
cleanup test
|
4572 | |
cleanup test
|
4573 |
eval { |
cleanup
|
4574 |
$dbi->type_rule( |
4575 |
into1 => { |
|
4576 |
Date => sub { $_[0] * 2 }, |
|
4577 |
} |
|
4578 |
); |
|
cleanup test
|
4579 |
}; |
4580 |
like($@, qr/lower/); |
|
cleanup test
|
4581 | |
4582 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
4583 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4584 |
$dbi->execute($create_table1_type); |
cleanup
|
4585 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4586 |
$dbi->type_rule( |
cleanup
|
4587 |
from1 => { |
4588 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
|
4589 |
}, |
|
4590 |
into1 => { |
|
4591 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4592 |
} |
|
cleanup test
|
4593 |
); |
4594 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
4595 |
$result = $dbi->select(table => $table1); |
|
4596 |
$result->type_rule_off; |
|
4597 |
like($result->one->{$key1}, qr/^2010-01-04/); |
|
cleanup test
|
4598 | |
4599 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
4600 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4601 |
$dbi->execute($create_table1_type); |
cleanup
|
4602 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4603 |
$dbi->type_rule( |
cleanup
|
4604 |
from1 => { |
4605 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }, |
|
4606 |
$datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4607 |
}, |
|
cleanup test
|
4608 |
); |
cleanup test
|
4609 |
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1); |
4610 |
$result = $dbi->select(table => $table1); |
|
4611 |
$result->type_rule( |
|
cleanup
|
4612 |
from1 => { |
4613 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4614 |
} |
|
cleanup test
|
4615 |
); |
cleanup test
|
4616 |
$row = $result->one; |
4617 |
like($row->{$key1}, qr/^2010-01-05/); |
|
4618 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
4619 | ||
4620 |
$result = $dbi->select(table => $table1); |
|
4621 |
$result->type_rule( |
|
cleanup
|
4622 |
from1 => { |
4623 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4624 |
} |
|
cleanup test
|
4625 |
); |
cleanup test
|
4626 |
$row = $result->one; |
4627 |
like($row->{$key1}, qr/2010-01-05/); |
|
4628 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
|
4629 | ||
4630 |
$result = $dbi->select(table => $table1); |
|
4631 |
$result->type_rule( |
|
cleanup
|
4632 |
from1 => { |
4633 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4634 |
} |
|
cleanup test
|
4635 |
); |
4636 |
$row = $result->one; |
|
4637 |
like($row->{$key1}, qr/2010-01-05/); |
|
4638 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
|
4639 | ||
4640 |
$result = $dbi->select(table => $table1); |
|
4641 |
$result->type_rule( |
|
cleanup
|
4642 |
from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }] |
cleanup test
|
4643 |
); |
4644 |
$row = $result->one; |
|
4645 |
like($row->{$key1}, qr/2010-01-05/); |
|
4646 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
|
4647 | ||
4648 |
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }); |
|
4649 |
$result = $dbi->select(table => $table1); |
|
4650 |
$result->type_rule( |
|
cleanup
|
4651 |
from1 => [$date_datatype => 'five'] |
cleanup test
|
4652 |
); |
4653 |
$row = $result->one; |
|
4654 |
like($row->{$key1}, qr/^2010-01-05/); |
|
4655 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
4656 | ||
4657 |
$result = $dbi->select(table => $table1); |
|
4658 |
$result->type_rule( |
|
cleanup
|
4659 |
from1 => [$date_datatype => undef] |
cleanup test
|
4660 |
); |
4661 |
$row = $result->one; |
|
4662 |
like($row->{$key1}, qr/^2010-01-03/); |
|
4663 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
cleanup test
|
4664 | |
4665 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
4666 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4667 |
$dbi->execute($create_table1_type); |
cleanup
|
4668 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4669 |
$dbi->type_rule( |
cleanup
|
4670 |
from1 => { |
4671 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }, |
|
4672 |
}, |
|
cleanup test
|
4673 |
); |
cleanup test
|
4674 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
4675 |
$result = $dbi->select(table => $table1); |
|
4676 |
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }); |
|
4677 |
like($result->one->{$key1}, qr/^2010-01-05/); |
|
cleanup test
|
4678 | |
cleanup test
|
4679 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
4680 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4681 |
$dbi->execute($create_table1_type); |
cleanup
|
4682 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4683 |
$dbi->type_rule( |
cleanup
|
4684 |
from1 => { |
4685 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4686 |
}, |
|
cleanup test
|
4687 |
); |
4688 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
4689 |
$result = $dbi->select(table => $table1); |
|
4690 |
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }); |
|
4691 |
like($result->fetch->[0], qr/^2010-01-05/); |
|
test cleanup
|
4692 | |
cleanup test
|
4693 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
4694 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4695 |
$dbi->execute($create_table1_type); |
cleanup
|
4696 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4697 |
$dbi->type_rule( |
cleanup
|
4698 |
into1 => { |
4699 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4700 |
}, |
|
4701 |
into2 => { |
|
4702 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4703 |
}, |
|
4704 |
from1 => { |
|
4705 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v } |
|
4706 |
}, |
|
4707 |
from2 => { |
|
4708 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v } |
|
4709 |
} |
|
cleanup test
|
4710 |
); |
4711 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1); |
|
4712 |
$result = $dbi->select(table => $table1); |
|
- renamed DBIx::Custom::Resu...
|
4713 |
like($result->type_rule_off->fetch_one->[0], qr/^2010-01-03/); |
cleanup test
|
4714 |
$result = $dbi->select(table => $table1); |
- renamed DBIx::Custom::Resu...
|
4715 |
like($result->type_rule_on->fetch_one->[0], qr/^2010-01-07/); |
test cleanup
|
4716 | |
cleanup test
|
4717 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
4718 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4719 |
$dbi->execute($create_table1_type); |
cleanup
|
4720 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4721 |
$dbi->type_rule( |
cleanup
|
4722 |
into1 => { |
4723 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4724 |
}, |
|
4725 |
into2 => { |
|
4726 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4727 |
}, |
|
4728 |
from1 => { |
|
4729 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v } |
|
4730 |
}, |
|
4731 |
from2 => { |
|
4732 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v } |
|
4733 |
} |
|
cleanup test
|
4734 |
); |
4735 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1); |
|
4736 |
$result = $dbi->select(table => $table1); |
|
- renamed DBIx::Custom::Resu...
|
4737 |
like($result->type_rule1_off->fetch_one->[0], qr/^2010-01-05/); |
cleanup test
|
4738 |
$result = $dbi->select(table => $table1); |
- renamed DBIx::Custom::Resu...
|
4739 |
like($result->type_rule1_on->fetch_one->[0], qr/^2010-01-07/); |
test cleanup
|
4740 | |
cleanup test
|
4741 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
4742 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4743 |
$dbi->execute($create_table1_type); |
cleanup
|
4744 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4745 |
$dbi->type_rule( |
cleanup
|
4746 |
into1 => { |
4747 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4748 |
}, |
|
4749 |
into2 => { |
|
4750 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4751 |
}, |
|
4752 |
from1 => { |
|
4753 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v } |
|
4754 |
}, |
|
4755 |
from2 => { |
|
4756 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v } |
|
4757 |
} |
|
cleanup test
|
4758 |
); |
4759 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1); |
|
4760 |
$result = $dbi->select(table => $table1); |
|
- renamed DBIx::Custom::Resu...
|
4761 |
like($result->type_rule2_off->fetch_one->[0], qr/^2010-01-06/); |
cleanup test
|
4762 |
$result = $dbi->select(table => $table1); |
- renamed DBIx::Custom::Resu...
|
4763 |
like($result->type_rule2_on->fetch_one->[0], qr/^2010-01-07/); |
test cleanup
|
4764 | |
added memory leak check test
|
4765 |
test 'join'; |
4766 |
$dbi = DBIx::Custom->connect; |
|
4767 |
eval { $dbi->execute("drop table $table1") }; |
|
4768 |
$dbi->execute($create_table1); |
|
test cleanup
|
4769 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
4770 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
added memory leak check test
|
4771 |
eval { $dbi->execute("drop table $table2") }; |
4772 |
$dbi->execute($create_table2); |
|
cleanup
|
4773 |
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2); |
added memory leak check test
|
4774 |
eval { $dbi->execute("drop table $table3") }; |
4775 |
$dbi->execute("create table $table3 ($key3 int, $key4 int)"); |
|
cleanup
|
4776 |
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3); |
added memory leak check test
|
4777 |
$rows = $dbi->select( |
cleanup
|
4778 |
table => $table1, |
improved tests
|
4779 |
column => "$table1.$key1 as " . u("${table1}_$key1") . ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3", |
cleanup
|
4780 |
where => {"$table1.$key2" => 2}, |
4781 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1"] |
|
added memory leak check test
|
4782 |
)->all; |
improved tests
|
4783 |
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]); |
added test
|
4784 | |
4785 |
$dbi = DBIx::Custom->connect; |
|
4786 |
eval { $dbi->execute("drop table $table1") }; |
|
4787 |
$dbi->execute($create_table1); |
|
test cleanup
|
4788 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
4789 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
added test
|
4790 |
eval { $dbi->execute("drop table $table2") }; |
4791 |
$dbi->execute($create_table2); |
|
cleanup
|
4792 |
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2); |
added test
|
4793 |
eval { $dbi->execute("drop table $table3") }; |
4794 |
$dbi->execute("create table $table3 ($key3 int, $key4 int)"); |
|
cleanup
|
4795 |
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3); |
added test
|
4796 |
$rows = $dbi->select( |
cleanup
|
4797 |
table => $table1, |
improved tests
|
4798 |
column => "$table1.$key1 as " . u("${table1}_$key1") . ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3", |
cleanup
|
4799 |
where => {"$table1.$key2" => 2}, |
4800 |
join => { |
|
4801 |
clause => "left outer join $table2 on $table1.$key1 = $table2.$key1", |
|
4802 |
table => [$table1, $table2] |
|
4803 |
} |
|
added test
|
4804 |
)->all; |
improved tests
|
4805 |
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]); |
added memory leak check test
|
4806 | |
4807 |
$rows = $dbi->select( |
|
cleanup
|
4808 |
table => $table1, |
4809 |
where => {$key1 => 1}, |
|
4810 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1"] |
|
added memory leak check test
|
4811 |
)->all; |
4812 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
|
4813 | ||
4814 |
$rows = $dbi->select( |
|
cleanup
|
4815 |
table => $table1, |
4816 |
where => {$key1 => 1}, |
|
4817 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1", |
|
4818 |
"left outer join $table3 on $table2.$key3 = $table3.$key3"] |
|
added memory leak check test
|
4819 |
)->all; |
4820 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
|
4821 | ||
4822 |
$rows = $dbi->select( |
|
improved tests
|
4823 |
column => "$table3.$key4 as " . u2("${table3}__$key4"), |
cleanup
|
4824 |
table => $table1, |
4825 |
where => {"$table1.$key1" => 1}, |
|
4826 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1", |
|
4827 |
"left outer join $table3 on $table2.$key3 = $table3.$key3"] |
|
added memory leak check test
|
4828 |
)->all; |
improved tests
|
4829 |
is_deeply($rows, [{u2"${table3}__$key4" => 4}]); |
added memory leak check test
|
4830 | |
4831 |
$rows = $dbi->select( |
|
improved tests
|
4832 |
column => "$table1.$key1 as " . u2("${table1}__$key1"), |
cleanup
|
4833 |
table => $table1, |
4834 |
where => {"$table3.$key4" => 4}, |
|
4835 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1", |
|
4836 |
"left outer join $table3 on $table2.$key3 = $table3.$key3"] |
|
added memory leak check test
|
4837 |
)->all; |
improved tests
|
4838 |
is_deeply($rows, [{u2"${table1}__$key1" => 1}]); |
added memory leak check test
|
4839 | |
4840 |
$dbi = DBIx::Custom->connect; |
|
4841 |
eval { $dbi->execute("drop table $table1") }; |
|
4842 |
$dbi->execute($create_table1); |
|
test cleanup
|
4843 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
added memory leak check test
|
4844 |
eval { $dbi->execute("drop table $table2") }; |
4845 |
$dbi->execute($create_table2); |
|
cleanup
|
4846 |
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2); |
added memory leak check test
|
4847 |
$rows = $dbi->select( |
cleanup
|
4848 |
table => $table1, |
fixed tests for fullqualifie...
|
4849 |
column => $dbi->_tq($table1) . ".${q}$key1$p as ${q}" . u("${table1}_$key1") . "$p, " . $dbi->_tq($table2) . ".${q}$key1$p as ${q}" . u("${table2}_$key1") . "$p, ${q}$key2$p, ${q}$key3$p", |
cleanup
|
4850 |
where => {"$table1.$key2" => 2}, |
fixed tests for fullqualifie...
|
4851 |
join => ["left outer join " . $dbi->_tq($table2) . " on " . $dbi->_tq($table1) . ".${q}$key1$p = " . $dbi->_tq($table2) . ".${q}$key1$p"], |
added memory leak check test
|
4852 |
)->all; |
fixed tests for fullqualifie...
|
4853 |
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], |
cleanup
|
4854 |
'quote'); |
added memory leak check test
|
4855 | |
4856 | ||
4857 |
$dbi = DBIx::Custom->connect; |
|
4858 |
eval { $dbi->execute("drop table $table1") }; |
|
4859 |
$dbi->execute($create_table1); |
|
test cleanup
|
4860 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
added memory leak check test
|
4861 |
$sql = <<"EOS"; |
4862 |
left outer join ( |
|
cleanup
|
4863 |
select * from $table1 t1 |
added t/common-mysql-qualifi...
|
4864 |
where t1.$key2 = ( |
4865 |
select max(t2.$key2) from $table1 t2 |
|
4866 |
where t1.$key1 = t2.$key1 |
|
4867 |
) |
|
added memory leak check test
|
4868 |
) $table3 on $table1.$key1 = $table3.$key1 |
4869 |
EOS |
|
added t/common-mysql-qualifi...
|
4870 |
$sql =~ s/\Q.table3/_table3/g; |
added memory leak check test
|
4871 |
$join = [$sql]; |
4872 |
$rows = $dbi->select( |
|
cleanup
|
4873 |
table => $table1, |
fixed tests for fullqualifie...
|
4874 |
column => u($table3) . ".$key1 as " . u2("${table3}__$key1"), |
cleanup
|
4875 |
join => $join |
added memory leak check test
|
4876 |
)->all; |
fixed tests for fullqualifie...
|
4877 |
is_deeply($rows, [{u2"${table3}__$key1" => 1}]); |
added memory leak check test
|
4878 | |
4879 |
$dbi = DBIx::Custom->connect; |
|
4880 |
eval { $dbi->execute("drop table $table1") }; |
|
4881 |
eval { $dbi->execute("drop table $table2") }; |
|
4882 |
$dbi->execute($create_table1); |
|
4883 |
$dbi->execute($create_table2); |
|
test cleanup
|
4884 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
4885 |
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2); |
4886 |
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2); |
|
added memory leak check test
|
4887 |
$result = $dbi->select( |
cleanup
|
4888 |
table => $table1, |
4889 |
join => [ |
|
4890 |
"left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1" |
|
4891 |
] |
|
added memory leak check test
|
4892 |
); |
4893 |
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]); |
|
4894 |
$result = $dbi->select( |
|
cleanup
|
4895 |
table => $table1, |
4896 |
column => [{$table2 => [$key3]}], |
|
4897 |
join => [ |
|
4898 |
"left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1" |
|
4899 |
] |
|
added memory leak check test
|
4900 |
); |
4901 |
is_deeply($result->all, [{"$table2.$key3" => 4}]); |
|
4902 |
$result = $dbi->select( |
|
cleanup
|
4903 |
table => $table1, |
4904 |
column => [{$table2 => [$key3]}], |
|
4905 |
join => [ |
|
4906 |
"left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'" |
|
4907 |
] |
|
added memory leak check test
|
4908 |
); |
4909 |
is_deeply($result->all, [{"$table2.$key3" => 4}]); |
|
4910 | ||
4911 |
$dbi = DBIx::Custom->connect; |
|
4912 |
eval { $dbi->execute("drop table $table1") }; |
|
4913 |
eval { $dbi->execute("drop table $table2") }; |
|
4914 |
$dbi->execute($create_table1); |
|
4915 |
$dbi->execute($create_table2); |
|
test cleanup
|
4916 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
4917 |
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2); |
4918 |
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2); |
|
added memory leak check test
|
4919 |
$result = $dbi->select( |
cleanup
|
4920 |
table => $table1, |
4921 |
column => [{$table2 => [$key3]}], |
|
4922 |
join => [ |
|
4923 |
{ |
|
4924 |
clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1", |
|
4925 |
table => [$table1, $table2] |
|
4926 |
} |
|
4927 |
] |
|
added memory leak check test
|
4928 |
); |
4929 |
is_deeply($result->all, [{"$table2.$key3" => 4}]); |
|
4930 | ||
improved join clause parsing
|
4931 |
$dbi = DBIx::Custom->connect; |
4932 |
eval { $dbi->execute("drop table $table1") }; |
|
4933 |
eval { $dbi->execute("drop table $table2") }; |
|
4934 |
$dbi->execute($create_table1); |
|
4935 |
$dbi->execute($create_table2); |
|
test cleanup
|
4936 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
4937 |
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2); |
4938 |
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2); |
|
improved join clause parsing
|
4939 |
$result = $dbi->select( |
cleanup
|
4940 |
table => $table1, |
4941 |
column => [{$table2 => [$key3]}], |
|
4942 |
join => [ |
|
4943 |
"left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'" |
|
4944 |
] |
|
improved join clause parsing
|
4945 |
); |
4946 |
is_deeply($result->all, [{"$table2.$key3" => 4}]); |
|
4947 | ||
4948 |
$dbi = DBIx::Custom->connect; |
|
4949 |
eval { $dbi->execute("drop table $table1") }; |
|
4950 |
eval { $dbi->execute("drop table $table2") }; |
|
4951 |
$dbi->execute($create_table1); |
|
4952 |
$dbi->execute($create_table2); |
|
test cleanup
|
4953 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
4954 |
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2); |
4955 |
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2); |
|
improved join clause parsing
|
4956 |
$result = $dbi->select( |
cleanup
|
4957 |
table => $table1, |
4958 |
column => [{$table2 => [$key3]}], |
|
4959 |
join => [ |
|
4960 |
"left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1" |
|
4961 |
] |
|
improved join clause parsing
|
4962 |
); |
4963 |
is_deeply($result->all, [{"$table2.$key3" => 4}]); |
|
4964 | ||
added memory leak check test
|
4965 |
test 'columns'; |
4966 |
$dbi = MyDBI1->connect; |
|
4967 |
$model = $dbi->model($table1); |
|
4968 | ||
- added EXPERIMENTAL DBIx::C...
|
4969 |
test 'count'; |
4970 |
$dbi = DBIx::Custom->connect; |
|
4971 |
eval { $dbi->execute("drop table $table1") }; |
|
4972 |
$dbi->execute($create_table1); |
|
test cleanup
|
4973 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
4974 |
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1); |
- added EXPERIMENTAL DBIx::C...
|
4975 |
is($dbi->count(table => $table1), 2); |
4976 |
is($dbi->count(table => $table1, where => {$key2 => 2}), 1); |
|
4977 |
$model = $dbi->create_model(table => $table1); |
|
4978 |
is($model->count, 2); |
|
cleanup test
|
4979 | |
- fixed bug that DBIx::Custo...
|
4980 |
eval { $dbi->execute("drop table $table1") }; |
4981 |
eval { $dbi->execute("drop table $table2") }; |
|
4982 |
$dbi->execute($create_table1); |
|
4983 |
$dbi->execute($create_table2); |
|
4984 |
$model = $dbi->create_model(table => $table1, primary_key => $key1); |
|
4985 |
$model->insert({$key1 => 1, $key2 => 2}); |
|
4986 |
$model = $dbi->create_model(table => $table2, primary_key => $key1, |
|
cleanup
|
4987 |
join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]); |
- fixed bug that DBIx::Custo...
|
4988 |
$model->insert({$key1 => 1, $key3 => 3}); |
4989 |
is($model->count(id => 1), 1); |
|
4990 |
is($model->count(where => {"$table2.$key3" => 3}), 1); |
|
4991 | ||
fixed documentation miss abo...
|
4992 |
test 'table_alias option'; |
4993 |
$dbi = DBIx::Custom->connect; |
|
4994 |
eval { $dbi->execute("drop table $table1") }; |
|
4995 |
$dbi->execute($create_table1_type); |
|
4996 |
$dbi->insert({$key1 => '2010-01-01'}, table => $table1); |
|
4997 |
$dbi->user_column_info($user_column_info); |
|
4998 |
$dbi->type_rule( |
|
4999 |
into1 => { |
|
5000 |
$date_typename => sub { '2010-' . $_[0] } |
|
5001 |
} |
|
5002 |
); |
|
5003 |
$result = $dbi->execute( |
|
5004 |
"select * from $table1 TABLE1_ALIAS where :TABLE1_ALIAS.${key1}{=}", |
|
5005 |
{"TABLE1_ALIAS.${key1}" => '01-01'}, |
|
5006 |
table_alias => {TABLE1_ALIAS => $table1} |
|
5007 |
); |
|
5008 |
like($result->one->{$key1}, qr/^2010-01-01/); |
|
5009 | ||
5010 |
$dbi = DBIx::Custom->connect; |
|
5011 |
eval { $dbi->execute("drop table $table1") }; |
|
5012 |
$dbi->execute($create_table1_type); |
|
5013 |
$dbi->insert({$key1 => '2010-01-01'}, table => $table1); |
|
5014 |
$dbi->user_column_info($user_column_info); |
|
5015 |
$dbi->type_rule( |
|
5016 |
into2 => { |
|
5017 |
$date_typename => sub { '2010-' . $_[0] } |
|
5018 |
} |
|
5019 |
); |
|
5020 |
$result = $dbi->execute( |
|
5021 |
"select * from $table1 TABLE1_ALIAS where :TABLE1_ALIAS.${key1}{=}", |
|
5022 |
{"TABLE1_ALIAS.${key1}" => '01-01'}, |
|
5023 |
table_alias => {TABLE1_ALIAS => $table1} |
|
5024 |
); |
|
5025 |
like($result->one->{$key1}, qr/^2010-01-01/); |
|
5026 | ||
cleanup test
|
5027 |
1; |