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 | |
DBIx::Custom::Result::kv met...
|
8 |
$ENV{DBIX_CUSTOM_SUPPRESS_DEPRECATION} = '0.28'; |
- added DBIX_CUSTOM_SUPPRESS...
|
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 | ||
DBIx::Custom::Result::kv met...
|
3770 |
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key2"); |
3771 |
$rows = $result->kvs; |
|
3772 |
is_deeply($rows, { |
|
3773 |
0 => [ |
|
3774 |
{$key2 => 1}, |
|
3775 |
{$key2 => 2} |
|
3776 |
], |
|
3777 |
3 => [ |
|
3778 |
{$key2 => 4}, |
|
3779 |
{$key2 => 5} |
|
3780 |
] |
|
3781 |
}); |
|
added EXPERIMETAL DBIx::Cust...
|
3782 | |
- fixed bug DBIx::Custom::Re...
|
3783 |
test 'DBIx::Custom::Result fetch_multi'; |
3784 |
eval { $dbi->execute("drop table $table1") }; |
|
3785 |
$dbi->execute($create_table1); |
|
3786 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
|
3787 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
3788 |
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1); |
|
3789 |
$result = $dbi->select(table => $table1); |
|
3790 |
$rows = $result->fetch_multi(2); |
|
3791 |
is_deeply($rows, [[1, 2], [3, 4]]); |
|
3792 |
$rows = $result->fetch_multi(2); |
|
3793 |
is_deeply($rows, [[5, 6]]); |
|
3794 |
$rows = $result->fetch_multi(2); |
|
3795 |
ok(!$rows); |
|
3796 | ||
3797 |
test 'DBIx::Custom::Result fetch_hash_multi'; |
|
3798 |
eval { $dbi->execute("drop table $table1") }; |
|
3799 |
$dbi->execute($create_table1); |
|
3800 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
|
3801 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
3802 |
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1); |
|
3803 |
$result = $dbi->select(table => $table1); |
|
3804 |
$rows = $result->fetch_hash_multi(2); |
|
3805 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
|
3806 |
$rows = $result->fetch_hash_multi(2); |
|
3807 |
is_deeply($rows, [{$key1 => 5, $key2 => 6}]); |
|
3808 |
$rows = $result->fetch_hash_multi(2); |
|
3809 |
ok(!$rows); |
|
3810 | ||
test cleanup
|
3811 |
test "query_builder"; |
3812 |
$datas = [ |
|
cleanup
|
3813 |
# Basic tests |
3814 |
{ name => 'placeholder basic', |
|
3815 |
source => "a {? k1} b {= k2} {<> k3} {> k4} {< k5} {>= k6} {<= k7} {like k8}", , |
|
3816 |
sql_expected => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?", |
|
3817 |
columns_expected => [qw/k1 k2 k3 k4 k5 k6 k7 k8/] |
|
3818 |
}, |
|
3819 |
{ |
|
3820 |
name => 'placeholder in', |
|
3821 |
source => "{in k1 3}", |
|
3822 |
sql_expected => "k1 in (?, ?, ?)", |
|
3823 |
columns_expected => [qw/k1 k1 k1/] |
|
3824 |
}, |
|
3825 |
|
|
3826 |
# Table name |
|
3827 |
{ |
|
3828 |
name => 'placeholder with table name', |
|
3829 |
source => "{= a.k1} {= a.k2}", |
|
3830 |
sql_expected => "a.k1 = ? a.k2 = ?", |
|
3831 |
columns_expected => [qw/a.k1 a.k2/] |
|
3832 |
}, |
|
3833 |
{ |
|
3834 |
name => 'placeholder in with table name', |
|
3835 |
source => "{in a.k1 2} {in b.k2 2}", |
|
3836 |
sql_expected => "a.k1 in (?, ?) b.k2 in (?, ?)", |
|
3837 |
columns_expected => [qw/a.k1 a.k1 b.k2 b.k2/] |
|
3838 |
}, |
|
3839 |
{ |
|
3840 |
name => 'not contain tag', |
|
3841 |
source => "aaa", |
|
3842 |
sql_expected => "aaa", |
|
3843 |
columns_expected => [], |
|
3844 |
} |
|
test cleanup
|
3845 |
]; |
3846 | ||
3847 |
for (my $i = 0; $i < @$datas; $i++) { |
|
cleanup
|
3848 |
my $data = $datas->[$i]; |
3849 |
my $dbi = DBIx::Custom->new; |
|
3850 |
my $builder = $dbi->query_builder; |
|
3851 |
my $query = $builder->build_query($data->{source}); |
|
3852 |
is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql"); |
|
3853 |
is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns"); |
|
test cleanup
|
3854 |
} |
3855 | ||
cleanup
|
3856 |
$dbi = DBIx::Custom->new; |
3857 |
$builder = $dbi->query_builder; |
|
3858 |
$dbi->register_tag( |
|
cleanup
|
3859 |
p => sub { |
3860 |
my @args = @_; |
|
3861 |
|
|
3862 |
my $expand = "? $args[0] $args[1]"; |
|
3863 |
my $columns = [2]; |
|
3864 |
return [$expand, $columns]; |
|
3865 |
} |
|
test cleanup
|
3866 |
); |
3867 | ||
3868 |
$query = $builder->build_query("{p a b}"); |
|
cleanup test
|
3869 |
is($query->{sql}, "? a b", "register_tag sql"); |
test cleanup
|
3870 |
is_deeply($query->{columns}, [2], "register_tag columns"); |
3871 | ||
3872 |
eval{$builder->build_query('{? }')}; |
|
3873 |
like($@, qr/\QColumn name must be specified in tag "{? }"/, "? not arguments"); |
|
3874 | ||
3875 |
eval{$builder->build_query("{a }")}; |
|
3876 |
like($@, qr/\QTag "a" is not registered/, "tag not exist"); |
|
3877 | ||
cleanup
|
3878 |
$dbi->register_tag({ |
cleanup
|
3879 |
q => 'string' |
test cleanup
|
3880 |
}); |
3881 | ||
3882 |
eval{$builder->build_query("{q}", {})}; |
|
3883 |
like($@, qr/Tag "q" must be sub reference/, "tag not code ref"); |
|
3884 | ||
cleanup
|
3885 |
$dbi->register_tag({ |
cleanup
|
3886 |
r => sub {} |
test cleanup
|
3887 |
}); |
3888 | ||
3889 |
eval{$builder->build_query("{r}")}; |
|
3890 |
like($@, qr/\QTag "r" must return [STRING, ARRAY_REFERENCE]/, "tag return noting"); |
|
3891 | ||
cleanup
|
3892 |
$dbi->register_tag({ |
cleanup
|
3893 |
s => sub { return ["a", ""]} |
test cleanup
|
3894 |
}); |
3895 | ||
3896 |
eval{$builder->build_query("{s}")}; |
|
3897 |
like($@, qr/\QTag "s" must return [STRING, ARRAY_REFERENCE]/, "tag return not array columns"); |
|
3898 | ||
cleanup
|
3899 |
$dbi->register_tag( |
cleanup
|
3900 |
t => sub {return ["a", []]} |
test cleanup
|
3901 |
); |
3902 | ||
3903 | ||
cleanup test
|
3904 |
test 'Default tag Error case'; |
3905 |
eval{$builder->build_query("{= }")}; |
|
fixed bug that when id optio...
|
3906 |
like($@, qr/\QColumn name must be specified in tag "{= }"/, "basic '=' : key not exist"); |
cleanup test
|
3907 | |
3908 |
eval{$builder->build_query("{in }")}; |
|
fixed bug that when id optio...
|
3909 |
like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/, "in : key not exist"); |
cleanup test
|
3910 | |
3911 |
eval{$builder->build_query("{in a}")}; |
|
3912 |
like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/, |
|
cleanup
|
3913 |
"in : key not exist"); |
cleanup test
|
3914 | |
3915 |
eval{$builder->build_query("{in a r}")}; |
|
3916 |
like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/, |
|
cleanup
|
3917 |
"in : key not exist"); |
cleanup test
|
3918 | |
3919 |
test 'variouse source'; |
|
3920 |
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d"; |
|
3921 |
$query = $builder->build_query($source); |
|
3922 |
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1"); |
|
3923 | ||
3924 |
$source = "abc"; |
|
3925 |
$query = $builder->build_query($source); |
|
micro optimization
|
3926 |
is($query->{sql}, 'abc', "basic : 2"); |
cleanup test
|
3927 | |
3928 |
$source = "{= a}"; |
|
3929 |
$query = $builder->build_query($source); |
|
micro optimization
|
3930 |
is($query->{sql}, 'a = ?', "only tag"); |
cleanup test
|
3931 | |
3932 |
$source = "000"; |
|
3933 |
$query = $builder->build_query($source); |
|
micro optimization
|
3934 |
is($query->{sql}, '000', "contain 0 value"); |
cleanup test
|
3935 | |
3936 |
$source = "a {= b} }"; |
|
3937 |
eval{$builder->build_query($source)}; |
|
3938 |
like($@, qr/unexpected "}"/, "error : 1"); |
|
3939 | ||
3940 |
$source = "a {= {}"; |
|
3941 |
eval{$builder->build_query($source)}; |
|
fixed bug that when id optio...
|
3942 |
like($@, qr/\Qunexpected "{"/, "error : 2"); |
cleanup test
|
3943 | |
3944 |
test 'select() sqlfilter option'; |
|
3945 |
$dbi = DBIx::Custom->connect; |
|
cleanup test
|
3946 |
$dbi->user_table_info($user_table_info); |
cleanup test
|
3947 |
eval { $dbi->execute("drop table $table1") }; |
3948 |
$dbi->execute($create_table1); |
|
test cleanup
|
3949 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
3950 |
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1); |
cleanup test
|
3951 |
$rows = $dbi->select( |
cleanup
|
3952 |
table => $table1, |
3953 |
column => $key1, |
|
3954 |
sqlfilter => sub { |
|
3955 |
my $sql = shift; |
|
3956 |
$sql = "select * from ( $sql ) t where $key1 = 1"; |
|
3957 |
return $sql; |
|
3958 |
} |
|
cleanup test
|
3959 |
)->all; |
3960 |
is_deeply($rows, [{$key1 => 1}]); |
|
3961 | ||
sqlfilter option is renamed ...
|
3962 |
test 'select() after_build_sql option'; |
3963 |
$dbi = DBIx::Custom->connect; |
|
3964 |
$dbi->user_table_info($user_table_info); |
|
3965 |
eval { $dbi->execute("drop table $table1") }; |
|
3966 |
$dbi->execute($create_table1); |
|
test cleanup
|
3967 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
3968 |
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1); |
sqlfilter option is renamed ...
|
3969 |
$rows = $dbi->select( |
cleanup
|
3970 |
table => $table1, |
3971 |
column => $key1, |
|
3972 |
after_build_sql => sub { |
|
3973 |
my $sql = shift; |
|
3974 |
$sql = "select * from ( $sql ) t where $key1 = 1"; |
|
3975 |
return $sql; |
|
3976 |
} |
|
sqlfilter option is renamed ...
|
3977 |
)->all; |
3978 |
is_deeply($rows, [{$key1 => 1}]); |
|
3979 | ||
cleanup test
|
3980 |
test 'dbi method from model'; |
3981 |
$dbi = MyDBI9->connect; |
|
3982 |
eval { $dbi->execute("drop table $table1") }; |
|
3983 |
$dbi->execute($create_table1); |
|
fixed setup method logic
|
3984 |
$dbi->setup_model; |
cleanup test
|
3985 |
$model = $dbi->model($table1); |
3986 |
eval{$model->execute("select * from $table1")}; |
|
3987 |
ok(!$@); |
|
3988 | ||
3989 |
test 'column table option'; |
|
3990 |
$dbi = MyDBI9->connect; |
|
cleanup test
|
3991 |
$dbi->user_table_info($user_table_info); |
cleanup test
|
3992 |
eval { $dbi->execute("drop table $table1") }; |
3993 |
$dbi->execute($create_table1); |
|
3994 |
eval { $dbi->execute("drop table $table2") }; |
|
3995 |
$dbi->execute($create_table2); |
|
fixed setup method logic
|
3996 |
$dbi->setup_model; |
cleanup test
|
3997 |
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)"); |
3998 |
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)"); |
|
3999 |
$model = $dbi->model($table1); |
|
4000 |
$result = $model->select( |
|
cleanup
|
4001 |
column => [ |
improved test
|
4002 |
$model->column($table2, {alias => u$table2_alias}) |
cleanup
|
4003 |
], |
improved test
|
4004 |
where => {u($table2_alias) . ".$key3" => 4} |
cleanup test
|
4005 |
); |
4006 |
is_deeply($result->one, |
|
improved test
|
4007 |
{u($table2_alias) . ".$key1" => 1, u($table2_alias) . ".$key3" => 4}); |
cleanup test
|
4008 | |
4009 |
$dbi->separator('__'); |
|
4010 |
$result = $model->select( |
|
cleanup
|
4011 |
column => [ |
improved test
|
4012 |
$model->column($table2, {alias => u$table2_alias}) |
cleanup
|
4013 |
], |
improved test
|
4014 |
where => {u($table2_alias) . ".$key3" => 4} |
cleanup test
|
4015 |
); |
4016 |
is_deeply($result->one, |
|
improved test
|
4017 |
{u(${table2_alias}) . "__$key1" => 1, u(${table2_alias}) . "__$key3" => 4}); |
cleanup test
|
4018 | |
4019 |
$dbi->separator('-'); |
|
4020 |
$result = $model->select( |
|
cleanup
|
4021 |
column => [ |
improved test
|
4022 |
$model->column($table2, {alias => u$table2_alias}) |
cleanup
|
4023 |
], |
improved test
|
4024 |
where => {u($table2_alias) . ".$key3" => 4} |
cleanup test
|
4025 |
); |
4026 |
is_deeply($result->one, |
|
improved test
|
4027 |
{u(${table2_alias}) . "-$key1" => 1, u(${table2_alias}) . "-$key3" => 4}); |
cleanup test
|
4028 | |
4029 |
test 'create_model'; |
|
4030 |
$dbi = DBIx::Custom->connect; |
|
cleanup test
|
4031 |
$dbi->user_table_info($user_table_info); |
cleanup test
|
4032 |
eval { $dbi->execute("drop table $table1") }; |
4033 |
eval { $dbi->execute("drop table $table2") }; |
|
4034 |
$dbi->execute($create_table1); |
|
4035 |
$dbi->execute($create_table2); |
|
4036 | ||
4037 |
$dbi->create_model( |
|
cleanup
|
4038 |
table => $table1, |
4039 |
join => [ |
|
4040 |
"left outer join $table2 on $table1.$key1 = $table2.$key1" |
|
4041 |
], |
|
4042 |
primary_key => [$key1] |
|
cleanup test
|
4043 |
); |
4044 |
$model2 = $dbi->create_model( |
|
cleanup
|
4045 |
table => $table2 |
cleanup test
|
4046 |
); |
4047 |
$dbi->create_model( |
|
cleanup
|
4048 |
table => $table3, |
4049 |
filter => [ |
|
4050 |
$key1 => {in => sub { uc $_[0] }} |
|
4051 |
] |
|
cleanup test
|
4052 |
); |
fixed setup method logic
|
4053 |
$dbi->setup_model; |
test cleanup
|
4054 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
4055 |
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2); |
cleanup test
|
4056 |
$model = $dbi->model($table1); |
4057 |
$result = $model->select( |
|
cleanup
|
4058 |
column => [$model->mycolumn, $model->column($table2)], |
4059 |
where => {"$table1.$key1" => 1} |
|
cleanup test
|
4060 |
); |
4061 |
is_deeply($result->one, |
|
cleanup
|
4062 |
{$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3}); |
cleanup test
|
4063 |
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3}); |
4064 | ||
4065 |
test 'model method'; |
|
4066 |
$dbi = DBIx::Custom->connect; |
|
4067 |
eval { $dbi->execute("drop table $table2") }; |
|
4068 |
$dbi->execute($create_table2); |
|
cleanup
|
4069 |
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2); |
cleanup test
|
4070 |
$model = $dbi->create_model( |
cleanup
|
4071 |
table => $table2 |
cleanup test
|
4072 |
); |
4073 |
$model->method(foo => sub { shift->select(@_) }); |
|
4074 |
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3}); |
|
- method method of DBIx::Cus...
|
4075 | |
4076 |
test 'model helper'; |
|
4077 |
$dbi = DBIx::Custom->connect; |
|
4078 |
eval { $dbi->execute("drop table $table2") }; |
|
4079 |
$dbi->execute($create_table2); |
|
cleanup
|
4080 |
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2); |
- method method of DBIx::Cus...
|
4081 |
$model = $dbi->create_model( |
cleanup
|
4082 |
table => $table2 |
- method method of DBIx::Cus...
|
4083 |
); |
4084 |
$model->helper(foo => sub { shift->select(@_) }); |
|
4085 |
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3}); |
|
cleanup test
|
4086 | |
- update_param is DEPRECATED...
|
4087 |
test 'assign_clause'; |
cleanup test
|
4088 |
$dbi = DBIx::Custom->connect; |
4089 |
eval { $dbi->execute("drop table $table1") }; |
|
4090 |
$dbi->execute($create_table1_2); |
|
test cleanup
|
4091 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
4092 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
cleanup test
|
4093 | |
4094 |
$param = {$key2 => 11}; |
|
- update_param is DEPRECATED...
|
4095 |
$assign_clause = $dbi->assign_clause($param); |
cleanup test
|
4096 |
$sql = <<"EOS"; |
- update_param is DEPRECATED...
|
4097 |
update $table1 set $assign_clause |
cleanup test
|
4098 |
where $key1 = 1 |
4099 |
EOS |
|
cleanup
|
4100 |
$dbi->execute($sql, $param); |
cleanup test
|
4101 |
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1); |
4102 |
$rows = $result->all; |
|
4103 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
|
cleanup
|
4104 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
4105 |
"basic"); |
|
cleanup test
|
4106 | |
4107 | ||
4108 |
$dbi = DBIx::Custom->connect; |
|
4109 |
eval { $dbi->execute("drop table $table1") }; |
|
4110 |
$dbi->execute($create_table1_2); |
|
test cleanup
|
4111 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
4112 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
cleanup test
|
4113 | |
4114 |
$param = {$key2 => 11, $key3 => 33}; |
|
- update_param is DEPRECATED...
|
4115 |
$assign_clause = $dbi->assign_clause($param); |
cleanup test
|
4116 |
$sql = <<"EOS"; |
- update_param is DEPRECATED...
|
4117 |
update $table1 set $assign_clause |
cleanup test
|
4118 |
where $key1 = 1 |
4119 |
EOS |
|
cleanup
|
4120 |
$dbi->execute($sql, $param); |
cleanup test
|
4121 |
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1); |
4122 |
$rows = $result->all; |
|
4123 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5}, |
|
cleanup
|
4124 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
4125 |
"basic"); |
|
cleanup test
|
4126 | |
4127 |
$dbi = DBIx::Custom->connect; |
|
4128 |
eval { $dbi->execute("drop table $table1") }; |
|
4129 |
$dbi->execute($create_table1_2); |
|
test cleanup
|
4130 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
4131 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
cleanup test
|
4132 | |
4133 |
$param = {$key2 => 11, $key3 => 33}; |
|
- update_param is DEPRECATED...
|
4134 |
$assign_clause = $dbi->update_param($param, {no_set => 1}); |
cleanup test
|
4135 |
$sql = <<"EOS"; |
- update_param is DEPRECATED...
|
4136 |
update $table1 set $assign_clause |
cleanup test
|
4137 |
where $key1 = 1 |
4138 |
EOS |
|
cleanup
|
4139 |
$dbi->execute($sql, $param); |
cleanup test
|
4140 |
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1); |
4141 |
$rows = $result->all; |
|
4142 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5}, |
|
cleanup
|
4143 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
4144 |
"update param no_set"); |
|
cleanup test
|
4145 | |
cleanup
|
4146 |
|
cleanup test
|
4147 |
$dbi = DBIx::Custom->connect; |
4148 |
eval { $dbi->execute("drop table $table1") }; |
|
4149 |
$dbi->execute($create_table1_2); |
|
test cleanup
|
4150 |
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1); |
4151 |
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1); |
|
test cleanup
|
4152 | |
cleanup test
|
4153 |
$param = {$key2 => 11}; |
- update_param is DEPRECATED...
|
4154 |
$assign_clause = $dbi->assign_param($param); |
4155 |
$sql = <<"EOS"; |
|
4156 |
update $table1 set $assign_clause |
|
4157 |
where $key1 = 1 |
|
4158 |
EOS |
|
cleanup
|
4159 |
$dbi->execute($sql, $param, table => $table1); |
- update_param is DEPRECATED...
|
4160 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
4161 |
$rows = $result->all; |
|
4162 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
|
cleanup
|
4163 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
4164 |
"basic"); |
|
- update_param is DEPRECATED...
|
4165 | |
4166 |
$param = {$key2 => 11}; |
|
4167 |
$assign_clause = $dbi->assign_clause($param); |
|
cleanup test
|
4168 |
$sql = <<"EOS"; |
- update_param is DEPRECATED...
|
4169 |
update $table1 set $assign_clause |
cleanup test
|
4170 |
where $key1 = 1 |
4171 |
EOS |
|
cleanup
|
4172 |
$dbi->execute($sql, $param, table => $table1); |
cleanup test
|
4173 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
4174 |
$rows = $result->all; |
|
4175 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
|
cleanup
|
4176 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
4177 |
"basic"); |
|
test cleanup
|
4178 | |
cleanup test
|
4179 |
test 'Model class'; |
4180 |
$dbi = MyDBI1->connect; |
|
4181 |
eval { $dbi->execute("drop table $table1") }; |
|
4182 |
$dbi->execute($create_table1); |
|
4183 |
$model = $dbi->model($table1); |
|
4184 |
$model->insert({$key1 => 'a', $key2 => 'b'}); |
|
4185 |
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic'); |
|
4186 |
eval { $dbi->execute("drop table $table2") }; |
|
4187 |
$dbi->execute($create_table2); |
|
4188 |
$model = $dbi->model($table2); |
|
4189 |
$model->insert({$key1 => 'a'}); |
|
4190 |
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic'); |
|
4191 |
is($dbi->models->{$table1}, $dbi->model($table1)); |
|
4192 |
is($dbi->models->{$table2}, $dbi->model($table2)); |
|
4193 | ||
4194 |
$dbi = MyDBI4->connect; |
|
4195 |
eval { $dbi->execute("drop table $table1") }; |
|
4196 |
$dbi->execute($create_table1); |
|
4197 |
$model = $dbi->model($table1); |
|
4198 |
$model->insert({$key1 => 'a', $key2 => 'b'}); |
|
4199 |
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic'); |
|
4200 |
eval { $dbi->execute("drop table $table2") }; |
|
4201 |
$dbi->execute($create_table2); |
|
4202 |
$model = $dbi->model($table2); |
|
4203 |
$model->insert({$key1 => 'a'}); |
|
4204 |
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic'); |
|
4205 | ||
4206 |
$dbi = MyDBI5->connect; |
|
4207 |
eval { $dbi->execute("drop table $table1") }; |
|
4208 |
eval { $dbi->execute("drop table $table2") }; |
|
4209 |
$dbi->execute($create_table1); |
|
4210 |
$dbi->execute($create_table2); |
|
4211 |
$model = $dbi->model($table2); |
|
4212 |
$model->insert({$key1 => 'a'}); |
|
4213 |
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model'); |
|
cleanup
|
4214 |
$dbi->insert({$key1 => 1}, table => $table1); |
cleanup test
|
4215 |
$model = $dbi->model($table1); |
4216 |
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model'); |
|
4217 | ||
4218 |
test 'primary_key'; |
|
4219 |
$dbi = MyDBI1->connect; |
|
4220 |
$model = $dbi->model($table1); |
|
4221 |
$model->primary_key([$key1, $key2]); |
|
4222 |
is_deeply($model->primary_key, [$key1, $key2]); |
|
4223 | ||
4224 |
test 'columns'; |
|
4225 |
$dbi = MyDBI1->connect; |
|
4226 |
$model = $dbi->model($table1); |
|
4227 |
$model->columns([$key1, $key2]); |
|
4228 |
is_deeply($model->columns, [$key1, $key2]); |
|
cleanup test
|
4229 | |
- added DBIX_CUSTOM_SUPPRESS...
|
4230 |
test 'columns'; |
4231 |
$dbi = MyDBI1->connect; |
|
4232 |
$model = $dbi->model($table1); |
|
4233 |
$model->columns([$key1, $key2]); |
|
4234 |
is_deeply($model->columns, [$key1, $key2]); |
|
4235 | ||
cleanup test
|
4236 |
test 'setup_model'; |
4237 |
$dbi = MyDBI1->connect; |
|
cleanup test
|
4238 |
$dbi->user_table_info($user_table_info); |
finishied sqlite test cleanu...
|
4239 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4240 |
eval { $dbi->execute("drop table $table2") }; |
added EXPERIMENTAL execute m...
|
4241 | |
cleanup test
|
4242 |
$dbi->execute($create_table1); |
cleanup test
|
4243 |
$dbi->execute($create_table2); |
fixed setup method logic
|
4244 |
$dbi->setup_model; |
cleanup test
|
4245 |
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]); |
4246 |
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]); |
|
cleanup test
|
4247 | |
cleanup test
|
4248 |
test 'each_column'; |
4249 |
$dbi = DBIx::Custom->connect; |
|
4250 |
eval { $dbi->execute("drop table ${q}table$p") }; |
|
finishied sqlite test cleanu...
|
4251 |
eval { $dbi->execute("drop table $table1") }; |
4252 |
eval { $dbi->execute("drop table $table2") }; |
|
cleanup test
|
4253 |
eval { $dbi->execute("drop table $table3") }; |
4254 |
$dbi->execute($create_table1_type); |
|
cleanup test
|
4255 |
$dbi->execute($create_table2); |
cleanup test
|
4256 | |
4257 |
$infos = []; |
|
4258 |
$dbi->each_column(sub { |
|
cleanup
|
4259 |
my ($self, $table, $column, $cinfo) = @_; |
4260 |
|
|
4261 |
if ($table =~ /^table\d/i) { |
|
4262 |
my $info = [$table, $column, $cinfo->{COLUMN_NAME}]; |
|
4263 |
push @$infos, $info; |
|
4264 |
} |
|
cleanup test
|
4265 |
}); |
4266 |
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos]; |
|
4267 |
is_deeply($infos, |
|
cleanup
|
4268 |
[ |
improved tests
|
4269 |
[table_only($table1), $key1, $key1], |
4270 |
[table_only($table1), $key2, $key2], |
|
4271 |
[table_only($table2), $key1, $key1], |
|
4272 |
[table_only($table2), $key3, $key3] |
|
cleanup
|
4273 |
] |
4274 |
|
|
cleanup test
|
4275 |
); |
cleanup test
|
4276 | |
cleanup test
|
4277 |
test 'each_table'; |
4278 |
$dbi = DBIx::Custom->connect; |
|
4279 |
eval { $dbi->execute("drop table $table1") }; |
|
4280 |
eval { $dbi->execute("drop table $table2") }; |
|
4281 |
$dbi->execute($create_table2); |
|
4282 |
$dbi->execute($create_table1_type); |
|
cleanup test
|
4283 | |
cleanup test
|
4284 |
$infos = []; |
4285 |
$dbi->each_table(sub { |
|
cleanup
|
4286 |
my ($self, $table, $table_info) = @_; |
4287 |
|
|
4288 |
if ($table =~ /^table\d/i) { |
|
4289 |
my $info = [$table, $table_info->{TABLE_NAME}]; |
|
4290 |
push @$infos, $info; |
|
4291 |
} |
|
cleanup test
|
4292 |
}); |
4293 |
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos]; |
|
4294 |
is_deeply($infos, |
|
cleanup
|
4295 |
[ |
improved tests
|
4296 |
[table_only($table1), table_only($table1)], |
4297 |
[table_only($table2), table_only($table2)], |
|
cleanup
|
4298 |
] |
cleanup test
|
4299 |
); |
4300 | ||
cleanup test
|
4301 |
$dbi = DBIx::Custom->connect; |
4302 |
eval { $dbi->execute("drop table $table1") }; |
|
4303 |
eval { $dbi->execute("drop table $table2") }; |
|
4304 |
$dbi->execute($create_table2); |
|
4305 |
$dbi->execute($create_table1_type); |
|
4306 | ||
4307 |
$infos = []; |
|
4308 |
$dbi->user_table_info($user_table_info); |
|
4309 |
$dbi->each_table(sub { |
|
cleanup
|
4310 |
my ($self, $table, $table_info) = @_; |
4311 |
|
|
4312 |
if ($table =~ /^table\d/i) { |
|
4313 |
my $info = [$table, $table_info->{TABLE_NAME}]; |
|
4314 |
push @$infos, $info; |
|
4315 |
} |
|
cleanup test
|
4316 |
}); |
4317 |
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos]; |
|
4318 |
is_deeply($infos, |
|
cleanup
|
4319 |
[ |
improved tests
|
4320 |
[table_only($table1), table_only($table1)], |
4321 |
[table_only($table2), table_only($table2)], |
|
4322 |
[table_only($table3), table_only($table3)], |
|
cleanup
|
4323 |
] |
cleanup test
|
4324 |
); |
4325 | ||
cleanup test
|
4326 |
test 'type_rule into'; |
4327 |
eval { $dbi->execute("drop table $table1") }; |
|
4328 |
$dbi->execute($create_table1_type); |
|
cleanup
|
4329 |
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table); |
4330 | ||
4331 | ||
cleanup test
|
4332 |
$dbi = DBIx::Custom->connect; |
4333 |
eval { $dbi->execute("drop table $table1") }; |
|
4334 |
$dbi->execute($create_table1_type); |
|
4335 | ||
cleanup
|
4336 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4337 |
$dbi->type_rule( |
cleanup
|
4338 |
into1 => { |
4339 |
$date_typename => sub { '2010-' . $_[0] } |
|
4340 |
} |
|
cleanup test
|
4341 |
); |
cleanup test
|
4342 |
$dbi->insert({$key1 => '01-01'}, table => $table1); |
4343 |
$result = $dbi->select(table => $table1); |
|
4344 |
like($result->one->{$key1}, qr/^2010-01-01/); |
|
cleanup test
|
4345 | |
4346 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
4347 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4348 |
$dbi->execute($create_table1_type); |
cleanup
|
4349 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4350 |
$dbi->type_rule( |
cleanup
|
4351 |
into1 => [ |
4352 |
[$date_typename, $datetime_typename] => sub { |
|
4353 |
my $value = shift; |
|
4354 |
$value =~ s/02/03/g; |
|
4355 |
return $value; |
|
4356 |
} |
|
4357 |
] |
|
cleanup test
|
4358 |
); |
4359 |
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1); |
|
4360 |
$result = $dbi->select(table => $table1); |
|
4361 |
$row = $result->one; |
|
4362 |
like($row->{$key1}, qr/^2010-01-03/); |
|
4363 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
cleanup test
|
4364 | |
cleanup test
|
4365 |
$dbi = DBIx::Custom->connect; |
4366 |
eval { $dbi->execute("drop table $table1") }; |
|
4367 |
$dbi->execute($create_table1_type); |
|
4368 |
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1); |
|
cleanup
|
4369 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4370 |
$dbi->type_rule( |
cleanup
|
4371 |
into1 => [ |
4372 |
[$date_typename, $datetime_typename] => sub { |
|
4373 |
my $value = shift; |
|
4374 |
$value =~ s/02/03/g; |
|
4375 |
return $value; |
|
4376 |
} |
|
4377 |
] |
|
cleanup test
|
4378 |
); |
cleanup test
|
4379 |
$result = $dbi->execute( |
cleanup
|
4380 |
"select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2", |
4381 |
{$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'} |
|
cleanup test
|
4382 |
); |
cleanup test
|
4383 |
$row = $result->one; |
4384 |
like($row->{$key1}, qr/^2010-01-03/); |
|
4385 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
4386 | ||
4387 |
$dbi = DBIx::Custom->connect; |
|
4388 |
eval { $dbi->execute("drop table $table1") }; |
|
4389 |
$dbi->execute($create_table1_type); |
|
4390 |
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1); |
|
cleanup
|
4391 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4392 |
$dbi->type_rule( |
cleanup
|
4393 |
into1 => [ |
4394 |
[$date_typename, $datetime_typename] => sub { |
|
4395 |
my $value = shift; |
|
4396 |
$value =~ s/02/03/g; |
|
4397 |
return $value; |
|
4398 |
} |
|
4399 |
] |
|
cleanup test
|
4400 |
); |
cleanup test
|
4401 |
$result = $dbi->execute( |
cleanup
|
4402 |
"select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2", |
4403 |
{$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'}, |
|
4404 |
table => $table1 |
|
cleanup test
|
4405 |
); |
4406 |
$row = $result->one; |
|
4407 |
like($row->{$key1}, qr/^2010-01-03/); |
|
4408 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
|
4409 | ||
4410 |
$dbi = DBIx::Custom->connect; |
|
4411 |
eval { $dbi->execute("drop table $table1") }; |
|
4412 |
$dbi->execute($create_table1_type); |
|
4413 |
$dbi->register_filter(convert => sub { |
|
cleanup
|
4414 |
my $value = shift || ''; |
4415 |
$value =~ s/02/03/; |
|
4416 |
return $value; |
|
cleanup test
|
4417 |
}); |
cleanup
|
4418 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4419 |
$dbi->type_rule( |
cleanup
|
4420 |
from1 => { |
4421 |
$date_datatype => 'convert', |
|
4422 |
}, |
|
4423 |
into1 => { |
|
4424 |
$date_typename => 'convert', |
|
4425 |
} |
|
cleanup test
|
4426 |
); |
4427 |
$dbi->insert({$key1 => '2010-02-02'}, table => $table1); |
|
4428 |
$result = $dbi->select(table => $table1); |
|
4429 |
like($result->fetch->[0], qr/^2010-03-03/); |
|
- fixed bug DBIx::Custom::Re...
|
4430 |
$result = $dbi->select(column => [$key1, $key1], table => $table1); |
4431 |
$row = $result->fetch; |
|
4432 |
like($row->[0], qr/^2010-03-03/); |
|
4433 |
like($row->[1], qr/^2010-03-03/); |
|
cleanup test
|
4434 | |
4435 |
test 'type_rule and filter order'; |
|
4436 |
$dbi = DBIx::Custom->connect; |
|
4437 |
eval { $dbi->execute("drop table $table1") }; |
|
4438 |
$dbi->execute($create_table1_type); |
|
cleanup
|
4439 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4440 |
$dbi->type_rule( |
cleanup
|
4441 |
into1 => { |
4442 |
$date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
|
4443 |
}, |
|
4444 |
into2 => { |
|
4445 |
$date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v } |
|
4446 |
}, |
|
4447 |
from1 => { |
|
4448 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v } |
|
4449 |
}, |
|
4450 |
from2 => { |
|
4451 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v } |
|
4452 |
} |
|
cleanup test
|
4453 |
); |
4454 |
$dbi->insert({$key1 => '2010-01-03'}, |
|
cleanup
|
4455 |
table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }}); |
cleanup test
|
4456 |
$result = $dbi->select(table => $table1); |
4457 |
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v }); |
|
- renamed DBIx::Custom::Resu...
|
4458 |
like($result->fetch_one->[0], qr/^2010-01-09/); |
cleanup test
|
4459 | |
4460 | ||
4461 |
$dbi = DBIx::Custom->connect; |
|
4462 |
eval { $dbi->execute("drop table $table1") }; |
|
4463 |
$dbi->execute($create_table1_type); |
|
cleanup
|
4464 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4465 |
$dbi->type_rule( |
cleanup
|
4466 |
from1 => { |
4467 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4468 |
}, |
|
4469 |
from2 => { |
|
4470 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
|
4471 |
}, |
|
cleanup test
|
4472 |
); |
4473 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
4474 |
$result = $dbi->select(table => $table1); |
|
cleanup
|
4475 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4476 |
$result->type_rule( |
cleanup
|
4477 |
from1 => { |
4478 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v } |
|
4479 |
}, |
|
4480 |
from2 => { |
|
4481 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v } |
|
4482 |
} |
|
cleanup test
|
4483 |
); |
cleanup test
|
4484 |
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v }); |
- renamed DBIx::Custom::Resu...
|
4485 |
like($result->fetch_one->[0], qr/^2010-01-09/); |
cleanup test
|
4486 | |
cleanup test
|
4487 |
test 'type_rule_off'; |
cleanup test
|
4488 |
$dbi = DBIx::Custom->connect; |
cleanup test
|
4489 |
eval { $dbi->execute("drop table $table1") }; |
4490 |
$dbi->execute($create_table1_type); |
|
cleanup
|
4491 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4492 |
$dbi->type_rule( |
cleanup
|
4493 |
from1 => { |
4494 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4495 |
}, |
|
4496 |
into1 => { |
|
4497 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4498 |
} |
|
cleanup test
|
4499 |
); |
cleanup test
|
4500 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1); |
4501 |
$result = $dbi->select(table => $table1, type_rule_off => 1); |
|
4502 |
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/); |
|
cleanup test
|
4503 | |
cleanup test
|
4504 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
4505 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4506 |
$dbi->execute($create_table1_type); |
cleanup
|
4507 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4508 |
$dbi->type_rule( |
cleanup
|
4509 |
from1 => { |
4510 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4511 |
}, |
|
4512 |
into1 => { |
|
4513 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4514 |
} |
|
cleanup test
|
4515 |
); |
4516 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1); |
|
4517 |
$result = $dbi->select(table => $table1, type_rule_off => 1); |
|
4518 |
like($result->one->{$key1}, qr/^2010-01-04/); |
|
cleanup test
|
4519 | |
4520 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
4521 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4522 |
$dbi->execute($create_table1_type); |
cleanup
|
4523 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4524 |
$dbi->type_rule( |
cleanup
|
4525 |
from1 => { |
4526 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
|
4527 |
}, |
|
4528 |
into1 => { |
|
4529 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4530 |
} |
|
cleanup test
|
4531 |
); |
4532 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
4533 |
$result = $dbi->select(table => $table1); |
|
4534 |
like($result->one->{$key1}, qr/^2010-01-05/); |
|
cleanup test
|
4535 | |
4536 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
4537 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4538 |
$dbi->execute($create_table1_type); |
cleanup
|
4539 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4540 |
$dbi->type_rule( |
cleanup
|
4541 |
from1 => { |
4542 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
|
4543 |
}, |
|
4544 |
into1 => { |
|
4545 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4546 |
} |
|
cleanup test
|
4547 |
); |
4548 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
4549 |
$result = $dbi->select(table => $table1); |
|
4550 |
like($result->fetch->[0], qr/2010-01-05/); |
|
cleanup test
|
4551 | |
4552 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
4553 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4554 |
$dbi->execute($create_table1_type); |
4555 |
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }); |
|
cleanup
|
4556 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4557 |
$dbi->type_rule( |
cleanup
|
4558 |
into1 => { |
4559 |
$date_typename => 'ppp' |
|
4560 |
} |
|
cleanup test
|
4561 |
); |
4562 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
4563 |
$result = $dbi->select(table => $table1); |
|
4564 |
like($result->one->{$key1}, qr/^2010-01-04/); |
|
cleanup test
|
4565 | |
cleanup test
|
4566 |
eval{$dbi->type_rule( |
cleanup
|
4567 |
into1 => { |
4568 |
$date_typename => 'pp' |
|
4569 |
} |
|
cleanup test
|
4570 |
)}; |
4571 |
like($@, qr/not registered/); |
|
cleanup test
|
4572 | |
cleanup test
|
4573 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
4574 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4575 |
$dbi->execute($create_table1_type); |
cleanup test
|
4576 |
eval { |
cleanup
|
4577 |
$dbi->type_rule( |
4578 |
from1 => { |
|
4579 |
Date => sub { $_[0] * 2 }, |
|
4580 |
} |
|
4581 |
); |
|
cleanup test
|
4582 |
}; |
cleanup test
|
4583 |
like($@, qr/lower/); |
cleanup test
|
4584 | |
cleanup test
|
4585 |
eval { |
cleanup
|
4586 |
$dbi->type_rule( |
4587 |
into1 => { |
|
4588 |
Date => sub { $_[0] * 2 }, |
|
4589 |
} |
|
4590 |
); |
|
cleanup test
|
4591 |
}; |
4592 |
like($@, qr/lower/); |
|
cleanup test
|
4593 | |
4594 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
4595 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4596 |
$dbi->execute($create_table1_type); |
cleanup
|
4597 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4598 |
$dbi->type_rule( |
cleanup
|
4599 |
from1 => { |
4600 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
|
4601 |
}, |
|
4602 |
into1 => { |
|
4603 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4604 |
} |
|
cleanup test
|
4605 |
); |
4606 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
4607 |
$result = $dbi->select(table => $table1); |
|
4608 |
$result->type_rule_off; |
|
4609 |
like($result->one->{$key1}, qr/^2010-01-04/); |
|
cleanup test
|
4610 | |
4611 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
4612 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4613 |
$dbi->execute($create_table1_type); |
cleanup
|
4614 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4615 |
$dbi->type_rule( |
cleanup
|
4616 |
from1 => { |
4617 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }, |
|
4618 |
$datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4619 |
}, |
|
cleanup test
|
4620 |
); |
cleanup test
|
4621 |
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1); |
4622 |
$result = $dbi->select(table => $table1); |
|
4623 |
$result->type_rule( |
|
cleanup
|
4624 |
from1 => { |
4625 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4626 |
} |
|
cleanup test
|
4627 |
); |
cleanup test
|
4628 |
$row = $result->one; |
4629 |
like($row->{$key1}, qr/^2010-01-05/); |
|
4630 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
4631 | ||
4632 |
$result = $dbi->select(table => $table1); |
|
4633 |
$result->type_rule( |
|
cleanup
|
4634 |
from1 => { |
4635 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4636 |
} |
|
cleanup test
|
4637 |
); |
cleanup test
|
4638 |
$row = $result->one; |
4639 |
like($row->{$key1}, qr/2010-01-05/); |
|
4640 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
|
4641 | ||
4642 |
$result = $dbi->select(table => $table1); |
|
4643 |
$result->type_rule( |
|
cleanup
|
4644 |
from1 => { |
4645 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4646 |
} |
|
cleanup test
|
4647 |
); |
4648 |
$row = $result->one; |
|
4649 |
like($row->{$key1}, qr/2010-01-05/); |
|
4650 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
|
4651 | ||
4652 |
$result = $dbi->select(table => $table1); |
|
4653 |
$result->type_rule( |
|
cleanup
|
4654 |
from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }] |
cleanup test
|
4655 |
); |
4656 |
$row = $result->one; |
|
4657 |
like($row->{$key1}, qr/2010-01-05/); |
|
4658 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
|
4659 | ||
4660 |
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }); |
|
4661 |
$result = $dbi->select(table => $table1); |
|
4662 |
$result->type_rule( |
|
cleanup
|
4663 |
from1 => [$date_datatype => 'five'] |
cleanup test
|
4664 |
); |
4665 |
$row = $result->one; |
|
4666 |
like($row->{$key1}, qr/^2010-01-05/); |
|
4667 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
4668 | ||
4669 |
$result = $dbi->select(table => $table1); |
|
4670 |
$result->type_rule( |
|
cleanup
|
4671 |
from1 => [$date_datatype => undef] |
cleanup test
|
4672 |
); |
4673 |
$row = $result->one; |
|
4674 |
like($row->{$key1}, qr/^2010-01-03/); |
|
4675 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
cleanup test
|
4676 | |
4677 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
4678 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4679 |
$dbi->execute($create_table1_type); |
cleanup
|
4680 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4681 |
$dbi->type_rule( |
cleanup
|
4682 |
from1 => { |
4683 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }, |
|
4684 |
}, |
|
cleanup test
|
4685 |
); |
cleanup test
|
4686 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
4687 |
$result = $dbi->select(table => $table1); |
|
4688 |
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }); |
|
4689 |
like($result->one->{$key1}, qr/^2010-01-05/); |
|
cleanup test
|
4690 | |
cleanup test
|
4691 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
4692 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4693 |
$dbi->execute($create_table1_type); |
cleanup
|
4694 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4695 |
$dbi->type_rule( |
cleanup
|
4696 |
from1 => { |
4697 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4698 |
}, |
|
cleanup test
|
4699 |
); |
4700 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
4701 |
$result = $dbi->select(table => $table1); |
|
4702 |
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }); |
|
4703 |
like($result->fetch->[0], qr/^2010-01-05/); |
|
test cleanup
|
4704 | |
cleanup test
|
4705 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
4706 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4707 |
$dbi->execute($create_table1_type); |
cleanup
|
4708 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4709 |
$dbi->type_rule( |
cleanup
|
4710 |
into1 => { |
4711 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4712 |
}, |
|
4713 |
into2 => { |
|
4714 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4715 |
}, |
|
4716 |
from1 => { |
|
4717 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v } |
|
4718 |
}, |
|
4719 |
from2 => { |
|
4720 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v } |
|
4721 |
} |
|
cleanup test
|
4722 |
); |
4723 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1); |
|
4724 |
$result = $dbi->select(table => $table1); |
|
- renamed DBIx::Custom::Resu...
|
4725 |
like($result->type_rule_off->fetch_one->[0], qr/^2010-01-03/); |
cleanup test
|
4726 |
$result = $dbi->select(table => $table1); |
- renamed DBIx::Custom::Resu...
|
4727 |
like($result->type_rule_on->fetch_one->[0], qr/^2010-01-07/); |
test cleanup
|
4728 | |
cleanup test
|
4729 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
4730 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4731 |
$dbi->execute($create_table1_type); |
cleanup
|
4732 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4733 |
$dbi->type_rule( |
cleanup
|
4734 |
into1 => { |
4735 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4736 |
}, |
|
4737 |
into2 => { |
|
4738 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4739 |
}, |
|
4740 |
from1 => { |
|
4741 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v } |
|
4742 |
}, |
|
4743 |
from2 => { |
|
4744 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v } |
|
4745 |
} |
|
cleanup test
|
4746 |
); |
4747 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1); |
|
4748 |
$result = $dbi->select(table => $table1); |
|
- renamed DBIx::Custom::Resu...
|
4749 |
like($result->type_rule1_off->fetch_one->[0], qr/^2010-01-05/); |
cleanup test
|
4750 |
$result = $dbi->select(table => $table1); |
- renamed DBIx::Custom::Resu...
|
4751 |
like($result->type_rule1_on->fetch_one->[0], qr/^2010-01-07/); |
test cleanup
|
4752 | |
cleanup test
|
4753 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
4754 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
4755 |
$dbi->execute($create_table1_type); |
cleanup
|
4756 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
4757 |
$dbi->type_rule( |
cleanup
|
4758 |
into1 => { |
4759 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4760 |
}, |
|
4761 |
into2 => { |
|
4762 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4763 |
}, |
|
4764 |
from1 => { |
|
4765 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v } |
|
4766 |
}, |
|
4767 |
from2 => { |
|
4768 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v } |
|
4769 |
} |
|
cleanup test
|
4770 |
); |
4771 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1); |
|
4772 |
$result = $dbi->select(table => $table1); |
|
- renamed DBIx::Custom::Resu...
|
4773 |
like($result->type_rule2_off->fetch_one->[0], qr/^2010-01-06/); |
cleanup test
|
4774 |
$result = $dbi->select(table => $table1); |
- renamed DBIx::Custom::Resu...
|
4775 |
like($result->type_rule2_on->fetch_one->[0], qr/^2010-01-07/); |
test cleanup
|
4776 | |
added memory leak check test
|
4777 |
test 'join'; |
4778 |
$dbi = DBIx::Custom->connect; |
|
4779 |
eval { $dbi->execute("drop table $table1") }; |
|
4780 |
$dbi->execute($create_table1); |
|
test cleanup
|
4781 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
4782 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
added memory leak check test
|
4783 |
eval { $dbi->execute("drop table $table2") }; |
4784 |
$dbi->execute($create_table2); |
|
cleanup
|
4785 |
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2); |
added memory leak check test
|
4786 |
eval { $dbi->execute("drop table $table3") }; |
4787 |
$dbi->execute("create table $table3 ($key3 int, $key4 int)"); |
|
cleanup
|
4788 |
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3); |
added memory leak check test
|
4789 |
$rows = $dbi->select( |
cleanup
|
4790 |
table => $table1, |
improved tests
|
4791 |
column => "$table1.$key1 as " . u("${table1}_$key1") . ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3", |
cleanup
|
4792 |
where => {"$table1.$key2" => 2}, |
4793 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1"] |
|
added memory leak check test
|
4794 |
)->all; |
improved tests
|
4795 |
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]); |
added test
|
4796 | |
4797 |
$dbi = DBIx::Custom->connect; |
|
4798 |
eval { $dbi->execute("drop table $table1") }; |
|
4799 |
$dbi->execute($create_table1); |
|
test cleanup
|
4800 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
4801 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
added test
|
4802 |
eval { $dbi->execute("drop table $table2") }; |
4803 |
$dbi->execute($create_table2); |
|
cleanup
|
4804 |
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2); |
added test
|
4805 |
eval { $dbi->execute("drop table $table3") }; |
4806 |
$dbi->execute("create table $table3 ($key3 int, $key4 int)"); |
|
cleanup
|
4807 |
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3); |
added test
|
4808 |
$rows = $dbi->select( |
cleanup
|
4809 |
table => $table1, |
improved tests
|
4810 |
column => "$table1.$key1 as " . u("${table1}_$key1") . ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3", |
cleanup
|
4811 |
where => {"$table1.$key2" => 2}, |
4812 |
join => { |
|
4813 |
clause => "left outer join $table2 on $table1.$key1 = $table2.$key1", |
|
4814 |
table => [$table1, $table2] |
|
4815 |
} |
|
added test
|
4816 |
)->all; |
improved tests
|
4817 |
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]); |
added memory leak check test
|
4818 | |
4819 |
$rows = $dbi->select( |
|
cleanup
|
4820 |
table => $table1, |
4821 |
where => {$key1 => 1}, |
|
4822 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1"] |
|
added memory leak check test
|
4823 |
)->all; |
4824 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
|
4825 | ||
4826 |
$rows = $dbi->select( |
|
cleanup
|
4827 |
table => $table1, |
4828 |
where => {$key1 => 1}, |
|
4829 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1", |
|
4830 |
"left outer join $table3 on $table2.$key3 = $table3.$key3"] |
|
added memory leak check test
|
4831 |
)->all; |
4832 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
|
4833 | ||
4834 |
$rows = $dbi->select( |
|
improved tests
|
4835 |
column => "$table3.$key4 as " . u2("${table3}__$key4"), |
cleanup
|
4836 |
table => $table1, |
4837 |
where => {"$table1.$key1" => 1}, |
|
4838 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1", |
|
4839 |
"left outer join $table3 on $table2.$key3 = $table3.$key3"] |
|
added memory leak check test
|
4840 |
)->all; |
improved tests
|
4841 |
is_deeply($rows, [{u2"${table3}__$key4" => 4}]); |
added memory leak check test
|
4842 | |
4843 |
$rows = $dbi->select( |
|
improved tests
|
4844 |
column => "$table1.$key1 as " . u2("${table1}__$key1"), |
cleanup
|
4845 |
table => $table1, |
4846 |
where => {"$table3.$key4" => 4}, |
|
4847 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1", |
|
4848 |
"left outer join $table3 on $table2.$key3 = $table3.$key3"] |
|
added memory leak check test
|
4849 |
)->all; |
improved tests
|
4850 |
is_deeply($rows, [{u2"${table1}__$key1" => 1}]); |
added memory leak check test
|
4851 | |
4852 |
$dbi = DBIx::Custom->connect; |
|
4853 |
eval { $dbi->execute("drop table $table1") }; |
|
4854 |
$dbi->execute($create_table1); |
|
test cleanup
|
4855 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
added memory leak check test
|
4856 |
eval { $dbi->execute("drop table $table2") }; |
4857 |
$dbi->execute($create_table2); |
|
cleanup
|
4858 |
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2); |
added memory leak check test
|
4859 |
$rows = $dbi->select( |
cleanup
|
4860 |
table => $table1, |
fixed tests for fullqualifie...
|
4861 |
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
|
4862 |
where => {"$table1.$key2" => 2}, |
fixed tests for fullqualifie...
|
4863 |
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
|
4864 |
)->all; |
fixed tests for fullqualifie...
|
4865 |
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], |
cleanup
|
4866 |
'quote'); |
added memory leak check test
|
4867 | |
4868 | ||
4869 |
$dbi = DBIx::Custom->connect; |
|
4870 |
eval { $dbi->execute("drop table $table1") }; |
|
4871 |
$dbi->execute($create_table1); |
|
test cleanup
|
4872 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
added memory leak check test
|
4873 |
$sql = <<"EOS"; |
4874 |
left outer join ( |
|
cleanup
|
4875 |
select * from $table1 t1 |
added t/common-mysql-qualifi...
|
4876 |
where t1.$key2 = ( |
4877 |
select max(t2.$key2) from $table1 t2 |
|
4878 |
where t1.$key1 = t2.$key1 |
|
4879 |
) |
|
added memory leak check test
|
4880 |
) $table3 on $table1.$key1 = $table3.$key1 |
4881 |
EOS |
|
added t/common-mysql-qualifi...
|
4882 |
$sql =~ s/\Q.table3/_table3/g; |
added memory leak check test
|
4883 |
$join = [$sql]; |
4884 |
$rows = $dbi->select( |
|
cleanup
|
4885 |
table => $table1, |
fixed tests for fullqualifie...
|
4886 |
column => u($table3) . ".$key1 as " . u2("${table3}__$key1"), |
cleanup
|
4887 |
join => $join |
added memory leak check test
|
4888 |
)->all; |
fixed tests for fullqualifie...
|
4889 |
is_deeply($rows, [{u2"${table3}__$key1" => 1}]); |
added memory leak check test
|
4890 | |
4891 |
$dbi = DBIx::Custom->connect; |
|
4892 |
eval { $dbi->execute("drop table $table1") }; |
|
4893 |
eval { $dbi->execute("drop table $table2") }; |
|
4894 |
$dbi->execute($create_table1); |
|
4895 |
$dbi->execute($create_table2); |
|
test cleanup
|
4896 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
4897 |
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2); |
4898 |
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2); |
|
added memory leak check test
|
4899 |
$result = $dbi->select( |
cleanup
|
4900 |
table => $table1, |
4901 |
join => [ |
|
4902 |
"left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1" |
|
4903 |
] |
|
added memory leak check test
|
4904 |
); |
4905 |
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]); |
|
4906 |
$result = $dbi->select( |
|
cleanup
|
4907 |
table => $table1, |
4908 |
column => [{$table2 => [$key3]}], |
|
4909 |
join => [ |
|
4910 |
"left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1" |
|
4911 |
] |
|
added memory leak check test
|
4912 |
); |
4913 |
is_deeply($result->all, [{"$table2.$key3" => 4}]); |
|
4914 |
$result = $dbi->select( |
|
cleanup
|
4915 |
table => $table1, |
4916 |
column => [{$table2 => [$key3]}], |
|
4917 |
join => [ |
|
4918 |
"left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'" |
|
4919 |
] |
|
added memory leak check test
|
4920 |
); |
4921 |
is_deeply($result->all, [{"$table2.$key3" => 4}]); |
|
4922 | ||
4923 |
$dbi = DBIx::Custom->connect; |
|
4924 |
eval { $dbi->execute("drop table $table1") }; |
|
4925 |
eval { $dbi->execute("drop table $table2") }; |
|
4926 |
$dbi->execute($create_table1); |
|
4927 |
$dbi->execute($create_table2); |
|
test cleanup
|
4928 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
4929 |
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2); |
4930 |
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2); |
|
added memory leak check test
|
4931 |
$result = $dbi->select( |
cleanup
|
4932 |
table => $table1, |
4933 |
column => [{$table2 => [$key3]}], |
|
4934 |
join => [ |
|
4935 |
{ |
|
4936 |
clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1", |
|
4937 |
table => [$table1, $table2] |
|
4938 |
} |
|
4939 |
] |
|
added memory leak check test
|
4940 |
); |
4941 |
is_deeply($result->all, [{"$table2.$key3" => 4}]); |
|
4942 | ||
improved join clause parsing
|
4943 |
$dbi = DBIx::Custom->connect; |
4944 |
eval { $dbi->execute("drop table $table1") }; |
|
4945 |
eval { $dbi->execute("drop table $table2") }; |
|
4946 |
$dbi->execute($create_table1); |
|
4947 |
$dbi->execute($create_table2); |
|
test cleanup
|
4948 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
4949 |
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2); |
4950 |
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2); |
|
improved join clause parsing
|
4951 |
$result = $dbi->select( |
cleanup
|
4952 |
table => $table1, |
4953 |
column => [{$table2 => [$key3]}], |
|
4954 |
join => [ |
|
4955 |
"left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'" |
|
4956 |
] |
|
improved join clause parsing
|
4957 |
); |
4958 |
is_deeply($result->all, [{"$table2.$key3" => 4}]); |
|
4959 | ||
4960 |
$dbi = DBIx::Custom->connect; |
|
4961 |
eval { $dbi->execute("drop table $table1") }; |
|
4962 |
eval { $dbi->execute("drop table $table2") }; |
|
4963 |
$dbi->execute($create_table1); |
|
4964 |
$dbi->execute($create_table2); |
|
test cleanup
|
4965 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
4966 |
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2); |
4967 |
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2); |
|
improved join clause parsing
|
4968 |
$result = $dbi->select( |
cleanup
|
4969 |
table => $table1, |
4970 |
column => [{$table2 => [$key3]}], |
|
4971 |
join => [ |
|
4972 |
"left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1" |
|
4973 |
] |
|
improved join clause parsing
|
4974 |
); |
4975 |
is_deeply($result->all, [{"$table2.$key3" => 4}]); |
|
4976 | ||
added memory leak check test
|
4977 |
test 'columns'; |
4978 |
$dbi = MyDBI1->connect; |
|
4979 |
$model = $dbi->model($table1); |
|
4980 | ||
- added EXPERIMENTAL DBIx::C...
|
4981 |
test 'count'; |
4982 |
$dbi = DBIx::Custom->connect; |
|
4983 |
eval { $dbi->execute("drop table $table1") }; |
|
4984 |
$dbi->execute($create_table1); |
|
test cleanup
|
4985 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
cleanup
|
4986 |
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1); |
- added EXPERIMENTAL DBIx::C...
|
4987 |
is($dbi->count(table => $table1), 2); |
4988 |
is($dbi->count(table => $table1, where => {$key2 => 2}), 1); |
|
4989 |
$model = $dbi->create_model(table => $table1); |
|
4990 |
is($model->count, 2); |
|
cleanup test
|
4991 | |
- fixed bug that DBIx::Custo...
|
4992 |
eval { $dbi->execute("drop table $table1") }; |
4993 |
eval { $dbi->execute("drop table $table2") }; |
|
4994 |
$dbi->execute($create_table1); |
|
4995 |
$dbi->execute($create_table2); |
|
4996 |
$model = $dbi->create_model(table => $table1, primary_key => $key1); |
|
4997 |
$model->insert({$key1 => 1, $key2 => 2}); |
|
4998 |
$model = $dbi->create_model(table => $table2, primary_key => $key1, |
|
cleanup
|
4999 |
join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]); |
- fixed bug that DBIx::Custo...
|
5000 |
$model->insert({$key1 => 1, $key3 => 3}); |
5001 |
is($model->count(id => 1), 1); |
|
5002 |
is($model->count(where => {"$table2.$key3" => 3}), 1); |
|
5003 | ||
fixed documentation miss abo...
|
5004 |
test 'table_alias option'; |
5005 |
$dbi = DBIx::Custom->connect; |
|
5006 |
eval { $dbi->execute("drop table $table1") }; |
|
5007 |
$dbi->execute($create_table1_type); |
|
5008 |
$dbi->insert({$key1 => '2010-01-01'}, table => $table1); |
|
5009 |
$dbi->user_column_info($user_column_info); |
|
5010 |
$dbi->type_rule( |
|
5011 |
into1 => { |
|
5012 |
$date_typename => sub { '2010-' . $_[0] } |
|
5013 |
} |
|
5014 |
); |
|
5015 |
$result = $dbi->execute( |
|
5016 |
"select * from $table1 TABLE1_ALIAS where :TABLE1_ALIAS.${key1}{=}", |
|
5017 |
{"TABLE1_ALIAS.${key1}" => '01-01'}, |
|
5018 |
table_alias => {TABLE1_ALIAS => $table1} |
|
5019 |
); |
|
5020 |
like($result->one->{$key1}, qr/^2010-01-01/); |
|
5021 | ||
5022 |
$dbi = DBIx::Custom->connect; |
|
5023 |
eval { $dbi->execute("drop table $table1") }; |
|
5024 |
$dbi->execute($create_table1_type); |
|
5025 |
$dbi->insert({$key1 => '2010-01-01'}, table => $table1); |
|
5026 |
$dbi->user_column_info($user_column_info); |
|
5027 |
$dbi->type_rule( |
|
5028 |
into2 => { |
|
5029 |
$date_typename => sub { '2010-' . $_[0] } |
|
5030 |
} |
|
5031 |
); |
|
5032 |
$result = $dbi->execute( |
|
5033 |
"select * from $table1 TABLE1_ALIAS where :TABLE1_ALIAS.${key1}{=}", |
|
5034 |
{"TABLE1_ALIAS.${key1}" => '01-01'}, |
|
5035 |
table_alias => {TABLE1_ALIAS => $table1} |
|
5036 |
); |
|
5037 |
like($result->one->{$key1}, qr/^2010-01-01/); |
|
5038 | ||
cleanup test
|
5039 |
1; |