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