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