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