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; |
6 |
use lib "$FindBin::Bin/common"; |
|
cleanup
|
7 |
use Scalar::Util 'isweak'; |
cleanup test
|
8 | |
added common test executing ...
|
9 |
my $dbi; |
10 | ||
11 |
plan skip_all => $ENV{DBIX_CUSTOM_SKIP_MESSAGE} || 'common.t is always skipped' |
|
12 |
unless $ENV{DBIX_CUSTOM_TEST_RUN} |
|
13 |
&& eval { $dbi = DBIx::Custom->connect; 1 }; |
|
14 | ||
15 |
plan 'no_plan'; |
|
16 | ||
test cleanup
|
17 |
use MyDBI1; |
18 |
{ |
|
19 |
package MyDBI4; |
|
20 | ||
21 |
use strict; |
|
22 |
use warnings; |
|
23 | ||
24 |
use base 'DBIx::Custom'; |
|
25 | ||
26 |
sub connect { |
|
27 |
my $self = shift->SUPER::connect(@_); |
|
28 |
|
|
29 |
$self->include_model( |
|
30 |
MyModel2 => [ |
|
test cleanup
|
31 |
'table1', |
cleanup
|
32 |
{class => 'table2', name => 'table2'} |
test cleanup
|
33 |
] |
34 |
); |
|
35 |
} |
|
36 | ||
37 |
package MyModel2::Base1; |
|
38 | ||
39 |
use strict; |
|
40 |
use warnings; |
|
41 | ||
42 |
use base 'DBIx::Custom::Model'; |
|
43 | ||
test cleanup
|
44 |
package MyModel2::table1; |
test cleanup
|
45 | |
46 |
use strict; |
|
47 |
use warnings; |
|
48 | ||
49 |
use base 'MyModel2::Base1'; |
|
50 | ||
51 |
sub insert { |
|
52 |
my ($self, $param) = @_; |
|
53 |
|
|
54 |
return $self->SUPER::insert(param => $param); |
|
55 |
} |
|
56 | ||
57 |
sub list { shift->select; } |
|
58 | ||
test cleanup
|
59 |
package MyModel2::table2; |
test cleanup
|
60 | |
61 |
use strict; |
|
62 |
use warnings; |
|
63 | ||
64 |
use base 'MyModel2::Base1'; |
|
65 | ||
66 |
sub insert { |
|
67 |
my ($self, $param) = @_; |
|
68 |
|
|
69 |
return $self->SUPER::insert(param => $param); |
|
70 |
} |
|
71 | ||
72 |
sub list { shift->select; } |
|
73 |
} |
|
74 |
{ |
|
75 |
package MyDBI5; |
|
76 | ||
77 |
use strict; |
|
78 |
use warnings; |
|
79 | ||
80 |
use base 'DBIx::Custom'; |
|
81 | ||
82 |
sub connect { |
|
83 |
my $self = shift->SUPER::connect(@_); |
|
84 |
|
|
85 |
$self->include_model('MyModel4'); |
|
86 |
} |
|
87 |
} |
|
88 |
{ |
|
89 |
package MyDBI6; |
|
90 |
|
|
91 |
use base 'DBIx::Custom'; |
|
92 |
|
|
93 |
sub connect { |
|
94 |
my $self = shift->SUPER::connect(@_); |
|
95 |
|
|
96 |
$self->include_model('MyModel5'); |
|
97 |
|
|
98 |
return $self; |
|
99 |
} |
|
100 |
} |
|
101 |
{ |
|
102 |
package MyDBI7; |
|
103 |
|
|
104 |
use base 'DBIx::Custom'; |
|
105 |
|
|
106 |
sub connect { |
|
107 |
my $self = shift->SUPER::connect(@_); |
|
108 |
|
|
109 |
$self->include_model('MyModel6'); |
|
110 |
|
|
111 |
|
|
112 |
return $self; |
|
113 |
} |
|
114 |
} |
|
115 |
{ |
|
116 |
package MyDBI8; |
|
117 |
|
|
118 |
use base 'DBIx::Custom'; |
|
119 |
|
|
120 |
sub connect { |
|
121 |
my $self = shift->SUPER::connect(@_); |
|
122 |
|
|
123 |
$self->include_model('MyModel7'); |
|
124 |
|
|
125 |
return $self; |
|
126 |
} |
|
127 |
} |
|
128 | ||
129 |
{ |
|
130 |
package MyDBI9; |
|
131 |
|
|
132 |
use base 'DBIx::Custom'; |
|
133 |
|
|
134 |
sub connect { |
|
135 |
my $self = shift->SUPER::connect(@_); |
|
136 |
|
|
cleanup test
|
137 |
$self->include_model('MyModel8'); |
test cleanup
|
138 |
|
139 |
return $self; |
|
140 |
} |
|
141 |
} |
|
142 | ||
cleanup test
|
143 |
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/}; |
144 |
sub test { print "# $_[0]\n" } |
|
145 | ||
added common test executing ...
|
146 |
# Constant |
test cleanup in progress
|
147 |
my $table1 = $dbi->table1; |
148 |
my $table2 = $dbi->table2; |
|
149 |
my $table2_alias = $dbi->table2_alias; |
|
150 |
my $table3 = $dbi->table3; |
|
151 |
my $key1 = $dbi->key1; |
|
152 |
my $key2 = $dbi->key2; |
|
153 |
my $key3 = $dbi->key3; |
|
154 |
my $key4 = $dbi->key4; |
|
155 |
my $key5 = $dbi->key5; |
|
156 |
my $key6 = $dbi->key6; |
|
157 |
my $key7 = $dbi->key7; |
|
158 |
my $key8 = $dbi->key8; |
|
159 |
my $key9 = $dbi->key9; |
|
160 |
my $key10 = $dbi->key10; |
|
added common test executing ...
|
161 |
my $create_table1 = $dbi->create_table1; |
cleanup test
|
162 |
my $create_table1_2 = $dbi->create_table1_2; |
test cleanup
|
163 |
my $create_table1_type = $dbi->create_table1_type; |
test cleanup
|
164 |
my $create_table1_highperformance = $dbi->create_table1_highperformance; |
test cleanup
|
165 |
my $create_table2 = $dbi->create_table2; |
test cleanup
|
166 |
my $create_table2_2 = $dbi->create_table2_2; |
167 |
my $create_table3 = $dbi->create_table3; |
|
test cleanup
|
168 |
my $create_table_reserved = $dbi->create_table_reserved; |
cleanup test
|
169 |
my $q = substr($dbi->quote, 0, 1); |
170 |
my $p = substr($dbi->quote, 1, 1) || $q; |
|
test cleanup
|
171 |
my $date_typename = $dbi->date_typename; |
172 |
my $datetime_typename = $dbi->datetime_typename; |
|
173 |
my $date_datatype = $dbi->date_datatype; |
|
174 |
my $datetime_datatype = $dbi->datetime_datatype; |
|
added common test executing ...
|
175 | |
cleanup test
|
176 |
# Variables |
177 |
my $builder; |
|
178 |
my $datas; |
|
179 |
my $sth; |
|
180 |
my $source; |
|
181 |
my @sources; |
|
182 |
my $select_source; |
|
183 |
my $insert_source; |
|
184 |
my $update_source; |
|
185 |
my $param; |
|
186 |
my $params; |
|
187 |
my $sql; |
|
188 |
my $result; |
|
189 |
my $row; |
|
190 |
my @rows; |
|
191 |
my $rows; |
|
192 |
my $query; |
|
193 |
my @queries; |
|
194 |
my $select_query; |
|
195 |
my $insert_query; |
|
196 |
my $update_query; |
|
197 |
my $ret_val; |
|
198 |
my $infos; |
|
added common test executing ...
|
199 |
my $model; |
cleanup test
|
200 |
my $model2; |
201 |
my $where; |
|
202 |
my $update_param; |
|
203 |
my $insert_param; |
|
204 |
my $join; |
|
cleanup test
|
205 |
my $binary; |
added common test executing ...
|
206 | |
added SQL Server test
|
207 | |
added common test executing ...
|
208 |
# Drop table |
test cleanup in progress
|
209 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
210 | |
211 |
test 'type_rule into'; |
|
212 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
213 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
214 |
$dbi->execute($create_table1_type); |
215 |
$dbi->type_rule( |
|
216 |
into1 => { |
|
217 |
$date_typename => sub { '2010-' . $_[0] } |
|
218 |
} |
|
219 |
); |
|
test cleanup in progress
|
220 |
$dbi->insert({$key1 => '01-01'}, table => $table1); |
221 |
$result = $dbi->select(table => $table1); |
|
222 |
like($result->one->{$key1}, qr/^2010-01-01/); |
|
test cleanup
|
223 | |
224 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
225 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
226 |
$dbi->execute($create_table1_type); |
227 |
$dbi->type_rule( |
|
228 |
into1 => [ |
|
229 |
[$date_typename, $datetime_typename] => sub { |
|
230 |
my $value = shift; |
|
231 |
$value =~ s/02/03/g; |
|
232 |
return $value; |
|
233 |
} |
|
234 |
] |
|
235 |
); |
|
test cleanup in progress
|
236 |
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1); |
237 |
$result = $dbi->select(table => $table1); |
|
test cleanup
|
238 |
$row = $result->one; |
test cleanup in progress
|
239 |
like($row->{$key1}, qr/^2010-01-03/); |
240 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
test cleanup
|
241 | |
242 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
243 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
244 |
$dbi->execute($create_table1_type); |
test cleanup in progress
|
245 |
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1); |
test cleanup
|
246 |
$dbi->type_rule( |
247 |
into1 => [ |
|
248 |
[$date_typename, $datetime_typename] => sub { |
|
249 |
my $value = shift; |
|
250 |
$value =~ s/02/03/g; |
|
251 |
return $value; |
|
252 |
} |
|
253 |
] |
|
254 |
); |
|
255 |
$result = $dbi->execute( |
|
test cleanup in progress
|
256 |
"select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2;", |
257 |
param => {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'} |
|
test cleanup
|
258 |
); |
259 |
$row = $result->one; |
|
test cleanup in progress
|
260 |
like($row->{$key1}, qr/^2010-01-03/); |
261 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
test cleanup
|
262 | |
263 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
264 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
265 |
$dbi->execute($create_table1_type); |
test cleanup in progress
|
266 |
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1); |
test cleanup
|
267 |
$dbi->type_rule( |
268 |
into1 => [ |
|
269 |
[$date_typename, $datetime_typename] => sub { |
|
270 |
my $value = shift; |
|
271 |
$value =~ s/02/03/g; |
|
272 |
return $value; |
|
273 |
} |
|
274 |
] |
|
275 |
); |
|
276 |
$result = $dbi->execute( |
|
test cleanup in progress
|
277 |
"select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2;", |
278 |
param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'}, |
|
279 |
table => $table1 |
|
test cleanup
|
280 |
); |
281 |
$row = $result->one; |
|
test cleanup in progress
|
282 |
like($row->{$key1}, qr/^2010-01-03/); |
283 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
|
test cleanup
|
284 | |
285 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
286 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
287 |
$dbi->execute($create_table1_type); |
288 |
$dbi->register_filter(convert => sub { |
|
fixex [] reserved_word_quote...
|
289 |
my $value = shift || ''; |
test cleanup
|
290 |
$value =~ s/02/03/; |
291 |
return $value; |
|
292 |
}); |
|
293 |
$dbi->type_rule( |
|
294 |
from1 => { |
|
295 |
$date_datatype => 'convert', |
|
296 |
}, |
|
297 |
into1 => { |
|
298 |
$date_typename => 'convert', |
|
299 |
} |
|
300 |
); |
|
test cleanup in progress
|
301 |
$dbi->insert({$key1 => '2010-02-02'}, table => $table1); |
302 |
$result = $dbi->select(table => $table1); |
|
fixex [] reserved_word_quote...
|
303 |
like($result->fetch->[0], qr/^2010-03-03/); |
test cleanup
|
304 | |
test cleanup
|
305 |
test 'type_rule and filter order'; |
306 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
307 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
308 |
$dbi->execute($create_table1_type); |
309 |
$dbi->type_rule( |
|
310 |
into1 => { |
|
fixex [] reserved_word_quote...
|
311 |
$date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
test cleanup
|
312 |
}, |
313 |
into2 => { |
|
fixex [] reserved_word_quote...
|
314 |
$date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v } |
test cleanup
|
315 |
}, |
316 |
from1 => { |
|
fixex [] reserved_word_quote...
|
317 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v } |
test cleanup
|
318 |
}, |
319 |
from2 => { |
|
fixex [] reserved_word_quote...
|
320 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v } |
test cleanup
|
321 |
} |
322 |
); |
|
test cleanup in progress
|
323 |
$dbi->insert({$key1 => '2010-01-03'}, |
324 |
table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }}); |
|
325 |
$result = $dbi->select(table => $table1); |
|
326 |
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v }); |
|
fixex [] reserved_word_quote...
|
327 |
like($result->fetch_first->[0], qr/^2010-01-09/); |
test cleanup
|
328 | |
329 | ||
test cleanup
|
330 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
331 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
332 |
$dbi->execute($create_table1_type); |
333 |
$dbi->type_rule( |
|
334 |
from1 => { |
|
fixex [] reserved_word_quote...
|
335 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
test cleanup
|
336 |
}, |
337 |
from2 => { |
|
fixex [] reserved_word_quote...
|
338 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
test cleanup
|
339 |
}, |
340 |
); |
|
test cleanup in progress
|
341 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
342 |
$result = $dbi->select(table => $table1); |
|
test cleanup
|
343 |
$result->type_rule( |
344 |
from1 => { |
|
fixex [] reserved_word_quote...
|
345 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v } |
test cleanup
|
346 |
}, |
347 |
from2 => { |
|
fixex [] reserved_word_quote...
|
348 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v } |
test cleanup
|
349 |
} |
350 |
); |
|
test cleanup in progress
|
351 |
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v }); |
fixex [] reserved_word_quote...
|
352 |
like($result->fetch_first->[0], qr/^2010-01-09/); |
test cleanup
|
353 | |
test cleanup
|
354 |
test 'type_rule_off'; |
355 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
356 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
357 |
$dbi->execute($create_table1_type); |
358 |
$dbi->type_rule( |
|
359 |
from1 => { |
|
fixex [] reserved_word_quote...
|
360 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
test cleanup
|
361 |
}, |
362 |
into1 => { |
|
fixex [] reserved_word_quote...
|
363 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
test cleanup
|
364 |
} |
365 |
); |
|
test cleanup in progress
|
366 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1); |
367 |
$result = $dbi->select(table => $table1, type_rule_off => 1); |
|
fixex [] reserved_word_quote...
|
368 |
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/); |
test cleanup
|
369 | |
test cleanup
|
370 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
371 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
372 |
$dbi->execute($create_table1_type); |
373 |
$dbi->type_rule( |
|
374 |
from1 => { |
|
fixex [] reserved_word_quote...
|
375 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
test cleanup
|
376 |
}, |
377 |
into1 => { |
|
fixex [] reserved_word_quote...
|
378 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
test cleanup
|
379 |
} |
380 |
); |
|
test cleanup in progress
|
381 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1); |
382 |
$result = $dbi->select(table => $table1, type_rule_off => 1); |
|
383 |
like($result->one->{$key1}, qr/^2010-01-04/); |
|
test cleanup
|
384 | |
test cleanup
|
385 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
386 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
387 |
$dbi->execute($create_table1_type); |
388 |
$dbi->type_rule( |
|
389 |
from1 => { |
|
fixex [] reserved_word_quote...
|
390 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
test cleanup
|
391 |
}, |
392 |
into1 => { |
|
fixex [] reserved_word_quote...
|
393 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
test cleanup
|
394 |
} |
395 |
); |
|
test cleanup in progress
|
396 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
397 |
$result = $dbi->select(table => $table1); |
|
398 |
like($result->one->{$key1}, qr/^2010-01-05/); |
|
test cleanup
|
399 | |
test cleanup
|
400 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
401 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
402 |
$dbi->execute($create_table1_type); |
403 |
$dbi->type_rule( |
|
404 |
from1 => { |
|
fixex [] reserved_word_quote...
|
405 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
test cleanup
|
406 |
}, |
407 |
into1 => { |
|
fixex [] reserved_word_quote...
|
408 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
test cleanup
|
409 |
} |
410 |
); |
|
test cleanup in progress
|
411 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
412 |
$result = $dbi->select(table => $table1); |
|
fixex [] reserved_word_quote...
|
413 |
like($result->fetch->[0], qr/2010-01-05/); |
test cleanup
|
414 | |
test cleanup
|
415 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
416 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
417 |
$dbi->execute($create_table1_type); |
fixex [] reserved_word_quote...
|
418 |
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }); |
test cleanup
|
419 |
$dbi->type_rule( |
420 |
into1 => { |
|
421 |
$date_typename => 'ppp' |
|
422 |
} |
|
423 |
); |
|
test cleanup in progress
|
424 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
425 |
$result = $dbi->select(table => $table1); |
|
426 |
like($result->one->{$key1}, qr/^2010-01-04/); |
|
test cleanup
|
427 | |
test cleanup
|
428 |
eval{$dbi->type_rule( |
429 |
into1 => { |
|
430 |
$date_typename => 'pp' |
|
431 |
} |
|
432 |
)}; |
|
433 |
like($@, qr/not registered/); |
|
test cleanup
|
434 | |
test cleanup
|
435 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
436 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
437 |
$dbi->execute($create_table1_type); |
438 |
eval { |
|
439 |
$dbi->type_rule( |
|
440 |
from1 => { |
|
441 |
Date => sub { $_[0] * 2 }, |
|
442 |
} |
|
443 |
); |
|
444 |
}; |
|
445 |
like($@, qr/lower/); |
|
test cleanup
|
446 | |
test cleanup
|
447 |
eval { |
448 |
$dbi->type_rule( |
|
449 |
into1 => { |
|
450 |
Date => sub { $_[0] * 2 }, |
|
451 |
} |
|
452 |
); |
|
453 |
}; |
|
454 |
like($@, qr/lower/); |
|
test cleanup
|
455 | |
test cleanup
|
456 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
457 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
458 |
$dbi->execute($create_table1_type); |
459 |
$dbi->type_rule( |
|
460 |
from1 => { |
|
fixex [] reserved_word_quote...
|
461 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
test cleanup
|
462 |
}, |
463 |
into1 => { |
|
fixex [] reserved_word_quote...
|
464 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
test cleanup
|
465 |
} |
466 |
); |
|
test cleanup in progress
|
467 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
468 |
$result = $dbi->select(table => $table1); |
|
test cleanup
|
469 |
$result->type_rule_off; |
test cleanup in progress
|
470 |
like($result->one->{$key1}, qr/^2010-01-04/); |
test cleanup
|
471 | |
test cleanup
|
472 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
473 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
474 |
$dbi->execute($create_table1_type); |
475 |
$dbi->type_rule( |
|
476 |
from1 => { |
|
fixex [] reserved_word_quote...
|
477 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }, |
478 |
$datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
test cleanup
|
479 |
}, |
480 |
); |
|
test cleanup in progress
|
481 |
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1); |
482 |
$result = $dbi->select(table => $table1); |
|
test cleanup
|
483 |
$result->type_rule( |
484 |
from1 => { |
|
fixex [] reserved_word_quote...
|
485 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
test cleanup
|
486 |
} |
487 |
); |
|
488 |
$row = $result->one; |
|
test cleanup in progress
|
489 |
like($row->{$key1}, qr/^2010-01-05/); |
490 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
test cleanup
|
491 | |
test cleanup in progress
|
492 |
$result = $dbi->select(table => $table1); |
test cleanup
|
493 |
$result->type_rule( |
494 |
from1 => { |
|
fixex [] reserved_word_quote...
|
495 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
test cleanup
|
496 |
} |
497 |
); |
|
498 |
$row = $result->one; |
|
test cleanup in progress
|
499 |
like($row->{$key1}, qr/2010-01-05/); |
500 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
|
test cleanup
|
501 | |
test cleanup in progress
|
502 |
$result = $dbi->select(table => $table1); |
test cleanup
|
503 |
$result->type_rule( |
504 |
from1 => { |
|
fixex [] reserved_word_quote...
|
505 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
test cleanup
|
506 |
} |
507 |
); |
|
508 |
$row = $result->one; |
|
test cleanup in progress
|
509 |
like($row->{$key1}, qr/2010-01-05/); |
510 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
|
test cleanup
|
511 | |
test cleanup in progress
|
512 |
$result = $dbi->select(table => $table1); |
test cleanup
|
513 |
$result->type_rule( |
fixex [] reserved_word_quote...
|
514 |
from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }] |
test cleanup
|
515 |
); |
516 |
$row = $result->one; |
|
test cleanup in progress
|
517 |
like($row->{$key1}, qr/2010-01-05/); |
518 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
|
test cleanup
|
519 | |
fixex [] reserved_word_quote...
|
520 |
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }); |
test cleanup in progress
|
521 |
$result = $dbi->select(table => $table1); |
test cleanup
|
522 |
$result->type_rule( |
523 |
from1 => [$date_datatype => 'five'] |
|
524 |
); |
|
525 |
$row = $result->one; |
|
test cleanup in progress
|
526 |
like($row->{$key1}, qr/^2010-01-05/); |
527 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
test cleanup
|
528 | |
test cleanup in progress
|
529 |
$result = $dbi->select(table => $table1); |
test cleanup
|
530 |
$result->type_rule( |
531 |
from1 => [$date_datatype => undef] |
|
532 |
); |
|
533 |
$row = $result->one; |
|
test cleanup in progress
|
534 |
like($row->{$key1}, qr/^2010-01-03/); |
535 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
test cleanup
|
536 | |
test cleanup
|
537 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
538 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
539 |
$dbi->execute($create_table1_type); |
540 |
$dbi->type_rule( |
|
541 |
from1 => { |
|
fixex [] reserved_word_quote...
|
542 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }, |
test cleanup
|
543 |
}, |
544 |
); |
|
test cleanup in progress
|
545 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
546 |
$result = $dbi->select(table => $table1); |
|
547 |
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }); |
|
548 |
like($result->one->{$key1}, qr/^2010-01-05/); |
|
test cleanup
|
549 | |
test cleanup
|
550 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
551 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
552 |
$dbi->execute($create_table1_type); |
553 |
$dbi->type_rule( |
|
554 |
from1 => { |
|
fixex [] reserved_word_quote...
|
555 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
test cleanup
|
556 |
}, |
557 |
); |
|
test cleanup in progress
|
558 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
559 |
$result = $dbi->select(table => $table1); |
|
560 |
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }); |
|
fixex [] reserved_word_quote...
|
561 |
like($result->fetch->[0], qr/^2010-01-05/); |
test cleanup
|
562 | |
test cleanup
|
563 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
564 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
565 |
$dbi->execute($create_table1_type); |
566 |
$dbi->type_rule( |
|
567 |
into1 => { |
|
fixex [] reserved_word_quote...
|
568 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
test cleanup
|
569 |
}, |
570 |
into2 => { |
|
fixex [] reserved_word_quote...
|
571 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
test cleanup
|
572 |
}, |
573 |
from1 => { |
|
fixex [] reserved_word_quote...
|
574 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v } |
test cleanup
|
575 |
}, |
576 |
from2 => { |
|
fixex [] reserved_word_quote...
|
577 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v } |
test cleanup
|
578 |
} |
579 |
); |
|
test cleanup in progress
|
580 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1); |
581 |
$result = $dbi->select(table => $table1); |
|
fixex [] reserved_word_quote...
|
582 |
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/); |
test cleanup in progress
|
583 |
$result = $dbi->select(table => $table1); |
fixex [] reserved_word_quote...
|
584 |
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/); |
test cleanup
|
585 | |
test cleanup
|
586 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
587 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
588 |
$dbi->execute($create_table1_type); |
589 |
$dbi->type_rule( |
|
590 |
into1 => { |
|
fixex [] reserved_word_quote...
|
591 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
test cleanup
|
592 |
}, |
593 |
into2 => { |
|
fixex [] reserved_word_quote...
|
594 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
test cleanup
|
595 |
}, |
596 |
from1 => { |
|
fixex [] reserved_word_quote...
|
597 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v } |
test cleanup
|
598 |
}, |
599 |
from2 => { |
|
fixex [] reserved_word_quote...
|
600 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v } |
test cleanup
|
601 |
} |
602 |
); |
|
test cleanup in progress
|
603 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1); |
604 |
$result = $dbi->select(table => $table1); |
|
fixex [] reserved_word_quote...
|
605 |
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/); |
test cleanup in progress
|
606 |
$result = $dbi->select(table => $table1); |
fixex [] reserved_word_quote...
|
607 |
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/); |
test cleanup
|
608 | |
test cleanup
|
609 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
610 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
611 |
$dbi->execute($create_table1_type); |
612 |
$dbi->type_rule( |
|
613 |
into1 => { |
|
fixex [] reserved_word_quote...
|
614 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
test cleanup
|
615 |
}, |
616 |
into2 => { |
|
fixex [] reserved_word_quote...
|
617 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
test cleanup
|
618 |
}, |
619 |
from1 => { |
|
fixex [] reserved_word_quote...
|
620 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v } |
test cleanup
|
621 |
}, |
622 |
from2 => { |
|
fixex [] reserved_word_quote...
|
623 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v } |
test cleanup
|
624 |
} |
625 |
); |
|
test cleanup in progress
|
626 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1); |
627 |
$result = $dbi->select(table => $table1); |
|
fixex [] reserved_word_quote...
|
628 |
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/); |
test cleanup in progress
|
629 |
$result = $dbi->select(table => $table1); |
fixex [] reserved_word_quote...
|
630 |
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/); |
test cleanup
|
631 | |
632 | ||
added common test executing ...
|
633 | |
634 |
# Create table |
|
test cleanup
|
635 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
636 |
eval { $dbi->execute('drop table $table1') }; |
added common test executing ...
|
637 |
$dbi->execute($create_table1); |
test cleanup in progress
|
638 |
$model = $dbi->create_model(table => $table1); |
639 |
$model->insert({$key1 => 1, $key2 => 2}); |
|
640 |
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]); |
|
added common test executing ...
|
641 | |
cleanup test
|
642 |
test 'DBIx::Custom::Result test'; |
test cleanup in progress
|
643 |
$dbi->delete_all(table => $table1); |
644 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
|
645 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
|
646 |
$source = "select $key1, $key2 from $table1"; |
|
cleanup test
|
647 |
$query = $dbi->create_query($source); |
648 |
$result = $dbi->execute($query); |
|
649 | ||
650 |
@rows = (); |
|
651 |
while (my $row = $result->fetch) { |
|
652 |
push @rows, [@$row]; |
|
653 |
} |
|
654 |
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch"); |
|
655 | ||
656 |
$result = $dbi->execute($query); |
|
657 |
@rows = (); |
|
658 |
while (my $row = $result->fetch_hash) { |
|
659 |
push @rows, {%$row}; |
|
660 |
} |
|
test cleanup in progress
|
661 |
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash"); |
cleanup test
|
662 | |
663 |
$result = $dbi->execute($query); |
|
664 |
$rows = $result->fetch_all; |
|
665 |
is_deeply($rows, [[1, 2], [3, 4]], "fetch_all"); |
|
666 | ||
667 |
$result = $dbi->execute($query); |
|
668 |
$rows = $result->fetch_hash_all; |
|
test cleanup in progress
|
669 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "all"); |
cleanup test
|
670 | |
671 |
test 'Insert query return value'; |
|
test cleanup in progress
|
672 |
$source = "insert into $table1 {insert_param $key1 $key2}"; |
cleanup test
|
673 |
$query = $dbi->execute($source, {}, query => 1); |
test cleanup in progress
|
674 |
$ret_val = $dbi->execute($query, param => {$key1 => 1, $key2 => 2}); |
cleanup test
|
675 |
ok($ret_val); |
676 | ||
677 |
test 'Direct query'; |
|
test cleanup in progress
|
678 |
$dbi->delete_all(table => $table1); |
679 |
$insert_source = "insert into $table1 {insert_param $key1 $key2}"; |
|
680 |
$dbi->execute($insert_source, param => {$key1 => 1, $key2 => 2}); |
|
681 |
$result = $dbi->execute("select * from $table1;"); |
|
cleanup test
|
682 |
$rows = $result->all; |
test cleanup in progress
|
683 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
cleanup test
|
684 | |
685 |
test 'Filter basic'; |
|
test cleanup in progress
|
686 |
$dbi->delete_all(table => $table1); |
cleanup test
|
687 |
$dbi->register_filter(twice => sub { $_[0] * 2}, |
688 |
three_times => sub { $_[0] * 3}); |
|
689 | ||
test cleanup in progress
|
690 |
$insert_source = "insert into $table1 {insert_param $key1 $key2};"; |
cleanup test
|
691 |
$insert_query = $dbi->execute($insert_source, {}, query => 1); |
test cleanup in progress
|
692 |
$insert_query->filter({$key1 => 'twice'}); |
693 |
$dbi->execute($insert_query, param => {$key1 => 1, $key2 => 2}); |
|
694 |
$result = $dbi->execute("select * from $table1;"); |
|
695 |
$rows = $result->filter({$key2 => 'three_times'})->all; |
|
696 |
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter"); |
|
cleanup test
|
697 | |
698 |
test 'Filter in'; |
|
test cleanup in progress
|
699 |
$dbi->delete_all(table => $table1); |
700 |
$insert_source = "insert into $table1 {insert_param $key1 $key2};"; |
|
cleanup test
|
701 |
$insert_query = $dbi->execute($insert_source, {}, query => 1); |
test cleanup in progress
|
702 |
$dbi->execute($insert_query, param => {$key1 => 2, $key2 => 4}); |
703 |
$select_source = "select * from $table1 where {in $table1.$key1 2} and {in $table1.$key2 2}"; |
|
cleanup test
|
704 |
$select_query = $dbi->execute($select_source,{}, query => 1); |
test cleanup in progress
|
705 |
$select_query->filter({'$table1.$key1' => 'twice'}); |
706 |
$result = $dbi->execute($select_query, param => {"$table1.$key1" => [1,5], "$table1.$key2" => [2,4]}); |
|
cleanup test
|
707 |
$rows = $result->all; |
test cleanup in progress
|
708 |
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter"); |
cleanup test
|
709 | |
cleanup test
|
710 |
test 'DBIx::Custom::SQLTemplate basic tag'; |
test cleanup in progress
|
711 |
$dbi->execute('drop table $table1'); |
cleanup test
|
712 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
713 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
714 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
cleanup test
|
715 | |
test cleanup in progress
|
716 |
$source = "select * from $table1 where $key1 = :$key1 and {<> $key2} and {< $key3} and {> $key4} and {>= $key5};"; |
cleanup test
|
717 |
$query = $dbi->execute($source, {}, query => 1); |
test cleanup in progress
|
718 |
$result = $dbi->execute($query, param => {$key1 => 1, $key2 => 3, $key3 => 4, $key4 => 3, $key5 => 5}); |
cleanup test
|
719 |
$rows = $result->all; |
test cleanup in progress
|
720 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}], "basic tag1"); |
cleanup test
|
721 | |
test cleanup in progress
|
722 |
$source = "select * from $table1 where $key1 = :$key1 and {<> $key2} and {< $key3} and {> $key4} and {>= $key5};"; |
cleanup test
|
723 |
$query = $dbi->execute($source, {}, query => 1); |
test cleanup in progress
|
724 |
$result = $dbi->execute($query, {$key1 => 1, $key2 => 3, $key3 => 4, $key4 => 3, $key5 => 5}); |
cleanup test
|
725 |
$rows = $result->all; |
test cleanup in progress
|
726 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}], "basic tag1"); |
cleanup test
|
727 | |
test cleanup in progress
|
728 |
$source = "select * from $table1 where {<= $key1} and {like $key2};"; |
cleanup test
|
729 |
$query = $dbi->execute($source, {}, query => 1); |
test cleanup in progress
|
730 |
$result = $dbi->execute($query, param => {$key1 => 1, $key2 => '%2%'}); |
cleanup test
|
731 |
$rows = $result->all; |
test cleanup in progress
|
732 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}], "basic tag2"); |
cleanup test
|
733 | |
734 |
test 'DIB::Custom::SQLTemplate in tag'; |
|
test cleanup in progress
|
735 |
$dbi->execute('drop table $table1'); |
cleanup test
|
736 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
737 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
738 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
cleanup test
|
739 | |
test cleanup in progress
|
740 |
$source = "select * from $table1 where {in $key1 2};"; |
cleanup test
|
741 |
$query = $dbi->execute($source, {}, query => 1); |
test cleanup in progress
|
742 |
$result = $dbi->execute($query, param => {$key1 => [9, 1]}); |
cleanup test
|
743 |
$rows = $result->all; |
test cleanup in progress
|
744 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}], "basic"); |
cleanup test
|
745 | |
746 |
test 'DBIx::Custom::SQLTemplate insert tag'; |
|
test cleanup in progress
|
747 |
$dbi->delete_all(table => $table1); |
748 |
$insert_source = "insert into $table1 {insert_param $key1 $key2 $key3 $key4 $key5}"; |
|
749 |
$dbi->execute($insert_source, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
|
cleanup test
|
750 | |
test cleanup in progress
|
751 |
$result = $dbi->execute("select * from $table1;"); |
cleanup test
|
752 |
$rows = $result->all; |
test cleanup in progress
|
753 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}], "basic"); |
cleanup test
|
754 | |
755 |
test 'DBIx::Custom::SQLTemplate update tag'; |
|
test cleanup in progress
|
756 |
$dbi->delete_all(table => $table1); |
757 |
$insert_source = "insert into $table1 {insert_param $key1 $key2 $key3 $key4 $key5}"; |
|
758 |
$dbi->execute($insert_source, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
|
759 |
$dbi->execute($insert_source, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
cleanup test
|
760 | |
test cleanup in progress
|
761 |
$update_source = "update $table1 {update_param $key1 $key2 $key3 $key4} where {= $key5}"; |
762 |
$dbi->execute($update_source, param => {$key1 => 1, $key2 => 1, $key3 => 1, $key4 => 1, $key5 => 5}); |
|
cleanup test
|
763 | |
test cleanup in progress
|
764 |
$result = $dbi->execute("select * from $table1 order by $key1;"); |
cleanup test
|
765 |
$rows = $result->all; |
test cleanup in progress
|
766 |
is_deeply($rows, [{$key1 => 1, $key2 => 1, $key3 => 1, $key4 => 1, $key5 => 5}, |
767 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], "basic"); |
|
cleanup test
|
768 | |
cleanup test
|
769 |
test 'Named placeholder'; |
test cleanup in progress
|
770 |
$dbi->execute('drop table $table1'); |
cleanup test
|
771 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
772 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
773 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
cleanup test
|
774 | |
test cleanup in progress
|
775 |
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2"; |
776 |
$result = $dbi->execute($source, param => {$key1 => 1, $key2 => 2}); |
|
cleanup test
|
777 |
$rows = $result->all; |
test cleanup in progress
|
778 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]); |
cleanup test
|
779 | |
test cleanup in progress
|
780 |
$source = "select * from $table1 where $key1 = \n:$key1\n and $key2 = :$key2"; |
781 |
$result = $dbi->execute($source, param => {$key1 => 1, $key2 => 2}); |
|
cleanup test
|
782 |
$rows = $result->all; |
test cleanup in progress
|
783 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]); |
cleanup test
|
784 | |
test cleanup in progress
|
785 |
$source = "select * from $table1 where $key1 = :$key1 or $key1 = :$key1"; |
786 |
$result = $dbi->execute($source, param => {$key1 => [1, 2]}); |
|
cleanup test
|
787 |
$rows = $result->all; |
test cleanup in progress
|
788 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]); |
cleanup test
|
789 | |
test cleanup in progress
|
790 |
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2"; |
cleanup test
|
791 |
$result = $dbi->execute( |
792 |
$source, |
|
test cleanup in progress
|
793 |
param => {"$table1.$key1" => 1, "$table1.$key2" => 1}, |
794 |
filter => {'$table1.$key2' => sub { $_[0] * 2 }} |
|
cleanup test
|
795 |
); |
796 |
$rows = $result->all; |
|
test cleanup in progress
|
797 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]); |
cleanup test
|
798 | |
test cleanup in progress
|
799 |
$dbi->execute('drop table $table1'); |
cleanup test
|
800 |
$dbi->execute($create_table1); |
test cleanup in progress
|
801 |
$dbi->insert(table => $table1, param => {$key1 => '2011-10-14 12:19:18', $key2 => 2}); |
802 |
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2"; |
|
cleanup test
|
803 |
$result = $dbi->execute( |
804 |
$source, |
|
test cleanup in progress
|
805 |
param => {$key2 => 2}, |
cleanup test
|
806 |
); |
807 | ||
808 |
$rows = $result->all; |
|
test cleanup in progress
|
809 |
like($rows->[0]->{$key1}, qr/2011-10-14 12:19:18/); |
810 |
is($rows->[0]->{$key2}, 2); |
|
cleanup test
|
811 | |
test cleanup in progress
|
812 |
$dbi->delete_all(table => $table1); |
813 |
$dbi->insert(table => $table1, param => {$key1 => 'a:b c:d', $key2 => 2}); |
|
814 |
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2"; |
|
cleanup test
|
815 |
$result = $dbi->execute( |
816 |
$source, |
|
test cleanup in progress
|
817 |
param => {$key2 => 2}, |
cleanup test
|
818 |
); |
819 |
$rows = $result->all; |
|
test cleanup in progress
|
820 |
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]); |
cleanup test
|
821 | |
test cleanup
|
822 |
test 'Error case'; |
823 |
eval {DBIx::Custom->connect(dsn => 'dbi:SQLit')}; |
|
824 |
ok($@, "connect error"); |
|
825 | ||
826 |
eval{$dbi->execute("{p }", {}, query => 1)}; |
|
827 |
ok($@, "create_query invalid SQL template"); |
|
added EXPERIMENTAL DBIx::Cus...
|
828 | |
cleanup test
|
829 |
test 'insert'; |
test cleanup in progress
|
830 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
831 |
$dbi->execute($create_table1); |
test cleanup in progress
|
832 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
833 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
|
834 |
$result = $dbi->execute("select * from $table1;"); |
|
cleanup test
|
835 |
$rows = $result->all; |
test cleanup in progress
|
836 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic"); |
cleanup test
|
837 | |
test cleanup in progress
|
838 |
$dbi->execute('delete from $table1'); |
cleanup test
|
839 |
$dbi->register_filter( |
840 |
twice => sub { $_[0] * 2 }, |
|
841 |
three_times => sub { $_[0] * 3 } |
|
842 |
); |
|
843 |
$dbi->default_bind_filter('twice'); |
|
test cleanup in progress
|
844 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => 'three_times'}); |
845 |
$result = $dbi->execute("select * from $table1;"); |
|
cleanup test
|
846 |
$rows = $result->all; |
test cleanup in progress
|
847 |
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter"); |
cleanup test
|
848 |
$dbi->default_bind_filter(undef); |
849 | ||
test cleanup in progress
|
850 |
$dbi->execute('drop table $table1'); |
cleanup test
|
851 |
$dbi->execute($create_table1); |
test cleanup in progress
|
852 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, append => ' '); |
853 |
$rows = $dbi->select(table => $table1)->all; |
|
854 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}], 'insert append'); |
|
cleanup test
|
855 | |
test cleanup in progress
|
856 |
eval{$dbi->insert(table => $table1, noexist => 1)}; |
cleanup test
|
857 |
like($@, qr/noexist/, "invalid"); |
858 | ||
859 |
eval{$dbi->insert(table => 'table', param => {';' => 1})}; |
|
860 |
like($@, qr/safety/); |
|
861 | ||
cleanup test
|
862 |
eval { $dbi->execute("drop table ${q}table$p") }; |
test cleanup
|
863 |
$dbi->execute($create_table_reserved); |
cleanup test
|
864 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
865 |
$dbi->insert(table => 'table', param => {select => 1}); |
|
cleanup test
|
866 |
$result = $dbi->execute("select * from ${q}table$p"); |
cleanup test
|
867 |
$rows = $result->all; |
test cleanup
|
868 |
is_deeply($rows, [{select => 2, update => undef}], "reserved word"); |
cleanup test
|
869 | |
test cleanup in progress
|
870 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
871 |
$dbi->execute($create_table1); |
test cleanup in progress
|
872 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
873 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
874 |
$result = $dbi->execute("select * from $table1;"); |
|
cleanup test
|
875 |
$rows = $result->all; |
test cleanup in progress
|
876 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic"); |
cleanup test
|
877 | |
test cleanup in progress
|
878 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
879 |
$dbi->execute($create_table1); |
test cleanup in progress
|
880 |
$dbi->insert(table => $table1, param => {$key1 => \"'1'", $key2 => 2}); |
881 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
|
882 |
$result = $dbi->execute("select * from $table1;"); |
|
cleanup test
|
883 |
$rows = $result->all; |
test cleanup in progress
|
884 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic"); |
cleanup test
|
885 | |
test cleanup
|
886 |
test 'update'; |
test cleanup in progress
|
887 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
888 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
889 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
890 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
891 |
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1}); |
|
892 |
$result = $dbi->execute("select * from $table1 order by $key1;"); |
|
test cleanup
|
893 |
$rows = $result->all; |
test cleanup in progress
|
894 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
895 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
test cleanup
|
896 |
"basic"); |
897 |
|
|
test cleanup in progress
|
898 |
$dbi->execute("delete from $table1"); |
899 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
|
900 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
901 |
$dbi->update(table => $table1, param => {$key2 => 12}, where => {$key2 => 2, $key3 => 3}); |
|
902 |
$result = $dbi->execute("select * from $table1 order by $key1;"); |
|
test cleanup
|
903 |
$rows = $result->all; |
test cleanup in progress
|
904 |
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5}, |
905 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
test cleanup
|
906 |
"update key same as search key"); |
907 | ||
test cleanup in progress
|
908 |
$dbi->update(table => $table1, param => {$key2 => [12]}, where => {$key2 => 2, $key3 => 3}); |
909 |
$result = $dbi->execute("select * from $table1 order by $key1;"); |
|
test cleanup
|
910 |
$rows = $result->all; |
test cleanup in progress
|
911 |
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5}, |
912 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
test cleanup
|
913 |
"update key same as search key : param is array ref"); |
914 | ||
test cleanup in progress
|
915 |
$dbi->execute("delete from $table1"); |
916 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
|
917 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
test cleanup
|
918 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
test cleanup in progress
|
919 |
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1}, |
920 |
filter => {$key2 => sub { $_[0] * 2 }}); |
|
921 |
$result = $dbi->execute("select * from $table1 order by $key1;"); |
|
test cleanup
|
922 |
$rows = $result->all; |
test cleanup in progress
|
923 |
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5}, |
924 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
test cleanup
|
925 |
"filter"); |
926 | ||
test cleanup in progress
|
927 |
$result = $dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1}, append => ' '); |
test cleanup
|
928 | |
test cleanup in progress
|
929 |
eval{$dbi->update(table => $table1, where => {$key1 => 1}, noexist => 1)}; |
test cleanup
|
930 |
like($@, qr/noexist/, "invalid"); |
931 | ||
test cleanup in progress
|
932 |
eval{$dbi->update(table => $table1)}; |
test cleanup
|
933 |
like($@, qr/where/, "not contain where"); |
934 | ||
test cleanup in progress
|
935 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
936 |
$dbi->execute($create_table1); |
test cleanup in progress
|
937 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
test cleanup
|
938 |
$where = $dbi->where; |
test cleanup in progress
|
939 |
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]); |
940 |
$where->param({$key1 => 1, $key2 => 2}); |
|
941 |
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where); |
|
942 |
$result = $dbi->select(table => $table1); |
|
943 |
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where'); |
|
test cleanup
|
944 | |
test cleanup in progress
|
945 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
946 |
$dbi->execute($create_table1); |
test cleanup in progress
|
947 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
test cleanup
|
948 |
$dbi->update( |
test cleanup in progress
|
949 |
table => $table1, |
950 |
param => {$key1 => 3}, |
|
test cleanup
|
951 |
where => [ |
test cleanup in progress
|
952 |
['and', "$key1 = :$key1", "$key2 = :$key2"], |
953 |
{$key1 => 1, $key2 => 2} |
|
test cleanup
|
954 |
] |
955 |
); |
|
test cleanup in progress
|
956 |
$result = $dbi->select(table => $table1); |
957 |
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where'); |
|
test cleanup
|
958 | |
test cleanup in progress
|
959 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
960 |
$dbi->execute($create_table1); |
test cleanup in progress
|
961 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
test cleanup
|
962 |
$where = $dbi->where; |
test cleanup in progress
|
963 |
$where->clause(['and', "$key2 = :$key2"]); |
964 |
$where->param({$key2 => 2}); |
|
965 |
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where); |
|
966 |
$result = $dbi->select(table => $table1); |
|
967 |
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where'); |
|
test cleanup
|
968 | |
test cleanup in progress
|
969 |
eval{$dbi->update(table => $table1, param => {';' => 1})}; |
test cleanup
|
970 |
like($@, qr/safety/); |
971 | ||
test cleanup in progress
|
972 |
eval{$dbi->update(table => $table1, param => {$key1 => 1}, where => {';' => 1})}; |
test cleanup
|
973 |
like($@, qr/safety/); |
974 | ||
test cleanup in progress
|
975 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
976 |
eval { $dbi->execute("drop table ${q}table$p") }; |
test cleanup
|
977 |
$dbi->execute($create_table_reserved); |
test cleanup
|
978 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
979 |
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}}); |
|
980 |
$dbi->insert(table => 'table', param => {select => 1}); |
|
981 |
$dbi->update(table => 'table', where => {select => 1}, param => {update => 2}); |
|
982 |
$result = $dbi->execute("select * from ${q}table$p"); |
|
983 |
$rows = $result->all; |
|
984 |
is_deeply($rows, [{select => 2, update => 6}], "reserved word"); |
|
985 | ||
986 |
eval {$dbi->update_all(table => 'table', param => {';' => 2}) }; |
|
987 |
like($@, qr/safety/); |
|
988 | ||
989 |
eval { $dbi->execute("drop table ${q}table$p") }; |
|
test cleanup
|
990 |
$dbi->execute($create_table_reserved); |
test cleanup
|
991 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
992 |
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}}); |
|
993 |
$dbi->insert(table => 'table', param => {select => 1}); |
|
994 |
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2}); |
|
995 |
$result = $dbi->execute("select * from ${q}table$p"); |
|
996 |
$rows = $result->all; |
|
997 |
is_deeply($rows, [{select => 2, update => 6}], "reserved word"); |
|
998 | ||
test cleanup in progress
|
999 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1000 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
1001 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
1002 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
1003 |
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1}); |
|
1004 |
$result = $dbi->execute("select * from $table1 order by $key1;"); |
|
test cleanup
|
1005 |
$rows = $result->all; |
test cleanup in progress
|
1006 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
1007 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
test cleanup
|
1008 |
"basic"); |
1009 | ||
test cleanup in progress
|
1010 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1011 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
1012 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
1013 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
1014 |
$dbi->update(table => $table1, param => {$key2 => \"'11'"}, where => {$key1 => 1}); |
|
1015 |
$result = $dbi->execute("select * from $table1 order by $key1;"); |
|
test cleanup
|
1016 |
$rows = $result->all; |
test cleanup in progress
|
1017 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
1018 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
test cleanup
|
1019 |
"basic"); |
1020 | ||
1021 |
test 'update_all'; |
|
test cleanup in progress
|
1022 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1023 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
1024 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
1025 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
test cleanup
|
1026 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
test cleanup in progress
|
1027 |
$dbi->update_all(table => $table1, param => {$key2 => 10}, filter => {$key2 => 'twice'}); |
1028 |
$result = $dbi->execute("select * from $table1;"); |
|
test cleanup
|
1029 |
$rows = $result->all; |
test cleanup in progress
|
1030 |
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5}, |
1031 |
{$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
test cleanup
|
1032 |
"filter"); |
1033 | ||
1034 | ||
1035 |
test 'delete'; |
|
test cleanup in progress
|
1036 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1037 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1038 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1039 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
|
1040 |
$dbi->delete(table => $table1, where => {$key1 => 1}); |
|
1041 |
$result = $dbi->execute("select * from $table1;"); |
|
test cleanup
|
1042 |
$rows = $result->all; |
test cleanup in progress
|
1043 |
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic"); |
test cleanup
|
1044 | |
test cleanup in progress
|
1045 |
$dbi->execute("delete from $table1;"); |
1046 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
|
1047 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
|
test cleanup
|
1048 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
test cleanup in progress
|
1049 |
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'}); |
1050 |
$result = $dbi->execute("select * from $table1;"); |
|
test cleanup
|
1051 |
$rows = $result->all; |
test cleanup in progress
|
1052 |
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter"); |
test cleanup
|
1053 | |
test cleanup in progress
|
1054 |
$dbi->delete(table => $table1, where => {$key1 => 1}, append => ' '); |
test cleanup
|
1055 | |
test cleanup in progress
|
1056 |
$dbi->delete_all(table => $table1); |
1057 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
|
1058 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
|
1059 |
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2}); |
|
1060 |
$rows = $dbi->select(table => $table1)->all; |
|
1061 |
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key"); |
|
test cleanup
|
1062 | |
test cleanup in progress
|
1063 |
eval{$dbi->delete(table => $table1, where => {$key1 => 1}, noexist => 1)}; |
test cleanup
|
1064 |
like($@, qr/noexist/, "invalid"); |
1065 | ||
test cleanup in progress
|
1066 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1067 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1068 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1069 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
|
test cleanup
|
1070 |
$where = $dbi->where; |
test cleanup in progress
|
1071 |
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]); |
1072 |
$where->param({ke1 => 1, $key2 => 2}); |
|
1073 |
$dbi->delete(table => $table1, where => $where); |
|
1074 |
$result = $dbi->select(table => $table1); |
|
1075 |
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where'); |
|
test cleanup
|
1076 | |
test cleanup in progress
|
1077 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1078 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1079 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1080 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
|
test cleanup
|
1081 |
$dbi->delete( |
test cleanup in progress
|
1082 |
table => $table1, |
test cleanup
|
1083 |
where => [ |
test cleanup in progress
|
1084 |
['and', "$key1 = :$key1", "$key2 = :$key2"], |
1085 |
{ke1 => 1, $key2 => 2} |
|
test cleanup
|
1086 |
] |
1087 |
); |
|
test cleanup in progress
|
1088 |
$result = $dbi->select(table => $table1); |
1089 |
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where'); |
|
test cleanup
|
1090 | |
test cleanup in progress
|
1091 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1092 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1093 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1094 |
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => ' '); |
|
1095 |
$result = $dbi->execute("select * from $table1;"); |
|
test cleanup
|
1096 |
$rows = $result->all; |
1097 |
is_deeply($rows, [], "basic"); |
|
1098 | ||
1099 |
test 'delete error'; |
|
test cleanup in progress
|
1100 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1101 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1102 |
eval{$dbi->delete(table => $table1)}; |
test cleanup
|
1103 |
like($@, qr/"where" must be specified/, |
1104 |
"where key-value pairs not specified"); |
|
1105 | ||
test cleanup in progress
|
1106 |
eval{$dbi->delete(table => $table1, where => {';' => 1})}; |
test cleanup
|
1107 |
like($@, qr/safety/); |
1108 | ||
test cleanup
|
1109 |
$dbi = undef; |
test cleanup
|
1110 |
$dbi = DBIx::Custom->connect; |
1111 |
eval { $dbi->execute("drop table ${q}table$p") }; |
|
test cleanup
|
1112 |
$dbi->execute($create_table_reserved); |
test cleanup
|
1113 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
1114 |
$dbi->insert(table => 'table', param => {select => 1}); |
|
1115 |
$dbi->delete(table => 'table', where => {select => 1}); |
|
1116 |
$result = $dbi->execute("select * from ${q}table$p"); |
|
1117 |
$rows = $result->all; |
|
1118 |
is_deeply($rows, [], "reserved word"); |
|
1119 | ||
1120 |
test 'delete_all'; |
|
test cleanup in progress
|
1121 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1122 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1123 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1124 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
|
1125 |
$dbi->delete_all(table => $table1); |
|
1126 |
$result = $dbi->execute("select * from $table1;"); |
|
test cleanup
|
1127 |
$rows = $result->all; |
1128 |
is_deeply($rows, [], "basic"); |
|
1129 | ||
1130 | ||
1131 |
test 'select'; |
|
test cleanup in progress
|
1132 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1133 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1134 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1135 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
|
1136 |
$rows = $dbi->select(table => $table1)->all; |
|
1137 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, |
|
1138 |
{$key1 => 3, $key2 => 4}], "table"); |
|
test cleanup
|
1139 | |
test cleanup in progress
|
1140 |
$rows = $dbi->select(table => $table1, column => [$key1])->all; |
1141 |
is_deeply($rows, [{$key1 => 1}, {$key1 => 3}], "table and columns and where key"); |
|
test cleanup
|
1142 | |
test cleanup in progress
|
1143 |
$rows = $dbi->select(table => $table1, where => {$key1 => 1})->all; |
1144 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table and columns and where key"); |
|
test cleanup
|
1145 | |
test cleanup in progress
|
1146 |
$rows = $dbi->select(table => $table1, column => [$key1], where => {$key1 => 3})->all; |
1147 |
is_deeply($rows, [{$key1 => 3}], "table and columns and where key"); |
|
test cleanup
|
1148 | |
1149 |
$dbi->register_filter(decrement => sub { $_[0] - 1 }); |
|
test cleanup in progress
|
1150 |
$rows = $dbi->select(table => $table1, where => {$key1 => 2}, filter => {$key1 => 'decrement'}) |
test cleanup
|
1151 |
->all; |
test cleanup in progress
|
1152 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "filter"); |
test cleanup
|
1153 | |
test cleanup in progress
|
1154 |
eval { $dbi->execute("drop table $table2") }; |
test cleanup
|
1155 |
$dbi->execute($create_table2); |
test cleanup in progress
|
1156 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5}); |
test cleanup
|
1157 |
$rows = $dbi->select( |
test cleanup in progress
|
1158 |
table => [$table1, $table2], |
1159 |
column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3", |
|
1160 |
where => {"$table1.$key2" => 2}, |
|
1161 |
relation => {"$table1.$key1" => "$table2.$key1"} |
|
test cleanup
|
1162 |
)->all; |
test cleanup in progress
|
1163 |
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], "relation : exists where"); |
test cleanup
|
1164 | |
1165 |
$rows = $dbi->select( |
|
test cleanup in progress
|
1166 |
table => [$table1, $table2], |
1167 |
column => ["$table1.$key1 as ${table1}_$key1', '${table2}.$key1 as ${table2}_$key1", $key2, $key3], |
|
1168 |
relation => {"$table1.$key1" => "$table2.$key1"} |
|
test cleanup
|
1169 |
)->all; |
test cleanup in progress
|
1170 |
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], "relation : no exists where"); |
test cleanup
|
1171 | |
test cleanup in progress
|
1172 |
eval{$dbi->select(table => $table1, noexist => 1)}; |
test cleanup
|
1173 |
like($@, qr/noexist/, "invalid"); |
1174 | ||
1175 |
$dbi = DBIx::Custom->connect; |
|
test cleanup
|
1176 |
eval { $dbi->execute("drop table ${q}table$p") }; |
1177 |
$dbi->execute($create_table_reserved); |
|
test cleanup
|
1178 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
1179 |
$dbi->insert(table => 'table', param => {select => 1, update => 2}); |
|
1180 |
$result = $dbi->select(table => 'table', where => {select => 1}); |
|
1181 |
$rows = $result->all; |
|
1182 |
is_deeply($rows, [{select => 2, update => 2}], "reserved word"); |
|
1183 | ||
1184 |
test 'fetch filter'; |
|
test cleanup in progress
|
1185 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1186 |
$dbi->register_filter( |
1187 |
twice => sub { $_[0] * 2 }, |
|
1188 |
three_times => sub { $_[0] * 3 } |
|
1189 |
); |
|
1190 |
$dbi->default_fetch_filter('twice'); |
|
1191 |
$dbi->execute($create_table1); |
|
test cleanup in progress
|
1192 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1193 |
$result = $dbi->select(table => $table1); |
|
1194 |
$result->filter({$key1 => 'three_times'}); |
|
test cleanup
|
1195 |
$row = $result->one; |
test cleanup in progress
|
1196 |
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter"); |
test cleanup
|
1197 | |
1198 |
test 'filters'; |
|
1199 |
$dbi = DBIx::Custom->new; |
|
1200 | ||
1201 |
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')), |
|
1202 |
'あ', "decode_utf8"); |
|
1203 | ||
1204 |
is($dbi->filters->{encode_utf8}->('あ'), |
|
1205 |
encode_utf8('あ'), "encode_utf8"); |
|
1206 | ||
cleanup test
|
1207 |
test 'transaction1'; |
test cleanup
|
1208 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
1209 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1210 |
$dbi->execute($create_table1); |
fixed transaction test
|
1211 |
$dbi->begin_work; |
1212 |
$dbi->dbh->{AutoCommit} = 0; |
|
test cleanup in progress
|
1213 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
fixed transaction test
|
1214 |
$dbi->rollback; |
1215 |
$dbi->dbh->{AutoCommit} = 1; |
|
1216 | ||
test cleanup in progress
|
1217 |
$result = $dbi->select(table => $table1); |
fixed transaction test
|
1218 |
ok(! $result->fetch_first, "rollback"); |
1219 | ||
test cleanup
|
1220 | |
1221 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1222 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1223 |
$dbi->execute($create_table1); |
fixed transaction test
|
1224 |
$dbi->begin_work; |
1225 |
$dbi->dbh->{AutoCommit} = 0; |
|
test cleanup in progress
|
1226 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1227 |
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3}); |
|
fixed transaction test
|
1228 |
$dbi->commit; |
1229 |
$dbi->dbh->{AutoCommit} = 1; |
|
test cleanup in progress
|
1230 |
$result = $dbi->select(table => $table1); |
1231 |
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}], |
|
fixed transaction test
|
1232 |
"commit"); |
test cleanup
|
1233 | |
1234 |
test 'execute'; |
|
test cleanup in progress
|
1235 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1236 |
$dbi->execute($create_table1); |
1237 |
{ |
|
1238 |
local $Carp::Verbose = 0; |
|
test cleanup in progress
|
1239 |
eval{$dbi->execute('select * frm $table1')}; |
1240 |
like($@, qr/\Qselect * frm $table1;/, "fail prepare"); |
|
test cleanup
|
1241 |
like($@, qr/\.t /, "fail : not verbose"); |
1242 |
} |
|
1243 |
{ |
|
1244 |
local $Carp::Verbose = 1; |
|
test cleanup in progress
|
1245 |
eval{$dbi->execute('select * frm $table1')}; |
test cleanup
|
1246 |
like($@, qr/Custom.*\.t /s, "fail : verbose"); |
1247 |
} |
|
1248 | ||
test cleanup in progress
|
1249 |
eval{$dbi->execute('select * from $table1', no_exists => 1)}; |
test cleanup
|
1250 |
like($@, qr/wrong/, "invald SQL"); |
1251 | ||
test cleanup in progress
|
1252 |
$query = $dbi->execute("select * from $table1 where $key1 = :$key1", {}, query => 1); |
test cleanup
|
1253 |
$dbi->dbh->disconnect; |
test cleanup in progress
|
1254 |
eval{$dbi->execute($query, param => {$key1 => {a => 1}})}; |
test cleanup
|
1255 |
ok($@, "execute fail"); |
1256 | ||
1257 |
{ |
|
1258 |
local $Carp::Verbose = 0; |
|
test cleanup in progress
|
1259 |
eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)}; |
test cleanup
|
1260 |
like($@, qr/\Q.t /, "caller spec : not vebose"); |
1261 |
} |
|
1262 |
{ |
|
1263 |
local $Carp::Verbose = 1; |
|
test cleanup in progress
|
1264 |
eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)}; |
test cleanup
|
1265 |
like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose"); |
1266 |
} |
|
1267 | ||
1268 | ||
cleanup test
|
1269 |
test 'transaction2'; |
test cleanup
|
1270 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
1271 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1272 |
$dbi->execute($create_table1); |
1273 | ||
1274 |
$dbi->begin_work; |
|
1275 | ||
1276 |
eval { |
|
test cleanup in progress
|
1277 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
test cleanup
|
1278 |
die "Error"; |
test cleanup in progress
|
1279 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
test cleanup
|
1280 |
}; |
1281 | ||
1282 |
$dbi->rollback if $@; |
|
1283 | ||
test cleanup in progress
|
1284 |
$result = $dbi->select(table => $table1); |
test cleanup
|
1285 |
$rows = $result->all; |
1286 |
is_deeply($rows, [], "rollback"); |
|
1287 | ||
1288 |
$dbi->begin_work; |
|
1289 | ||
1290 |
eval { |
|
test cleanup in progress
|
1291 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1292 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
|
test cleanup
|
1293 |
}; |
1294 | ||
1295 |
$dbi->commit unless $@; |
|
1296 | ||
test cleanup in progress
|
1297 |
$result = $dbi->select(table => $table1); |
test cleanup
|
1298 |
$rows = $result->all; |
test cleanup in progress
|
1299 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "commit"); |
test cleanup
|
1300 | |
1301 |
$dbi->dbh->{AutoCommit} = 0; |
|
1302 |
eval{ $dbi->begin_work }; |
|
1303 |
ok($@, "exception"); |
|
1304 |
$dbi->dbh->{AutoCommit} = 1; |
|
added EXPERIMENTAL DBIx::Cus...
|
1305 | |
test cleanup
|
1306 |
test 'cache'; |
test cleanup in progress
|
1307 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1308 |
$dbi->cache(1); |
1309 |
$dbi->execute($create_table1); |
|
test cleanup in progress
|
1310 |
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2;"; |
test cleanup
|
1311 |
$dbi->execute($source, {}, query => 1); |
1312 |
is_deeply($dbi->{_cached}->{$source}, |
|
test cleanup in progress
|
1313 |
{sql => "select * from $table1 where $key1 = ? and $key2 = ?;", columns => [$key1, $key2], tables => []}, "cache"); |
test cleanup
|
1314 | |
test cleanup in progress
|
1315 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1316 |
$dbi->execute($create_table1); |
1317 |
$dbi->{_cached} = {}; |
|
1318 |
$dbi->cache(0); |
|
test cleanup in progress
|
1319 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
test cleanup
|
1320 |
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache'); |
1321 | ||
1322 |
test 'execute'; |
|
test cleanup in progress
|
1323 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1324 |
$dbi->execute($create_table1); |
1325 |
{ |
|
1326 |
local $Carp::Verbose = 0; |
|
test cleanup in progress
|
1327 |
eval{$dbi->execute('select * frm $table1')}; |
1328 |
like($@, qr/\Qselect * frm $table1;/, "fail prepare"); |
|
test cleanup
|
1329 |
like($@, qr/\.t /, "fail : not verbose"); |
1330 |
} |
|
1331 |
{ |
|
1332 |
local $Carp::Verbose = 1; |
|
test cleanup in progress
|
1333 |
eval{$dbi->execute('select * frm $table1')}; |
test cleanup
|
1334 |
like($@, qr/Custom.*\.t /s, "fail : verbose"); |
1335 |
} |
|
1336 | ||
test cleanup in progress
|
1337 |
eval{$dbi->execute('select * from $table1', no_exists => 1)}; |
test cleanup
|
1338 |
like($@, qr/wrong/, "invald SQL"); |
1339 | ||
test cleanup in progress
|
1340 |
$query = $dbi->execute("select * from $table1 where $key1 = :$key1", {}, query => 1); |
test cleanup
|
1341 |
$dbi->dbh->disconnect; |
test cleanup in progress
|
1342 |
eval{$dbi->execute($query, param => {$key1 => {a => 1}})}; |
test cleanup
|
1343 |
ok($@, "execute fail"); |
1344 | ||
1345 |
{ |
|
1346 |
local $Carp::Verbose = 0; |
|
test cleanup in progress
|
1347 |
eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)}; |
test cleanup
|
1348 |
like($@, qr/\Q.t /, "caller spec : not vebose"); |
1349 |
} |
|
1350 |
{ |
|
1351 |
local $Carp::Verbose = 1; |
|
test cleanup in progress
|
1352 |
eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)}; |
test cleanup
|
1353 |
like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose"); |
1354 |
} |
|
1355 | ||
1356 |
test 'method'; |
|
1357 |
$dbi->method( |
|
1358 |
one => sub { 1 } |
|
1359 |
); |
|
1360 |
$dbi->method( |
|
1361 |
two => sub { 2 } |
|
1362 |
); |
|
1363 |
$dbi->method({ |
|
1364 |
twice => sub { |
|
1365 |
my $self = shift; |
|
1366 |
return $_[0] * 2; |
|
1367 |
} |
|
1368 |
}); |
|
1369 | ||
1370 |
is($dbi->one, 1, "first"); |
|
1371 |
is($dbi->two, 2, "second"); |
|
1372 |
is($dbi->twice(5), 10 , "second"); |
|
1373 | ||
1374 |
eval {$dbi->XXXXXX}; |
|
1375 |
ok($@, "not exists"); |
|
1376 | ||
1377 |
test 'out filter'; |
|
1378 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1379 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1380 |
$dbi->execute($create_table1); |
1381 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1382 |
$dbi->register_filter(three_times => sub { $_[0] * 3}); |
|
1383 |
$dbi->apply_filter( |
|
test cleanup in progress
|
1384 |
$table1, $key1 => {out => 'twice', in => 'three_times'}, |
1385 |
$key2 => {out => 'three_times', in => 'twice'}); |
|
1386 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
|
1387 |
$result = $dbi->execute("select * from $table1;"); |
|
test cleanup
|
1388 |
$row = $result->fetch_hash_first; |
test cleanup in progress
|
1389 |
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert"); |
1390 |
$result = $dbi->select(table => $table1); |
|
test cleanup
|
1391 |
$row = $result->one; |
test cleanup in progress
|
1392 |
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert"); |
test cleanup
|
1393 | |
1394 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1395 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1396 |
$dbi->execute($create_table1); |
1397 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1398 |
$dbi->register_filter(three_times => sub { $_[0] * 3}); |
|
1399 |
$dbi->apply_filter( |
|
test cleanup in progress
|
1400 |
$table1, $key1 => {out => 'twice', in => 'three_times'}, |
1401 |
$key2 => {out => 'three_times', in => 'twice'}); |
|
test cleanup
|
1402 |
$dbi->apply_filter( |
test cleanup in progress
|
1403 |
$table1, $key1 => {out => undef} |
test cleanup
|
1404 |
); |
test cleanup in progress
|
1405 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1406 |
$result = $dbi->execute("select * from $table1;"); |
|
test cleanup
|
1407 |
$row = $result->one; |
test cleanup in progress
|
1408 |
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert"); |
test cleanup
|
1409 | |
1410 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1411 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1412 |
$dbi->execute($create_table1); |
1413 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1414 |
$dbi->apply_filter( |
|
test cleanup in progress
|
1415 |
$table1, $key1 => {out => 'twice', in => 'twice'} |
test cleanup
|
1416 |
); |
test cleanup in progress
|
1417 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => undef}); |
1418 |
$dbi->update(table => $table1, param => {$key1 => 2}, where => {$key2 => 2}); |
|
1419 |
$result = $dbi->execute("select * from $table1;"); |
|
test cleanup
|
1420 |
$row = $result->one; |
test cleanup in progress
|
1421 |
is_deeply($row, {$key1 => 4, $key2 => 2}, "update"); |
test cleanup
|
1422 | |
1423 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1424 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1425 |
$dbi->execute($create_table1); |
1426 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1427 |
$dbi->apply_filter( |
|
test cleanup in progress
|
1428 |
$table1, $key1 => {out => 'twice', in => 'twice'} |
test cleanup
|
1429 |
); |
test cleanup in progress
|
1430 |
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1=> undef}); |
1431 |
$dbi->delete(table => $table1, where => {$key1 => 1}); |
|
1432 |
$result = $dbi->execute("select * from $table1;"); |
|
test cleanup
|
1433 |
$rows = $result->all; |
1434 |
is_deeply($rows, [], "delete"); |
|
1435 | ||
1436 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1437 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1438 |
$dbi->execute($create_table1); |
1439 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1440 |
$dbi->apply_filter( |
|
test cleanup in progress
|
1441 |
$table1, $key1 => {out => 'twice', in => 'twice'} |
test cleanup
|
1442 |
); |
test cleanup in progress
|
1443 |
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef}); |
1444 |
$result = $dbi->select(table => $table1, where => {$key1 => 1}); |
|
1445 |
$result->filter({$key2 => 'twice'}); |
|
test cleanup
|
1446 |
$rows = $result->all; |
test cleanup in progress
|
1447 |
is_deeply($rows, [{$key1 => 4, $key2 => 4}], "select"); |
test cleanup
|
1448 | |
1449 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1450 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1451 |
$dbi->execute($create_table1); |
1452 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1453 |
$dbi->apply_filter( |
|
test cleanup in progress
|
1454 |
$table1, $key1 => {out => 'twice', in => 'twice'} |
test cleanup
|
1455 |
); |
test cleanup in progress
|
1456 |
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef}); |
1457 |
$result = $dbi->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2;", |
|
1458 |
param => {$key1 => 1, $key2 => 2}, |
|
1459 |
table => [$table1]); |
|
test cleanup
|
1460 |
$rows = $result->all; |
test cleanup in progress
|
1461 |
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute"); |
test cleanup
|
1462 | |
1463 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1464 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1465 |
$dbi->execute($create_table1); |
1466 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1467 |
$dbi->apply_filter( |
|
test cleanup in progress
|
1468 |
$table1, $key1 => {out => 'twice', in => 'twice'} |
test cleanup
|
1469 |
); |
test cleanup in progress
|
1470 |
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef}); |
1471 |
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2;", |
|
1472 |
param => {$key1 => 1, $key2 => 2}); |
|
test cleanup
|
1473 |
$rows = $result->all; |
test cleanup in progress
|
1474 |
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag"); |
test cleanup
|
1475 | |
1476 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1477 |
eval { $dbi->execute('drop table $table1') }; |
1478 |
eval { $dbi->execute('drop table $table2') }; |
|
test cleanup
|
1479 |
$dbi->execute($create_table1); |
1480 |
$dbi->execute($create_table2); |
|
1481 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1482 |
$dbi->register_filter(three_times => sub { $_[0] * 3 }); |
|
1483 |
$dbi->apply_filter( |
|
test cleanup in progress
|
1484 |
$table1, $key2 => {out => 'twice', in => 'twice'} |
test cleanup
|
1485 |
); |
1486 |
$dbi->apply_filter( |
|
test cleanup in progress
|
1487 |
$table2, $key3 => {out => 'three_times', in => 'three_times'} |
test cleanup
|
1488 |
); |
test cleanup in progress
|
1489 |
$dbi->insert(table => $table1, param => {$key1 => 5, $key2 => 2}, filter => {$key2 => undef}); |
1490 |
$dbi->insert(table => $table2, param => {$key1 => 5, $key3 => 6}, filter => {$key3 => undef}); |
|
test cleanup
|
1491 |
$result = $dbi->select( |
test cleanup in progress
|
1492 |
table => [$table1, $table2], |
1493 |
column => [$key2, $key3], |
|
1494 |
where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"}); |
|
test cleanup
|
1495 | |
test cleanup in progress
|
1496 |
$result->filter({$key2 => 'twice'}); |
test cleanup
|
1497 |
$rows = $result->all; |
test cleanup in progress
|
1498 |
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join"); |
test cleanup
|
1499 | |
1500 |
$result = $dbi->select( |
|
test cleanup in progress
|
1501 |
table => [$table1, $table2], |
1502 |
column => [$key2, $key3], |
|
1503 |
where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"}); |
|
test cleanup
|
1504 | |
test cleanup in progress
|
1505 |
$result->filter({$key2 => 'twice'}); |
test cleanup
|
1506 |
$rows = $result->all; |
test cleanup in progress
|
1507 |
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join : omit"); |
test cleanup
|
1508 | |
1509 |
test 'each_column'; |
|
1510 |
$dbi = DBIx::Custom->connect; |
|
1511 |
eval { $dbi->execute("drop table ${q}table$p") }; |
|
test cleanup in progress
|
1512 |
eval { $dbi->execute('drop table $table1') }; |
1513 |
eval { $dbi->execute('drop table $table2') }; |
|
1514 |
eval { $dbi->execute('drop table $table3') }; |
|
test cleanup
|
1515 |
$dbi->execute($create_table1_type); |
1516 |
$dbi->execute($create_table2); |
|
1517 | ||
1518 |
$infos = []; |
|
1519 |
$dbi->each_column(sub { |
|
1520 |
my ($self, $table, $column, $cinfo) = @_; |
|
1521 |
|
|
1522 |
if ($table =~ /^table\d/) { |
|
1523 |
my $info = [$table, $column, $cinfo->{COLUMN_NAME}]; |
|
1524 |
push @$infos, $info; |
|
1525 |
} |
|
1526 |
}); |
|
1527 |
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos]; |
|
1528 |
is_deeply($infos, |
|
1529 |
[ |
|
test cleanup in progress
|
1530 |
[$table1, $key1, $key1], |
1531 |
[$table1, $key2, $key2], |
|
1532 |
[$table2, $key1, $key1], |
|
1533 |
[$table2, $key3, $key3] |
|
test cleanup
|
1534 |
] |
1535 |
|
|
1536 |
); |
|
1537 |
test 'each_table'; |
|
1538 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1539 |
eval { $dbi->execute('drop table $table1') }; |
1540 |
eval { $dbi->execute('drop table $table2') }; |
|
test cleanup
|
1541 |
$dbi->execute($create_table2); |
1542 |
$dbi->execute($create_table1_type); |
|
1543 | ||
1544 |
$infos = []; |
|
1545 |
$dbi->each_table(sub { |
|
1546 |
my ($self, $table, $table_info) = @_; |
|
1547 |
|
|
1548 |
if ($table =~ /^table\d/) { |
|
1549 |
my $info = [$table, $table_info->{TABLE_NAME}]; |
|
1550 |
push @$infos, $info; |
|
1551 |
} |
|
1552 |
}); |
|
1553 |
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos]; |
|
1554 |
is_deeply($infos, |
|
1555 |
[ |
|
test cleanup in progress
|
1556 |
[$table1, $table1], |
1557 |
[$table2, $table2], |
|
test cleanup
|
1558 |
] |
1559 |
); |
|
1560 | ||
1561 |
test 'connect super'; |
|
test cleanup
|
1562 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
1563 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1564 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1565 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1566 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
|
test cleanup
|
1567 | |
test cleanup
|
1568 |
$dbi = DBIx::Custom->new; |
test cleanup
|
1569 |
$dbi->connect; |
test cleanup in progress
|
1570 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1571 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1572 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1573 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
|
test cleanup
|
1574 | |
test cleanup
|
1575 |
$dbi = DBIx::Custom->connect; |
test cleanup in progress
|
1576 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1577 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1578 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1579 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
|
test cleanup
|
1580 | |
1581 |
test 'end_filter'; |
|
1582 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1583 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1584 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1585 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1586 |
$result = $dbi->select(table => $table1); |
|
1587 |
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 }); |
|
1588 |
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 }); |
|
test cleanup
|
1589 |
$row = $result->fetch_first; |
1590 |
is_deeply($row, [6, 40]); |
|
1591 | ||
1592 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1593 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1594 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1595 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1596 |
$result = $dbi->select(table => $table1); |
|
1597 |
$result->filter([qw/$key1 $key2/] => sub { $_[0] * 2 }); |
|
1598 |
$result->end_filter([[qw/$key1 $key2/] => sub { $_[0] * 3 }]); |
|
test cleanup
|
1599 |
$row = $result->fetch_first; |
1600 |
is_deeply($row, [6, 12]); |
|
1601 | ||
1602 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1603 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1604 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1605 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1606 |
$result = $dbi->select(table => $table1); |
|
1607 |
$result->filter([[qw/$key1 $key2/] => sub { $_[0] * 2 }]); |
|
1608 |
$result->end_filter([qw/$key1 $key2/] => sub { $_[0] * 3 }); |
|
test cleanup
|
1609 |
$row = $result->fetch_first; |
1610 |
is_deeply($row, [6, 12]); |
|
1611 | ||
1612 |
$dbi->register_filter(five_times => sub { $_[0] * 5 }); |
|
test cleanup in progress
|
1613 |
$result = $dbi->select(table => $table1); |
1614 |
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 }); |
|
1615 |
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' }); |
|
test cleanup
|
1616 |
$row = $result->one; |
test cleanup in progress
|
1617 |
is_deeply($row, {$key1 => 6, $key2 => 40}); |
test cleanup
|
1618 | |
1619 |
$dbi->register_filter(five_times => sub { $_[0] * 5 }); |
|
test cleanup in progress
|
1620 |
$dbi->apply_filter($table1, |
1621 |
$key1 => {end => sub { $_[0] * 3 } }, |
|
1622 |
$key2 => {end => 'five_times'} |
|
test cleanup
|
1623 |
); |
test cleanup in progress
|
1624 |
$result = $dbi->select(table => $table1); |
1625 |
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 }); |
|
test cleanup
|
1626 |
$row = $result->one; |
test cleanup in progress
|
1627 |
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter'); |
test cleanup
|
1628 | |
1629 |
$dbi->register_filter(five_times => sub { $_[0] * 5 }); |
|
test cleanup in progress
|
1630 |
$dbi->apply_filter($table1, |
1631 |
$key1 => {end => sub { $_[0] * 3 } }, |
|
1632 |
$key2 => {end => 'five_times'} |
|
1633 |
); |
|
1634 |
$result = $dbi->select(table => $table1); |
|
1635 |
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 }); |
|
1636 |
$result->filter($key1 => undef); |
|
1637 |
$result->end_filter($key1 => undef); |
|
test cleanup
|
1638 |
$row = $result->one; |
test cleanup in progress
|
1639 |
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite'); |
test cleanup
|
1640 | |
test cleanup
|
1641 |
test 'remove_end_filter and remove_filter'; |
1642 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1643 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1644 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1645 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1646 |
$result = $dbi->select(table => $table1); |
|
test cleanup
|
1647 |
$row = $result |
test cleanup in progress
|
1648 |
->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 }) |
test cleanup
|
1649 |
->remove_filter |
test cleanup in progress
|
1650 |
->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 }) |
test cleanup
|
1651 |
->remove_end_filter |
1652 |
->fetch_first; |
|
1653 |
is_deeply($row, [1, 2]); |
|
1654 | ||
1655 |
test 'empty where select'; |
|
1656 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1657 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1658 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1659 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1660 |
$result = $dbi->select(table => $table1, where => {}); |
|
test cleanup
|
1661 |
$row = $result->one; |
test cleanup in progress
|
1662 |
is_deeply($row, {$key1 => 1, $key2 => 2}); |
test cleanup
|
1663 | |
1664 |
test 'select query option'; |
|
1665 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1666 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1667 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1668 |
$query = $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, query => 1); |
test cleanup
|
1669 |
is(ref $query, 'DBIx::Custom::Query'); |
test cleanup in progress
|
1670 |
$query = $dbi->update(table => $table1, where => {$key1 => 1}, param => {$key2 => 2}, query => 1); |
test cleanup
|
1671 |
is(ref $query, 'DBIx::Custom::Query'); |
test cleanup in progress
|
1672 |
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1); |
test cleanup
|
1673 |
is(ref $query, 'DBIx::Custom::Query'); |
test cleanup in progress
|
1674 |
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1); |
test cleanup
|
1675 |
is(ref $query, 'DBIx::Custom::Query'); |
1676 | ||
1677 |
test 'where'; |
|
1678 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
1679 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
1680 |
$dbi->execute($create_table1); |
test cleanup in progress
|
1681 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
1682 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
|
1683 |
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]); |
|
1684 |
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param'); |
|
test cleanup
|
1685 | |
1686 |
$where = $dbi->where |
|
test cleanup in progress
|
1687 |
->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]) |
1688 |
->param({$key1 => 1}); |
|
test cleanup
|
1689 | |
1690 |
$result = $dbi->select( |
|
test cleanup in progress
|
1691 |
table => $table1, |
test cleanup
|
1692 |
where => $where |
1693 |
); |
|
1694 |
$row = $result->all; |
|
test cleanup in progress
|
1695 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
1696 | |
1697 |
$result = $dbi->select( |
|
test cleanup in progress
|
1698 |
table => $table1, |
test cleanup
|
1699 |
where => [ |
test cleanup in progress
|
1700 |
['and', "$key1 = :$key1", "$key2 = :$key2"], |
1701 |
{$key1 => 1} |
|
test cleanup
|
1702 |
] |
1703 |
); |
|
1704 |
$row = $result->all; |
|
test cleanup in progress
|
1705 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
1706 | |
1707 |
$where = $dbi->where |
|
test cleanup in progress
|
1708 |
->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]) |
1709 |
->param({$key1 => 1, $key2 => 2}); |
|
test cleanup
|
1710 |
$result = $dbi->select( |
test cleanup in progress
|
1711 |
table => $table1, |
test cleanup
|
1712 |
where => $where |
1713 |
); |
|
1714 |
$row = $result->all; |
|
test cleanup in progress
|
1715 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
1716 | |
1717 |
$where = $dbi->where |
|
test cleanup in progress
|
1718 |
->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]) |
test cleanup
|
1719 |
->param({}); |
1720 |
$result = $dbi->select( |
|
test cleanup in progress
|
1721 |
table => $table1, |
test cleanup
|
1722 |
where => $where, |
1723 |
); |
|
1724 |
$row = $result->all; |
|
test cleanup in progress
|
1725 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
1726 | |
1727 |
$where = $dbi->where |
|
test cleanup in progress
|
1728 |
->clause(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"]) |
1729 |
->param({$key1 => [0, 3], $key2 => 2}); |
|
test cleanup
|
1730 |
$result = $dbi->select( |
test cleanup in progress
|
1731 |
table => $table1, |
test cleanup
|
1732 |
where => $where, |
1733 |
); |
|
1734 |
$row = $result->all; |
|
test cleanup in progress
|
1735 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
1736 | |
1737 |
$where = $dbi->where; |
|
1738 |
$result = $dbi->select( |
|
test cleanup in progress
|
1739 |
table => $table1, |
test cleanup
|
1740 |
where => $where |
1741 |
); |
|
1742 |
$row = $result->all; |
|
test cleanup in progress
|
1743 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
1744 | |
1745 |
eval { |
|
1746 |
$where = $dbi->where |
|
1747 |
->clause(['uuu']); |
|
1748 |
$result = $dbi->select( |
|
test cleanup in progress
|
1749 |
table => $table1, |
test cleanup
|
1750 |
where => $where |
1751 |
); |
|
1752 |
}; |
|
1753 |
ok($@); |
|
1754 | ||
1755 |
$where = $dbi->where; |
|
1756 |
is("$where", ''); |
|
1757 | ||
1758 |
$where = $dbi->where |
|
test cleanup in progress
|
1759 |
->clause(['or', ("$key1 = :$key1") x 2]) |
1760 |
->param({$key1 => [1, 3]}); |
|
test cleanup
|
1761 |
$result = $dbi->select( |
test cleanup in progress
|
1762 |
table => $table1, |
test cleanup
|
1763 |
where => $where, |
1764 |
); |
|
1765 |
$row = $result->all; |
|
test cleanup in progress
|
1766 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
1767 | |
1768 |
$where = $dbi->where |
|
test cleanup in progress
|
1769 |
->clause(['or', ("$key1 = :$key1") x 2]) |
1770 |
->param({$key1 => [1]}); |
|
test cleanup
|
1771 |
$result = $dbi->select( |
test cleanup in progress
|
1772 |
table => $table1, |
test cleanup
|
1773 |
where => $where, |
1774 |
); |
|
1775 |
$row = $result->all; |
|
test cleanup in progress
|
1776 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
1777 | |
1778 |
$where = $dbi->where |
|
test cleanup in progress
|
1779 |
->clause(['or', ("$key1 = :$key1") x 2]) |
1780 |
->param({$key1 => 1}); |
|
test cleanup
|
1781 |
$result = $dbi->select( |
test cleanup in progress
|
1782 |
table => $table1, |
test cleanup
|
1783 |
where => $where, |
1784 |
); |
|
1785 |
$row = $result->all; |
|
test cleanup in progress
|
1786 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
1787 | |
1788 |
$where = $dbi->where |
|
test cleanup in progress
|
1789 |
->clause('$key1 = :$key1') |
1790 |
->param({$key1 => 1}); |
|
test cleanup
|
1791 |
$result = $dbi->select( |
test cleanup in progress
|
1792 |
table => $table1, |
test cleanup
|
1793 |
where => $where, |
1794 |
); |
|
1795 |
$row = $result->all; |
|
test cleanup in progress
|
1796 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
1797 | |
1798 |
$where = $dbi->where |
|
test cleanup in progress
|
1799 |
->clause("$key1 = :$key1 $key2 = :$key2") |
1800 |
->param({$key1 => 1}); |
|
test cleanup
|
1801 |
eval{$where->to_string}; |
1802 |
like($@, qr/one column/); |
|
1803 | ||
1804 |
$where = $dbi->where |
|
test cleanup in progress
|
1805 |
->clause(['or', ("$key1 = :$key1") x 3]) |
1806 |
->param({$key1 => [$dbi->not_exists, 1, 3]}); |
|
test cleanup
|
1807 |
$result = $dbi->select( |
test cleanup in progress
|
1808 |
table => $table1, |
test cleanup
|
1809 |
where => $where, |
1810 |
); |
|
1811 |
$row = $result->all; |
|
test cleanup in progress
|
1812 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists'); |
test cleanup
|
1813 | |
1814 |
$where = $dbi->where |
|
test cleanup in progress
|
1815 |
->clause(['or', ("$key1 = :$key1") x 3]) |
1816 |
->param({$key1 => [1, $dbi->not_exists, 3]}); |
|
test cleanup
|
1817 |
$result = $dbi->select( |
test cleanup in progress
|
1818 |
table => $table1, |
test cleanup
|
1819 |
where => $where, |
1820 |
); |
|
1821 |
$row = $result->all; |
|
test cleanup in progress
|
1822 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists'); |
test cleanup
|
1823 | |
1824 |
$where = $dbi->where |
|
test cleanup in progress
|
1825 |
->clause(['or', ("$key1 = :$key1") x 3]) |
1826 |
->param({$key1 => [1, 3, $dbi->not_exists]}); |
|
test cleanup
|
1827 |
$result = $dbi->select( |
test cleanup in progress
|
1828 |
table => $table1, |
test cleanup
|
1829 |
where => $where, |
1830 |
); |
|
1831 |
$row = $result->all; |
|
test cleanup in progress
|
1832 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists'); |
test cleanup
|
1833 | |
1834 |
$where = $dbi->where |
|
test cleanup in progress
|
1835 |
->clause(['or', ("$key1 = :$key1") x 3]) |
1836 |
->param({$key1 => [1, $dbi->not_exists, $dbi->not_exists]}); |
|
test cleanup
|
1837 |
$result = $dbi->select( |
test cleanup in progress
|
1838 |
table => $table1, |
test cleanup
|
1839 |
where => $where, |
1840 |
); |
|
1841 |
$row = $result->all; |
|
test cleanup in progress
|
1842 |
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists'); |
test cleanup
|
1843 | |
1844 |
$where = $dbi->where |
|
test cleanup in progress
|
1845 |
->clause(['or', ("$key1 = :$key1") x 3]) |
1846 |
->param({$key1 => [$dbi->not_exists, 1, $dbi->not_exists]}); |
|
test cleanup
|
1847 |
$result = $dbi->select( |
test cleanup in progress
|
1848 |
table => $table1, |
test cleanup
|
1849 |
where => $where, |
1850 |
); |
|
1851 |
$row = $result->all; |
|
test cleanup in progress
|
1852 |
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists'); |
test cleanup
|
1853 | |
1854 |
$where = $dbi->where |
|
test cleanup in progress
|
1855 |
->clause(['or', ("$key1 = :$key1") x 3]) |
1856 |
->param({$key1 => [$dbi->not_exists, $dbi->not_exists, 1]}); |
|
test cleanup
|
1857 |
$result = $dbi->select( |
test cleanup in progress
|
1858 |
table => $table1, |
test cleanup
|
1859 |
where => $where, |
1860 |
); |
|
1861 |
$row = $result->all; |
|
test cleanup in progress
|
1862 |
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists'); |
test cleanup
|
1863 | |
1864 |
$where = $dbi->where |
|
test cleanup in progress
|
1865 |
->clause(['or', ("$key1 = :$key1") x 3]) |
1866 |
->param({$key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]}); |
|
test cleanup
|
1867 |
$result = $dbi->select( |
test cleanup in progress
|
1868 |
table => $table1, |
test cleanup
|
1869 |
where => $where, |
1870 |
); |
|
1871 |
$row = $result->all; |
|
test cleanup in progress
|
1872 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists'); |
test cleanup
|
1873 | |
1874 |
$where = $dbi->where |
|
test cleanup in progress
|
1875 |
->clause(['or', ("$key1 = :$key1") x 3]) |
1876 |
->param({$key1 => []}); |
|
test cleanup
|
1877 |
$result = $dbi->select( |
test cleanup in progress
|
1878 |
table => $table1, |
test cleanup
|
1879 |
where => $where, |
1880 |
); |
|
1881 |
$row = $result->all; |
|
test cleanup in progress
|
1882 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists'); |
test cleanup
|
1883 | |
1884 |
$where = $dbi->where |
|
test cleanup in progress
|
1885 |
->clause(['and', "{> $key1}", "{< $key1}" ]) |
1886 |
->param({$key1 => [2, $dbi->not_exists]}); |
|
test cleanup
|
1887 |
$result = $dbi->select( |
test cleanup in progress
|
1888 |
table => $table1, |
test cleanup
|
1889 |
where => $where, |
1890 |
); |
|
1891 |
$row = $result->all; |
|
test cleanup in progress
|
1892 |
is_deeply($row, [{$key1 => 3, $key2 => 4}], 'not_exists'); |
test cleanup
|
1893 | |
1894 |
$where = $dbi->where |
|
test cleanup in progress
|
1895 |
->clause(['and', "{> $key1}", "{< $key1}" ]) |
1896 |
->param({$key1 => [$dbi->not_exists, 2]}); |
|
test cleanup
|
1897 |
$result = $dbi->select( |
test cleanup in progress
|
1898 |
table => $table1, |
test cleanup
|
1899 |
where => $where, |
1900 |
); |
|
1901 |
$row = $result->all; |
|
test cleanup in progress
|
1902 |
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists'); |
test cleanup
|
1903 | |
1904 |
$where = $dbi->where |
|
test cleanup in progress
|
1905 |
->clause(['and', "{> $key1}", "{< $key1}" ]) |
1906 |
->param({$key1 => [$dbi->not_exists, $dbi->not_exists]}); |
|
test cleanup
|
1907 |
$result = $dbi->select( |
test cleanup in progress
|
1908 |
table => $table1, |
test cleanup
|
1909 |
where => $where, |
1910 |
); |
|
1911 |
$row = $result->all; |
|
test cleanup in progress
|
1912 |
is_deeply($row, [{$key1 => 1, $key2 => 2},{$key1 => 3, $key2 => 4}], 'not_exists'); |
test cleanup
|
1913 | |
1914 |
$where = $dbi->where |
|
test cleanup in progress
|
1915 |
->clause(['and', "{> $key1}", "{< $key1}" ]) |
1916 |
->param({$key1 => [0, 2]}); |
|
test cleanup
|
1917 |
$result = $dbi->select( |
test cleanup in progress
|
1918 |
table => $table1, |
test cleanup
|
1919 |
where => $where, |
1920 |
); |
|
1921 |
$row = $result->all; |
|
test cleanup in progress
|
1922 |
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists'); |
test cleanup
|
1923 | |
1924 |
$where = $dbi->where |
|
test cleanup in progress
|
1925 |
->clause(['and',"$key1 is not null", "$key2 is not null" ]); |
test cleanup
|
1926 |
$result = $dbi->select( |
test cleanup in progress
|
1927 |
table => $table1, |
test cleanup
|
1928 |
where => $where, |
1929 |
); |
|
1930 |
$row = $result->all; |
|
test cleanup in progress
|
1931 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists'); |
test cleanup
|
1932 | |
1933 |
eval {$dbi->where(ppp => 1) }; |
|
1934 |
like($@, qr/invalid/); |
|
1935 | ||
1936 |
$where = $dbi->where( |
|
test cleanup in progress
|
1937 |
clause => ['and', ['or'], ['and', "$key1 = :$key1", "$key2 = :$key2"]], |
1938 |
param => {$key1 => 1, $key2 => 2} |
|
test cleanup
|
1939 |
); |
1940 |
$result = $dbi->select( |
|
test cleanup in progress
|
1941 |
table => $table1, |
test cleanup
|
1942 |
where => $where, |
1943 |
); |
|
1944 |
$row = $result->all; |
|
test cleanup in progress
|
1945 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
1946 | |
1947 | ||
1948 |
$where = $dbi->where( |
|
test cleanup in progress
|
1949 |
clause => ['and', ['or'], ['or', ":$key1", ":$key2"]], |
test cleanup
|
1950 |
param => {} |
1951 |
); |
|
1952 |
$result = $dbi->select( |
|
test cleanup in progress
|
1953 |
table => $table1, |
test cleanup
|
1954 |
where => $where, |
1955 |
); |
|
1956 |
$row = $result->all; |
|
test cleanup in progress
|
1957 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
1958 | |
1959 |
$where = $dbi->where; |
|
test cleanup in progress
|
1960 |
$where->clause(['and', ":${key1}{=}"]); |
1961 |
$where->param({$key1 => undef}); |
|
1962 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1}); |
|
test cleanup
|
1963 |
$row = $result->all; |
test cleanup in progress
|
1964 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
1965 | |
1966 |
$where = $dbi->where; |
|
test cleanup in progress
|
1967 |
$where->clause(['and', ":${key1}{=}"]); |
1968 |
$where->param({$key1 => undef}); |
|
test cleanup
|
1969 |
$where->if('defined'); |
1970 |
$where->map; |
|
test cleanup in progress
|
1971 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1}); |
test cleanup
|
1972 |
$row = $result->all; |
test cleanup in progress
|
1973 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
1974 | |
1975 |
$where = $dbi->where; |
|
test cleanup in progress
|
1976 |
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]); |
1977 |
$where->param({$key1 => [undef, undef]}); |
|
1978 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]}); |
|
test cleanup
|
1979 |
$row = $result->all; |
test cleanup in progress
|
1980 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
1981 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]}); |
|
test cleanup
|
1982 |
$row = $result->all; |
test cleanup in progress
|
1983 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
1984 | |
1985 |
$where = $dbi->where; |
|
test cleanup in progress
|
1986 |
$where->clause(['and', ":${key1}{=}"]); |
1987 |
$where->param({$key1 => [undef, undef]}); |
|
test cleanup
|
1988 |
$where->if('defined'); |
1989 |
$where->map; |
|
test cleanup in progress
|
1990 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]}); |
test cleanup
|
1991 |
$row = $result->all; |
test cleanup in progress
|
1992 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
1993 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]}); |
|
test cleanup
|
1994 |
$row = $result->all; |
test cleanup in progress
|
1995 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
1996 | |
1997 |
$where = $dbi->where; |
|
test cleanup in progress
|
1998 |
$where->clause(['and', ":${key1}{=}"]); |
1999 |
$where->param({$key1 => 0}); |
|
test cleanup
|
2000 |
$where->if('length'); |
2001 |
$where->map; |
|
test cleanup in progress
|
2002 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1}); |
test cleanup
|
2003 |
$row = $result->all; |
test cleanup in progress
|
2004 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
2005 | |
2006 |
$where = $dbi->where; |
|
test cleanup in progress
|
2007 |
$where->clause(['and', ":${key1}{=}"]); |
2008 |
$where->param({$key1 => ''}); |
|
test cleanup
|
2009 |
$where->if('length'); |
2010 |
$where->map; |
|
test cleanup in progress
|
2011 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1}); |
test cleanup
|
2012 |
$row = $result->all; |
test cleanup in progress
|
2013 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
2014 | |
2015 |
$where = $dbi->where; |
|
test cleanup in progress
|
2016 |
$where->clause(['and', ":${key1}{=}"]); |
2017 |
$where->param({$key1 => 5}); |
|
test cleanup
|
2018 |
$where->if(sub { ($_[0] || '') eq 5 }); |
2019 |
$where->map; |
|
test cleanup in progress
|
2020 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1}); |
test cleanup
|
2021 |
$row = $result->all; |
test cleanup in progress
|
2022 |
is_deeply($row, [{$key1 => 1, $key2 => 2}]); |
test cleanup
|
2023 | |
2024 |
$where = $dbi->where; |
|
test cleanup in progress
|
2025 |
$where->clause(['and', ":${key1}{=}"]); |
2026 |
$where->param({$key1 => 7}); |
|
test cleanup
|
2027 |
$where->if(sub { ($_[0] || '') eq 5 }); |
2028 |
$where->map; |
|
test cleanup in progress
|
2029 |
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1}); |
test cleanup
|
2030 |
$row = $result->all; |
test cleanup in progress
|
2031 |
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
2032 | |
2033 |
$where = $dbi->where; |
|
2034 |
$where->param({id => 1, author => 'Ken', price => 1900}); |
|
test cleanup in progress
|
2035 |
$where->map(id => '$table1.id', |
2036 |
author => ['$table1.author', sub { '%' . $_[0] . '%' }], |
|
2037 |
price => ['$table1.price', {if => sub { $_[0] eq 1900 }}] |
|
test cleanup
|
2038 |
); |
test cleanup in progress
|
2039 |
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%', |
2040 |
'$table1.price' => 1900}); |
|
test cleanup
|
2041 | |
2042 |
$where = $dbi->where; |
|
2043 |
$where->param({id => 0, author => 0, price => 0}); |
|
2044 |
$where->map( |
|
test cleanup in progress
|
2045 |
id => '$table1.id', |
2046 |
author => ['$table1.author', sub { '%' . $_[0] . '%' }], |
|
2047 |
price => ['$table1.price', sub { '%' . $_[0] . '%' }, |
|
test cleanup
|
2048 |
{if => sub { $_[0] eq 0 }}] |
2049 |
); |
|
test cleanup in progress
|
2050 |
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'}); |
test cleanup
|
2051 | |
2052 |
$where = $dbi->where; |
|
2053 |
$where->param({id => '', author => '', price => ''}); |
|
2054 |
$where->if('length'); |
|
2055 |
$where->map( |
|
test cleanup in progress
|
2056 |
id => '$table1.id', |
2057 |
author => ['$table1.author', sub { '%' . $_[0] . '%' }], |
|
2058 |
price => ['$table1.price', sub { '%' . $_[0] . '%' }, |
|
test cleanup
|
2059 |
{if => sub { $_[0] eq 1 }}] |
2060 |
); |
|
2061 |
is_deeply($where->param, {}); |
|
2062 | ||
2063 |
$where = $dbi->where; |
|
2064 |
$where->param({id => undef, author => undef, price => undef}); |
|
2065 |
$where->if('length'); |
|
2066 |
$where->map( |
|
test cleanup in progress
|
2067 |
id => '$table1.id', |
2068 |
price => ['$table1.price', {if => 'exists'}] |
|
test cleanup
|
2069 |
); |
test cleanup in progress
|
2070 |
is_deeply($where->param, {'$table1.price' => undef}); |
test cleanup
|
2071 | |
2072 |
$where = $dbi->where; |
|
2073 |
$where->param({price => 'a'}); |
|
2074 |
$where->if('length'); |
|
2075 |
$where->map( |
|
test cleanup in progress
|
2076 |
id => ['$table1.id', {if => 'exists'}], |
2077 |
price => ['$table1.price', sub { '%' . $_[0] }, {if => 'exists'}] |
|
test cleanup
|
2078 |
); |
test cleanup in progress
|
2079 |
is_deeply($where->param, {'$table1.price' => '%a'}); |
test cleanup
|
2080 | |
2081 |
$where = $dbi->where; |
|
2082 |
$where->param({id => [1, 2], author => 'Ken', price => 1900}); |
|
2083 |
$where->map( |
|
test cleanup in progress
|
2084 |
id => '$table1.id', |
2085 |
author => ['$table1.author', sub { '%' . $_[0] . '%' }], |
|
2086 |
price => ['$table1.price', {if => sub { $_[0] eq 1900 }}] |
|
test cleanup
|
2087 |
); |
test cleanup in progress
|
2088 |
is_deeply($where->param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%', |
2089 |
'$table1.price' => 1900}); |
|
test cleanup
|
2090 | |
2091 |
$where = $dbi->where; |
|
2092 |
$where->if('length'); |
|
2093 |
$where->param({id => ['', ''], author => 'Ken', price => 1900}); |
|
2094 |
$where->map( |
|
test cleanup in progress
|
2095 |
id => '$table1.id', |
2096 |
author => ['$table1.author', sub { '%' . $_[0] . '%' }], |
|
2097 |
price => ['$table1.price', {if => sub { $_[0] eq 1900 }}] |
|
test cleanup
|
2098 |
); |
test cleanup in progress
|
2099 |
is_deeply($where->param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%', |
2100 |
'$table1.price' => 1900}); |
|
test cleanup
|
2101 | |
2102 |
$where = $dbi->where; |
|
2103 |
$where->param({id => ['', ''], author => 'Ken', price => 1900}); |
|
2104 |
$where->map( |
|
test cleanup in progress
|
2105 |
id => ['$table1.id', {if => 'length'}], |
2106 |
author => ['$table1.author', sub { '%' . $_[0] . '%' }, {if => 'defined'}], |
|
2107 |
price => ['$table1.price', {if => sub { $_[0] eq 1900 }}] |
|
test cleanup
|
2108 |
); |
test cleanup in progress
|
2109 |
is_deeply($where->param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%', |
2110 |
'$table1.price' => 1900}); |
|
test cleanup
|
2111 | |
2112 |
test 'dbi_option default'; |
|
2113 |
$dbi = DBIx::Custom->new; |
|
2114 |
is_deeply($dbi->dbi_option, {}); |
|
2115 | ||
2116 |
test 'register_tag_processor'; |
|
2117 |
$dbi = DBIx::Custom->connect; |
|
2118 |
$dbi->register_tag_processor( |
|
2119 |
a => sub { 1 } |
|
2120 |
); |
|
test cleanup
|
2121 |
is($dbi->{_tags}->{a}->(), 1); |
test cleanup
|
2122 | |
2123 |
test 'register_tag'; |
|
2124 |
$dbi = DBIx::Custom->connect; |
|
2125 |
$dbi->register_tag( |
|
2126 |
b => sub { 2 } |
|
2127 |
); |
|
test cleanup
|
2128 |
is($dbi->{_tags}->{b}->(), 2); |
test cleanup
|
2129 | |
2130 |
test 'table not specify exception'; |
|
2131 |
$dbi = DBIx::Custom->connect; |
|
2132 |
eval {$dbi->insert}; |
|
2133 |
like($@, qr/table/); |
|
2134 |
eval {$dbi->update}; |
|
2135 |
like($@, qr/table/); |
|
2136 |
eval {$dbi->delete}; |
|
2137 |
like($@, qr/table/); |
|
2138 |
eval {$dbi->select}; |
|
2139 |
like($@, qr/table/); |
|
test cleanup
|
2140 | |
test cleanup
|
2141 |
test 'more tests'; |
2142 |
$dbi = DBIx::Custom->connect; |
|
2143 |
eval{$dbi->apply_filter('table', 'column', [])}; |
|
2144 |
like($@, qr/apply_filter/); |
|
2145 | ||
2146 |
eval{$dbi->apply_filter('table', 'column', {outer => 2})}; |
|
2147 |
like($@, qr/apply_filter/); |
|
2148 | ||
2149 |
$dbi->apply_filter( |
|
2150 | ||
2151 |
); |
|
2152 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2153 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
2154 |
$dbi->execute($create_table1); |
test cleanup in progress
|
2155 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
2156 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
|
2157 |
$dbi->apply_filter($table1, $key2, |
|
test cleanup
|
2158 |
{in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }}); |
test cleanup in progress
|
2159 |
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all; |
2160 |
is_deeply($rows, [{$key1 => 1, $key2 => 6}]); |
|
test cleanup
|
2161 | |
2162 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2163 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
2164 |
$dbi->execute($create_table1); |
test cleanup in progress
|
2165 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
2166 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
|
2167 |
$dbi->apply_filter($table1, $key2, {}); |
|
2168 |
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all; |
|
2169 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
|
test cleanup
|
2170 | |
2171 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2172 |
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})}; |
test cleanup
|
2173 |
like($@, qr/not registered/); |
test cleanup in progress
|
2174 |
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})}; |
test cleanup
|
2175 |
like($@, qr/not registered/); |
2176 |
$dbi->method({one => sub { 1 }}); |
|
2177 |
is($dbi->one, 1); |
|
2178 | ||
2179 |
eval{DBIx::Custom->connect(dsn => undef)}; |
|
2180 |
like($@, qr/_connect/); |
|
2181 | ||
2182 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2183 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
2184 |
$dbi->execute($create_table1); |
2185 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
test cleanup in progress
|
2186 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, |
2187 |
filter => {$key1 => 'twice'}); |
|
2188 |
$row = $dbi->select(table => $table1)->one; |
|
2189 |
is_deeply($row, {$key1 => 2, $key2 => 2}); |
|
2190 |
eval {$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, |
|
2191 |
filter => {$key1 => 'no'}) }; |
|
test cleanup
|
2192 |
like($@, qr//); |
2193 | ||
2194 |
$dbi->register_filter(one => sub { }); |
|
2195 |
$dbi->default_fetch_filter('one'); |
|
2196 |
ok($dbi->default_fetch_filter); |
|
2197 |
$dbi->default_bind_filter('one'); |
|
2198 |
ok($dbi->default_bind_filter); |
|
2199 |
eval{$dbi->default_fetch_filter('no')}; |
|
2200 |
like($@, qr/not registered/); |
|
2201 |
eval{$dbi->default_bind_filter('no')}; |
|
2202 |
like($@, qr/not registered/); |
|
2203 |
$dbi->default_bind_filter(undef); |
|
2204 |
ok(!defined $dbi->default_bind_filter); |
|
2205 |
$dbi->default_fetch_filter(undef); |
|
2206 |
ok(!defined $dbi->default_fetch_filter); |
|
test cleanup in progress
|
2207 |
eval {$dbi->execute("select * from $table1 {} {= author") }; |
test cleanup
|
2208 |
like($@, qr/Tag not finished/); |
2209 | ||
2210 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2211 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
2212 |
$dbi->execute($create_table1); |
2213 |
$dbi->register_filter(one => sub { 1 }); |
|
test cleanup in progress
|
2214 |
$result = $dbi->select(table => $table1); |
2215 |
eval {$result->filter($key1 => 'no')}; |
|
test cleanup
|
2216 |
like($@, qr/not registered/); |
test cleanup in progress
|
2217 |
eval {$result->end_filter($key1 => 'no')}; |
test cleanup
|
2218 |
like($@, qr/not registered/); |
2219 |
$result->default_filter(undef); |
|
2220 |
ok(!defined $result->default_filter); |
|
2221 |
$result->default_filter('one'); |
|
2222 |
is($result->default_filter->(), 1); |
|
2223 | ||
2224 |
test 'dbi_option'; |
|
2225 |
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1}); |
|
2226 |
ok($dbi->dbh->{PrintError}); |
|
2227 |
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1}); |
|
2228 |
ok($dbi->dbh->{PrintError}); |
|
2229 | ||
2230 |
test 'DBIx::Custom::Result stash()'; |
|
2231 |
$result = DBIx::Custom::Result->new; |
|
2232 |
is_deeply($result->stash, {}, 'default'); |
|
2233 |
$result->stash->{foo} = 1; |
|
2234 |
is($result->stash->{foo}, 1, 'get and set'); |
|
test cleanup
|
2235 | |
cleanup test
|
2236 |
test 'delete_at'; |
2237 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2238 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2239 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2240 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
cleanup test
|
2241 |
$dbi->delete_at( |
test cleanup in progress
|
2242 |
table => $table1, |
2243 |
primary_key => [$key1, $key2], |
|
cleanup test
|
2244 |
where => [1, 2], |
2245 |
); |
|
test cleanup in progress
|
2246 |
is_deeply($dbi->select(table => $table1)->all, []); |
cleanup test
|
2247 | |
test cleanup in progress
|
2248 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
cleanup test
|
2249 |
$dbi->delete_at( |
test cleanup in progress
|
2250 |
table => $table1, |
2251 |
primary_key => $key1, |
|
cleanup test
|
2252 |
where => 1, |
2253 |
); |
|
test cleanup in progress
|
2254 |
is_deeply($dbi->select(table => $table1)->all, []); |
cleanup test
|
2255 | |
2256 |
test 'insert_at'; |
|
2257 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2258 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2259 |
$dbi->execute($create_table1_2); |
2260 |
$dbi->insert_at( |
|
test cleanup in progress
|
2261 |
primary_key => [$key1, $key2], |
2262 |
table => $table1, |
|
cleanup test
|
2263 |
where => [1, 2], |
test cleanup in progress
|
2264 |
param => {$key3 => 3} |
cleanup test
|
2265 |
); |
test cleanup in progress
|
2266 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2267 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2268 |
is($dbi->select(table => $table1)->one->{$key3}, 3); |
|
cleanup test
|
2269 | |
test cleanup in progress
|
2270 |
$dbi->delete_all(table => $table1); |
2271 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
|
cleanup test
|
2272 |
$dbi->insert_at( |
test cleanup in progress
|
2273 |
primary_key => $key1, |
2274 |
table => $table1, |
|
cleanup test
|
2275 |
where => 1, |
test cleanup in progress
|
2276 |
param => {$key2 => 2, $key3 => 3} |
cleanup test
|
2277 |
); |
2278 | ||
test cleanup in progress
|
2279 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2280 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2281 |
is($dbi->select(table => $table1)->one->{$key3}, 3); |
|
cleanup test
|
2282 | |
2283 |
eval { |
|
2284 |
$dbi->insert_at( |
|
test cleanup in progress
|
2285 |
table => $table1, |
2286 |
primary_key => [$key1, $key2], |
|
cleanup test
|
2287 |
where => {}, |
test cleanup in progress
|
2288 |
param => {$key1 => 1, $key2 => 2, $key3 => 3}, |
cleanup test
|
2289 |
); |
2290 |
}; |
|
2291 |
like($@, qr/must be/); |
|
2292 | ||
2293 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2294 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2295 |
$dbi->execute($create_table1_2); |
2296 |
$dbi->insert_at( |
|
test cleanup in progress
|
2297 |
{$key3 => 3}, |
2298 |
primary_key => [$key1, $key2], |
|
2299 |
table => $table1, |
|
cleanup test
|
2300 |
where => [1, 2], |
2301 |
); |
|
test cleanup in progress
|
2302 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2303 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2304 |
is($dbi->select(table => $table1)->one->{$key3}, 3); |
|
cleanup test
|
2305 | |
2306 |
test 'update_at'; |
|
2307 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2308 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2309 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2310 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
cleanup test
|
2311 |
$dbi->update_at( |
test cleanup in progress
|
2312 |
table => $table1, |
2313 |
primary_key => [$key1, $key2], |
|
cleanup test
|
2314 |
where => [1, 2], |
test cleanup in progress
|
2315 |
param => {$key3 => 4} |
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}, 4); |
|
cleanup test
|
2320 | |
test cleanup in progress
|
2321 |
$dbi->delete_all(table => $table1); |
2322 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
|
cleanup test
|
2323 |
$dbi->update_at( |
test cleanup in progress
|
2324 |
table => $table1, |
2325 |
primary_key => $key1, |
|
cleanup test
|
2326 |
where => 1, |
test cleanup in progress
|
2327 |
param => {$key3 => 4} |
cleanup test
|
2328 |
); |
test cleanup in progress
|
2329 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2330 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2331 |
is($dbi->select(table => $table1)->one->{$key3}, 4); |
|
cleanup test
|
2332 | |
2333 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2334 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2335 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2336 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
cleanup test
|
2337 |
$dbi->update_at( |
test cleanup in progress
|
2338 |
{$key3 => 4}, |
2339 |
table => $table1, |
|
2340 |
primary_key => [$key1, $key2], |
|
cleanup test
|
2341 |
where => [1, 2] |
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}, 4); |
|
cleanup test
|
2346 | |
2347 |
test 'select_at'; |
|
2348 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2349 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2350 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2351 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
cleanup test
|
2352 |
$result = $dbi->select_at( |
test cleanup in progress
|
2353 |
table => $table1, |
2354 |
primary_key => [$key1, $key2], |
|
cleanup test
|
2355 |
where => [1, 2] |
2356 |
); |
|
2357 |
$row = $result->one; |
|
test cleanup in progress
|
2358 |
is($row->{$key1}, 1); |
2359 |
is($row->{$key2}, 2); |
|
2360 |
is($row->{$key3}, 3); |
|
cleanup test
|
2361 | |
test cleanup in progress
|
2362 |
$dbi->delete_all(table => $table1); |
2363 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
|
cleanup test
|
2364 |
$result = $dbi->select_at( |
test cleanup in progress
|
2365 |
table => $table1, |
2366 |
primary_key => $key1, |
|
cleanup test
|
2367 |
where => 1, |
2368 |
); |
|
2369 |
$row = $result->one; |
|
test cleanup in progress
|
2370 |
is($row->{$key1}, 1); |
2371 |
is($row->{$key2}, 2); |
|
2372 |
is($row->{$key3}, 3); |
|
cleanup test
|
2373 | |
test cleanup in progress
|
2374 |
$dbi->delete_all(table => $table1); |
2375 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
|
cleanup test
|
2376 |
$result = $dbi->select_at( |
test cleanup in progress
|
2377 |
table => $table1, |
2378 |
primary_key => [$key1, $key2], |
|
cleanup test
|
2379 |
where => [1, 2] |
2380 |
); |
|
2381 |
$row = $result->one; |
|
test cleanup in progress
|
2382 |
is($row->{$key1}, 1); |
2383 |
is($row->{$key2}, 2); |
|
2384 |
is($row->{$key3}, 3); |
|
cleanup test
|
2385 | |
2386 |
eval { |
|
2387 |
$result = $dbi->select_at( |
|
test cleanup in progress
|
2388 |
table => $table1, |
2389 |
primary_key => [$key1, $key2], |
|
cleanup test
|
2390 |
where => {}, |
2391 |
); |
|
2392 |
}; |
|
2393 |
like($@, qr/must be/); |
|
2394 | ||
2395 |
eval { |
|
2396 |
$result = $dbi->select_at( |
|
test cleanup in progress
|
2397 |
table => $table1, |
2398 |
primary_key => [$key1, $key2], |
|
cleanup test
|
2399 |
where => [1], |
2400 |
); |
|
2401 |
}; |
|
2402 |
like($@, qr/same/); |
|
2403 | ||
2404 |
eval { |
|
2405 |
$result = $dbi->update_at( |
|
test cleanup in progress
|
2406 |
table => $table1, |
2407 |
primary_key => [$key1, $key2], |
|
cleanup test
|
2408 |
where => {}, |
test cleanup in progress
|
2409 |
param => {$key1 => 1, $key2 => 2}, |
cleanup test
|
2410 |
); |
2411 |
}; |
|
2412 |
like($@, qr/must be/); |
|
2413 | ||
2414 |
eval { |
|
2415 |
$result = $dbi->delete_at( |
|
test cleanup in progress
|
2416 |
table => $table1, |
2417 |
primary_key => [$key1, $key2], |
|
cleanup test
|
2418 |
where => {}, |
2419 |
); |
|
2420 |
}; |
|
2421 |
like($@, qr/must be/); |
|
2422 | ||
2423 |
test 'columns'; |
|
2424 |
use MyDBI1; |
|
2425 |
$dbi = MyDBI1->connect; |
|
test cleanup in progress
|
2426 |
$model = $dbi->model($table1); |
cleanup test
|
2427 | |
2428 | ||
2429 |
test 'model delete_at'; |
|
2430 |
$dbi = MyDBI6->connect; |
|
test cleanup in progress
|
2431 |
eval { $dbi->execute('drop table $table1') }; |
2432 |
eval { $dbi->execute('drop table $table2') }; |
|
2433 |
eval { $dbi->execute('drop table $table3') }; |
|
cleanup test
|
2434 |
$dbi->execute($create_table1_2); |
2435 |
$dbi->execute($create_table2_2); |
|
2436 |
$dbi->execute($create_table3); |
|
test cleanup in progress
|
2437 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
2438 |
$dbi->model($table1)->delete_at(where => [1, 2]); |
|
2439 |
is_deeply($dbi->select(table => $table1)->all, []); |
|
2440 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
|
2441 |
$dbi->model($table1)->delete_at(where => [1, 2]); |
|
2442 |
is_deeply($dbi->select(table => $table1)->all, []); |
|
2443 |
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
|
2444 |
$dbi->model($table3)->delete_at(where => [1, 2]); |
|
2445 |
is_deeply($dbi->select(table => $table3)->all, []); |
|
cleanup test
|
2446 | |
2447 |
test 'model insert_at'; |
|
2448 |
$dbi = MyDBI6->connect; |
|
test cleanup in progress
|
2449 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2450 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2451 |
$dbi->model($table1)->insert_at( |
cleanup test
|
2452 |
where => [1, 2], |
test cleanup in progress
|
2453 |
param => {$key3 => 3} |
cleanup test
|
2454 |
); |
test cleanup in progress
|
2455 |
$result = $dbi->model($table1)->select; |
cleanup test
|
2456 |
$row = $result->one; |
test cleanup in progress
|
2457 |
is($row->{$key1}, 1); |
2458 |
is($row->{$key2}, 2); |
|
2459 |
is($row->{$key3}, 3); |
|
cleanup test
|
2460 | |
2461 |
test 'model update_at'; |
|
2462 |
$dbi = MyDBI6->connect; |
|
test cleanup in progress
|
2463 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2464 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2465 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
2466 |
$dbi->model($table1)->update_at( |
|
cleanup test
|
2467 |
where => [1, 2], |
test cleanup in progress
|
2468 |
param => {$key3 => 4} |
cleanup test
|
2469 |
); |
test cleanup in progress
|
2470 |
$result = $dbi->model($table1)->select; |
cleanup test
|
2471 |
$row = $result->one; |
test cleanup in progress
|
2472 |
is($row->{$key1}, 1); |
2473 |
is($row->{$key2}, 2); |
|
2474 |
is($row->{$key3}, 4); |
|
cleanup test
|
2475 | |
2476 |
test 'model select_at'; |
|
2477 |
$dbi = MyDBI6->connect; |
|
test cleanup in progress
|
2478 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2479 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2480 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
2481 |
$result = $dbi->model($table1)->select_at(where => [1, 2]); |
|
cleanup test
|
2482 |
$row = $result->one; |
test cleanup in progress
|
2483 |
is($row->{$key1}, 1); |
2484 |
is($row->{$key2}, 2); |
|
2485 |
is($row->{$key3}, 3); |
|
cleanup test
|
2486 | |
2487 | ||
2488 |
test 'mycolumn and column'; |
|
2489 |
$dbi = MyDBI7->connect; |
|
test cleanup in progress
|
2490 |
eval { $dbi->execute('drop table $table1') }; |
2491 |
eval { $dbi->execute('drop table $table2') }; |
|
cleanup test
|
2492 |
$dbi->execute($create_table1); |
2493 |
$dbi->execute($create_table2); |
|
2494 |
$dbi->separator('__'); |
|
2495 |
$dbi->setup_model; |
|
test cleanup in progress
|
2496 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
2497 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3}); |
|
2498 |
$model = $dbi->model($table1); |
|
cleanup test
|
2499 |
$result = $model->select( |
test cleanup in progress
|
2500 |
column => [$model->mycolumn, $model->column($table2)], |
2501 |
where => {'$table1.$key1' => 1} |
|
cleanup test
|
2502 |
); |
2503 |
is_deeply($result->one, |
|
test cleanup in progress
|
2504 |
{$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3}); |
test cleanup
|
2505 | |
test cleanup
|
2506 |
test 'insert_param'; |
2507 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2508 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
2509 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2510 |
$param = {$key1 => 1, $key2 => 2}; |
test cleanup
|
2511 |
$insert_param = $dbi->insert_param($param); |
2512 |
$sql = <<"EOS"; |
|
test cleanup in progress
|
2513 |
insert into $table1 $insert_param |
test cleanup
|
2514 |
EOS |
test cleanup in progress
|
2515 |
$dbi->execute($sql, param => $param, table => $table1); |
2516 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
|
2517 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
test cleanup
|
2518 | |
2519 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2520 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
2521 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2522 |
$param = {$key1 => 1, $key2 => 2}; |
test cleanup
|
2523 |
$insert_param = $dbi->insert_param($param); |
2524 |
$sql = <<"EOS"; |
|
test cleanup in progress
|
2525 |
insert into $table1 $insert_param |
test cleanup
|
2526 |
EOS |
test cleanup in progress
|
2527 |
$dbi->execute($sql, param => $param, table => $table1); |
2528 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
|
2529 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
test cleanup
|
2530 | |
2531 |
eval { $dbi->insert_param({";" => 1}) }; |
|
2532 |
like($@, qr/not safety/); |
|
test cleanup
|
2533 | |
cleanup test
|
2534 |
test 'mycolumn'; |
2535 |
$dbi = MyDBI8->connect; |
|
test cleanup in progress
|
2536 |
eval { $dbi->execute('drop table $table1') }; |
2537 |
eval { $dbi->execute('drop table $table2') }; |
|
cleanup test
|
2538 |
$dbi->execute($create_table1); |
2539 |
$dbi->execute($create_table2); |
|
2540 |
$dbi->setup_model; |
|
test cleanup in progress
|
2541 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
2542 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3}); |
|
2543 |
$model = $dbi->model($table1); |
|
cleanup test
|
2544 |
$result = $model->select_at( |
2545 |
column => [ |
|
2546 |
$model->mycolumn, |
|
test cleanup in progress
|
2547 |
$model->column($table2) |
cleanup test
|
2548 |
] |
2549 |
); |
|
2550 |
is_deeply($result->one, |
|
test cleanup in progress
|
2551 |
{$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3}); |
cleanup test
|
2552 | |
2553 |
$result = $model->select_at( |
|
2554 |
column => [ |
|
test cleanup in progress
|
2555 |
$model->mycolumn([$key1]), |
2556 |
$model->column($table2 => [$key1]) |
|
cleanup test
|
2557 |
] |
2558 |
); |
|
2559 |
is_deeply($result->one, |
|
test cleanup in progress
|
2560 |
{$key1 => 1, '$table2.$key1' => 1}); |
cleanup test
|
2561 |
$result = $model->select_at( |
2562 |
column => [ |
|
test cleanup in progress
|
2563 |
$model->mycolumn([$key1]), |
2564 |
{$table2 => [$key1]} |
|
cleanup test
|
2565 |
] |
2566 |
); |
|
2567 |
is_deeply($result->one, |
|
test cleanup in progress
|
2568 |
{$key1 => 1, '$table2.$key1' => 1}); |
cleanup test
|
2569 | |
2570 |
$result = $model->select_at( |
|
2571 |
column => [ |
|
test cleanup in progress
|
2572 |
$model->mycolumn([$key1]), |
2573 |
["$table2.$key1", as => "$table2.$key1"] |
|
cleanup test
|
2574 |
] |
2575 |
); |
|
2576 |
is_deeply($result->one, |
|
test cleanup in progress
|
2577 |
{$key1 => 1, '$table2.$key1' => 1}); |
cleanup test
|
2578 | |
2579 |
$result = $model->select_at( |
|
2580 |
column => [ |
|
test cleanup in progress
|
2581 |
$model->mycolumn([$key1]), |
2582 |
["$table2.$key1" => "$table2.$key1"] |
|
cleanup test
|
2583 |
] |
2584 |
); |
|
2585 |
is_deeply($result->one, |
|
test cleanup in progress
|
2586 |
{$key1 => 1, '$table2.$key1' => 1}); |
cleanup test
|
2587 | |
cleanup test
|
2588 |
test 'merge_param'; |
2589 |
$dbi = DBIx::Custom->new; |
|
2590 |
$params = [ |
|
test cleanup in progress
|
2591 |
{$key1 => 1, $key2 => 2, $key3 => 3}, |
2592 |
{$key1 => 1, $key2 => 2}, |
|
2593 |
{$key1 => 1} |
|
cleanup test
|
2594 |
]; |
2595 |
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]); |
|
test cleanup in progress
|
2596 |
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3}); |
cleanup test
|
2597 | |
2598 |
$params = [ |
|
test cleanup in progress
|
2599 |
{$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]}, |
2600 |
{$key1 => [3, 4], $key2 => [2, 3], $key3 => 3} |
|
cleanup test
|
2601 |
]; |
2602 |
$param = $dbi->merge_param($params->[0], $params->[1]); |
|
test cleanup in progress
|
2603 |
is_deeply($param, {$key1 => [1, 2, 3, 4], $key2 => [1, 2, 3], $key3 => [1, 2, 3]}); |
cleanup test
|
2604 | |
2605 |
test 'select() param option'; |
|
2606 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2607 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2608 |
$dbi->execute($create_table1); |
test cleanup in progress
|
2609 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
2610 |
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3}); |
|
2611 |
eval { $dbi->execute('drop table $table2') }; |
|
cleanup test
|
2612 |
$dbi->execute($create_table2); |
test cleanup in progress
|
2613 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4}); |
2614 |
$dbi->insert(table => $table2, param => {$key1 => 2, $key3 => 5}); |
|
cleanup test
|
2615 |
$rows = $dbi->select( |
test cleanup in progress
|
2616 |
table => $table1, |
2617 |
column => "$table1.$key1 as ${table1}_$key1, $key2, $key3", |
|
2618 |
where => {'$table1.$key2' => 3}, |
|
2619 |
join => ["inner join (select * from $table2 where {= $table2.$key3})" . |
|
2620 |
" as $table2 on $table1.$key1 = $table2.$key1"], |
|
2621 |
param => {'$table2.$key3' => 5} |
|
cleanup test
|
2622 |
)->all; |
test cleanup in progress
|
2623 |
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]); |
cleanup test
|
2624 | |
2625 |
test 'select() string where'; |
|
2626 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2627 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2628 |
$dbi->execute($create_table1); |
test cleanup in progress
|
2629 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
2630 |
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3}); |
|
cleanup test
|
2631 |
$rows = $dbi->select( |
test cleanup in progress
|
2632 |
table => $table1, |
2633 |
where => "$key1 = :$key1 and $key2 = :$key2", |
|
2634 |
where_param => {$key1 => 1, $key2 => 2} |
|
cleanup test
|
2635 |
)->all; |
test cleanup in progress
|
2636 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
cleanup test
|
2637 | |
2638 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2639 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2640 |
$dbi->execute($create_table1); |
test cleanup in progress
|
2641 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
2642 |
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3}); |
|
cleanup test
|
2643 |
$rows = $dbi->select( |
test cleanup in progress
|
2644 |
table => $table1, |
cleanup test
|
2645 |
where => [ |
test cleanup in progress
|
2646 |
"$key1 = :$key1 and $key2 = :$key2", |
2647 |
{$key1 => 1, $key2 => 2} |
|
cleanup test
|
2648 |
] |
2649 |
)->all; |
|
test cleanup in progress
|
2650 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
cleanup test
|
2651 | |
2652 |
test 'delete() string where'; |
|
2653 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2654 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2655 |
$dbi->execute($create_table1); |
test cleanup in progress
|
2656 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
2657 |
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3}); |
|
cleanup test
|
2658 |
$dbi->delete( |
test cleanup in progress
|
2659 |
table => $table1, |
2660 |
where => "$key1 = :$key1 and $key2 = :$key2", |
|
2661 |
where_param => {$key1 => 1, $key2 => 2} |
|
cleanup test
|
2662 |
); |
test cleanup in progress
|
2663 |
$rows = $dbi->select(table => $table1)->all; |
2664 |
is_deeply($rows, [{$key1 => 2, $key2 => 3}]); |
|
cleanup test
|
2665 | |
2666 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2667 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2668 |
$dbi->execute($create_table1); |
test cleanup in progress
|
2669 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
2670 |
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3}); |
|
cleanup test
|
2671 |
$dbi->delete( |
test cleanup in progress
|
2672 |
table => $table1, |
cleanup test
|
2673 |
where => [ |
test cleanup in progress
|
2674 |
"$key1 = :$key1 and $key2 = :$key2", |
2675 |
{$key1 => 1, $key2 => 2} |
|
cleanup test
|
2676 |
] |
2677 |
); |
|
test cleanup in progress
|
2678 |
$rows = $dbi->select(table => $table1)->all; |
2679 |
is_deeply($rows, [{$key1 => 2, $key2 => 3}]); |
|
cleanup test
|
2680 | |
2681 | ||
2682 |
test 'update() string where'; |
|
2683 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2684 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2685 |
$dbi->execute($create_table1); |
test cleanup in progress
|
2686 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
cleanup test
|
2687 |
$dbi->update( |
test cleanup in progress
|
2688 |
table => $table1, |
2689 |
param => {$key1 => 5}, |
|
2690 |
where => "$key1 = :$key1 and $key2 = :$key2", |
|
2691 |
where_param => {$key1 => 1, $key2 => 2} |
|
cleanup test
|
2692 |
); |
test cleanup in progress
|
2693 |
$rows = $dbi->select(table => $table1)->all; |
2694 |
is_deeply($rows, [{$key1 => 5, $key2 => 2}]); |
|
cleanup test
|
2695 | |
2696 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2697 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2698 |
$dbi->execute($create_table1); |
test cleanup in progress
|
2699 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
cleanup test
|
2700 |
$dbi->update( |
test cleanup in progress
|
2701 |
table => $table1, |
2702 |
param => {$key1 => 5}, |
|
cleanup test
|
2703 |
where => [ |
test cleanup in progress
|
2704 |
"$key1 = :$key1 and $key2 = :$key2", |
2705 |
{$key1 => 1, $key2 => 2} |
|
cleanup test
|
2706 |
] |
2707 |
); |
|
test cleanup in progress
|
2708 |
$rows = $dbi->select(table => $table1)->all; |
2709 |
is_deeply($rows, [{$key1 => 5, $key2 => 2}]); |
|
cleanup test
|
2710 | |
2711 |
test 'insert id and primary_key option'; |
|
2712 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2713 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2714 |
$dbi->execute($create_table1_2); |
2715 |
$dbi->insert( |
|
test cleanup in progress
|
2716 |
primary_key => [$key1, $key2], |
2717 |
table => $table1, |
|
cleanup test
|
2718 |
id => [1, 2], |
test cleanup in progress
|
2719 |
param => {$key3 => 3} |
cleanup test
|
2720 |
); |
test cleanup in progress
|
2721 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2722 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2723 |
is($dbi->select(table => $table1)->one->{$key3}, 3); |
|
cleanup test
|
2724 | |
test cleanup in progress
|
2725 |
$dbi->delete_all(table => $table1); |
cleanup test
|
2726 |
$dbi->insert( |
test cleanup in progress
|
2727 |
primary_key => $key1, |
2728 |
table => $table1, |
|
cleanup test
|
2729 |
id => 0, |
test cleanup in progress
|
2730 |
param => {$key2 => 2, $key3 => 3} |
cleanup test
|
2731 |
); |
2732 | ||
test cleanup in progress
|
2733 |
is($dbi->select(table => $table1)->one->{$key1}, 0); |
2734 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2735 |
is($dbi->select(table => $table1)->one->{$key3}, 3); |
|
cleanup test
|
2736 | |
2737 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2738 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2739 |
$dbi->execute($create_table1_2); |
2740 |
$dbi->insert( |
|
test cleanup in progress
|
2741 |
{$key3 => 3}, |
2742 |
primary_key => [$key1, $key2], |
|
2743 |
table => $table1, |
|
cleanup test
|
2744 |
id => [1, 2], |
2745 |
); |
|
test cleanup in progress
|
2746 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2747 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2748 |
is($dbi->select(table => $table1)->one->{$key3}, 3); |
|
test cleanup
|
2749 | |
cleanup test
|
2750 |
test 'model insert id and primary_key option'; |
2751 |
$dbi = MyDBI6->connect; |
|
test cleanup in progress
|
2752 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2753 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2754 |
$dbi->model($table1)->insert( |
cleanup test
|
2755 |
id => [1, 2], |
test cleanup in progress
|
2756 |
param => {$key3 => 3} |
cleanup test
|
2757 |
); |
test cleanup in progress
|
2758 |
$result = $dbi->model($table1)->select; |
cleanup test
|
2759 |
$row = $result->one; |
test cleanup in progress
|
2760 |
is($row->{$key1}, 1); |
2761 |
is($row->{$key2}, 2); |
|
2762 |
is($row->{$key3}, 3); |
|
cleanup test
|
2763 | |
2764 |
$dbi = MyDBI6->connect; |
|
test cleanup in progress
|
2765 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2766 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2767 |
$dbi->model($table1)->insert( |
2768 |
{$key3 => 3}, |
|
cleanup test
|
2769 |
id => [1, 2] |
2770 |
); |
|
test cleanup in progress
|
2771 |
$result = $dbi->model($table1)->select; |
cleanup test
|
2772 |
$row = $result->one; |
test cleanup in progress
|
2773 |
is($row->{$key1}, 1); |
2774 |
is($row->{$key2}, 2); |
|
2775 |
is($row->{$key3}, 3); |
|
cleanup test
|
2776 | |
2777 |
test 'update and id option'; |
|
2778 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2779 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2780 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2781 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
cleanup test
|
2782 |
$dbi->update( |
test cleanup in progress
|
2783 |
table => $table1, |
2784 |
primary_key => [$key1, $key2], |
|
cleanup test
|
2785 |
id => [1, 2], |
test cleanup in progress
|
2786 |
param => {$key3 => 4} |
cleanup test
|
2787 |
); |
test cleanup in progress
|
2788 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2789 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2790 |
is($dbi->select(table => $table1)->one->{$key3}, 4); |
|
cleanup test
|
2791 | |
test cleanup in progress
|
2792 |
$dbi->delete_all(table => $table1); |
2793 |
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3}); |
|
cleanup test
|
2794 |
$dbi->update( |
test cleanup in progress
|
2795 |
table => $table1, |
2796 |
primary_key => $key1, |
|
cleanup test
|
2797 |
id => 0, |
test cleanup in progress
|
2798 |
param => {$key3 => 4} |
cleanup test
|
2799 |
); |
test cleanup in progress
|
2800 |
is($dbi->select(table => $table1)->one->{$key1}, 0); |
2801 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2802 |
is($dbi->select(table => $table1)->one->{$key3}, 4); |
|
cleanup test
|
2803 | |
2804 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2805 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2806 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2807 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
cleanup test
|
2808 |
$dbi->update( |
test cleanup in progress
|
2809 |
{$key3 => 4}, |
2810 |
table => $table1, |
|
2811 |
primary_key => [$key1, $key2], |
|
cleanup test
|
2812 |
id => [1, 2] |
2813 |
); |
|
test cleanup in progress
|
2814 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2815 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
|
2816 |
is($dbi->select(table => $table1)->one->{$key3}, 4); |
|
cleanup test
|
2817 | |
2818 | ||
2819 |
test 'model update and id option'; |
|
2820 |
$dbi = MyDBI6->connect; |
|
test cleanup in progress
|
2821 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2822 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2823 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
2824 |
$dbi->model($table1)->update( |
|
cleanup test
|
2825 |
id => [1, 2], |
test cleanup in progress
|
2826 |
param => {$key3 => 4} |
cleanup test
|
2827 |
); |
test cleanup in progress
|
2828 |
$result = $dbi->model($table1)->select; |
cleanup test
|
2829 |
$row = $result->one; |
test cleanup in progress
|
2830 |
is($row->{$key1}, 1); |
2831 |
is($row->{$key2}, 2); |
|
2832 |
is($row->{$key3}, 4); |
|
cleanup test
|
2833 | |
2834 | ||
2835 |
test 'delete and id option'; |
|
2836 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2837 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2838 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2839 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
cleanup test
|
2840 |
$dbi->delete( |
test cleanup in progress
|
2841 |
table => $table1, |
2842 |
primary_key => [$key1, $key2], |
|
cleanup test
|
2843 |
id => [1, 2], |
2844 |
); |
|
test cleanup in progress
|
2845 |
is_deeply($dbi->select(table => $table1)->all, []); |
cleanup test
|
2846 | |
test cleanup in progress
|
2847 |
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3}); |
cleanup test
|
2848 |
$dbi->delete( |
test cleanup in progress
|
2849 |
table => $table1, |
2850 |
primary_key => $key1, |
|
cleanup test
|
2851 |
id => 0, |
2852 |
); |
|
test cleanup in progress
|
2853 |
is_deeply($dbi->select(table => $table1)->all, []); |
cleanup test
|
2854 | |
2855 | ||
2856 |
test 'model delete and id option'; |
|
2857 |
$dbi = MyDBI6->connect; |
|
test cleanup in progress
|
2858 |
eval { $dbi->execute('drop table $table1') }; |
2859 |
eval { $dbi->execute('drop table $table2') }; |
|
2860 |
eval { $dbi->execute('drop table $table3') }; |
|
cleanup test
|
2861 |
$dbi->execute($create_table1_2); |
2862 |
$dbi->execute($create_table2_2); |
|
2863 |
$dbi->execute($create_table3); |
|
test cleanup in progress
|
2864 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
2865 |
$dbi->model($table1)->delete(id => [1, 2]); |
|
2866 |
is_deeply($dbi->select(table => $table1)->all, []); |
|
2867 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
|
2868 |
$dbi->model($table1)->delete(id => [1, 2]); |
|
2869 |
is_deeply($dbi->select(table => $table1)->all, []); |
|
2870 |
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
|
2871 |
$dbi->model($table3)->delete(id => [1, 2]); |
|
2872 |
is_deeply($dbi->select(table => $table3)->all, []); |
|
cleanup test
|
2873 | |
2874 | ||
2875 |
test 'select and id option'; |
|
2876 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2877 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2878 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2879 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
cleanup test
|
2880 |
$result = $dbi->select( |
test cleanup in progress
|
2881 |
table => $table1, |
2882 |
primary_key => [$key1, $key2], |
|
cleanup test
|
2883 |
id => [1, 2] |
2884 |
); |
|
2885 |
$row = $result->one; |
|
test cleanup in progress
|
2886 |
is($row->{$key1}, 1); |
2887 |
is($row->{$key2}, 2); |
|
2888 |
is($row->{$key3}, 3); |
|
cleanup test
|
2889 | |
test cleanup in progress
|
2890 |
$dbi->delete_all(table => $table1); |
2891 |
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3}); |
|
cleanup test
|
2892 |
$result = $dbi->select( |
test cleanup in progress
|
2893 |
table => $table1, |
2894 |
primary_key => $key1, |
|
cleanup test
|
2895 |
id => 0, |
2896 |
); |
|
2897 |
$row = $result->one; |
|
test cleanup in progress
|
2898 |
is($row->{$key1}, 0); |
2899 |
is($row->{$key2}, 2); |
|
2900 |
is($row->{$key3}, 3); |
|
cleanup test
|
2901 | |
test cleanup in progress
|
2902 |
$dbi->delete_all(table => $table1); |
2903 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
|
cleanup test
|
2904 |
$result = $dbi->select( |
test cleanup in progress
|
2905 |
table => $table1, |
2906 |
primary_key => [$key1, $key2], |
|
cleanup test
|
2907 |
id => [1, 2] |
2908 |
); |
|
2909 |
$row = $result->one; |
|
test cleanup in progress
|
2910 |
is($row->{$key1}, 1); |
2911 |
is($row->{$key2}, 2); |
|
2912 |
is($row->{$key3}, 3); |
|
cleanup test
|
2913 | |
2914 | ||
2915 |
test 'model select_at'; |
|
2916 |
$dbi = MyDBI6->connect; |
|
test cleanup in progress
|
2917 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
2918 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
2919 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3}); |
2920 |
$result = $dbi->model($table1)->select(id => [1, 2]); |
|
cleanup test
|
2921 |
$row = $result->one; |
test cleanup in progress
|
2922 |
is($row->{$key1}, 1); |
2923 |
is($row->{$key2}, 2); |
|
2924 |
is($row->{$key3}, 3); |
|
cleanup test
|
2925 | |
2926 |
test 'column separator is default .'; |
|
2927 |
$dbi = MyDBI7->connect; |
|
test cleanup in progress
|
2928 |
eval { $dbi->execute('drop table $table1') }; |
2929 |
eval { $dbi->execute('drop table $table2') }; |
|
cleanup test
|
2930 |
$dbi->execute($create_table1); |
2931 |
$dbi->execute($create_table2); |
|
2932 |
$dbi->setup_model; |
|
test cleanup in progress
|
2933 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
2934 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3}); |
|
2935 |
$model = $dbi->model($table1); |
|
cleanup test
|
2936 |
$result = $model->select( |
test cleanup in progress
|
2937 |
column => [$model->column($table2)], |
2938 |
where => {'$table1.$key1' => 1} |
|
cleanup test
|
2939 |
); |
2940 |
is_deeply($result->one, |
|
test cleanup in progress
|
2941 |
{"$table2.$key1" => 1, "$table2.$key3" => 3}); |
cleanup test
|
2942 | |
2943 |
$result = $model->select( |
|
test cleanup in progress
|
2944 |
column => [$model->column($table2 => [qw/$key1 $key3/])], |
2945 |
where => {'$table1.$key1' => 1} |
|
cleanup test
|
2946 |
); |
2947 |
is_deeply($result->one, |
|
test cleanup in progress
|
2948 |
{"$table2.$key1" => 1, "$table2.$key3" => 3}); |
test cleanup
|
2949 | |
cleanup test
|
2950 |
test 'separator'; |
2951 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
2952 |
eval { $dbi->execute('drop table $table1') }; |
2953 |
eval { $dbi->execute('drop table $table2') }; |
|
cleanup test
|
2954 |
$dbi->execute($create_table1); |
2955 |
$dbi->execute($create_table2); |
|
test cleanup
|
2956 | |
cleanup test
|
2957 |
$dbi->create_model( |
test cleanup in progress
|
2958 |
table => $table1, |
cleanup test
|
2959 |
join => [ |
test cleanup in progress
|
2960 |
"left outer join $table2 on $table1.$key1 = $table2.$key1" |
cleanup test
|
2961 |
], |
test cleanup in progress
|
2962 |
primary_key => [$key1], |
cleanup test
|
2963 |
); |
2964 |
$model2 = $dbi->create_model( |
|
test cleanup in progress
|
2965 |
table => $table2, |
cleanup test
|
2966 |
); |
2967 |
$dbi->setup_model; |
|
test cleanup in progress
|
2968 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
2969 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3}); |
|
2970 |
$model = $dbi->model($table1); |
|
cleanup test
|
2971 |
$result = $model->select( |
2972 |
column => [ |
|
2973 |
$model->mycolumn, |
|
test cleanup in progress
|
2974 |
{$table2 => [qw/$key1 $key3/]} |
cleanup test
|
2975 |
], |
test cleanup in progress
|
2976 |
where => {'$table1.$key1' => 1} |
cleanup test
|
2977 |
); |
2978 |
is_deeply($result->one, |
|
test cleanup in progress
|
2979 |
{$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3}); |
2980 |
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3}); |
|
test cleanup
|
2981 | |
cleanup test
|
2982 |
$dbi->separator('__'); |
test cleanup in progress
|
2983 |
$model = $dbi->model($table1); |
cleanup test
|
2984 |
$result = $model->select( |
2985 |
column => [ |
|
2986 |
$model->mycolumn, |
|
test cleanup in progress
|
2987 |
{$table2 => [qw/$key1 $key3/]} |
cleanup test
|
2988 |
], |
test cleanup in progress
|
2989 |
where => {'$table1.$key1' => 1} |
cleanup test
|
2990 |
); |
2991 |
is_deeply($result->one, |
|
test cleanup in progress
|
2992 |
{$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3}); |
2993 |
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3}); |
|
test cleanup
|
2994 | |
cleanup test
|
2995 |
$dbi->separator('-'); |
test cleanup in progress
|
2996 |
$model = $dbi->model($table1); |
cleanup test
|
2997 |
$result = $model->select( |
2998 |
column => [ |
|
2999 |
$model->mycolumn, |
|
test cleanup in progress
|
3000 |
{$table2 => [qw/$key1 $key3/]} |
cleanup test
|
3001 |
], |
test cleanup in progress
|
3002 |
where => {'$table1.$key1' => 1} |
cleanup test
|
3003 |
); |
3004 |
is_deeply($result->one, |
|
test cleanup in progress
|
3005 |
{$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3}); |
3006 |
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3}); |
|
test cleanup
|
3007 | |
3008 | ||
cleanup test
|
3009 |
test 'filter_off'; |
3010 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3011 |
eval { $dbi->execute('drop table $table1') }; |
3012 |
eval { $dbi->execute('drop table $table2') }; |
|
cleanup test
|
3013 |
$dbi->execute($create_table1); |
3014 |
$dbi->execute($create_table2); |
|
test cleanup
|
3015 | |
cleanup test
|
3016 |
$dbi->create_model( |
test cleanup in progress
|
3017 |
table => $table1, |
cleanup test
|
3018 |
join => [ |
test cleanup in progress
|
3019 |
"left outer join $table2 on $table1.$key1 = $table2.$key1" |
cleanup test
|
3020 |
], |
test cleanup in progress
|
3021 |
primary_key => [$key1], |
cleanup test
|
3022 |
); |
3023 |
$dbi->setup_model; |
|
test cleanup in progress
|
3024 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
3025 |
$model = $dbi->model($table1); |
|
3026 |
$result = $model->select(column => $key1); |
|
3027 |
$result->filter($key1 => sub { $_[0] * 2 }); |
|
3028 |
is_deeply($result->one, {$key1 => 2}); |
|
test cleanup
|
3029 | |
cleanup test
|
3030 |
test 'available_datetype'; |
3031 |
$dbi = DBIx::Custom->connect; |
|
3032 |
ok($dbi->can('available_datatype')); |
|
test cleanup
|
3033 | |
3034 | ||
cleanup test
|
3035 |
test 'select prefix option'; |
3036 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3037 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
3038 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3039 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
3040 |
$rows = $dbi->select(prefix => '$key1,', column => $key2, table => $table1)->all; |
|
3041 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table"); |
|
test cleanup
|
3042 | |
cleanup test
|
3043 |
test 'map_param'; |
3044 |
$dbi = DBIx::Custom->connect; |
|
3045 |
$param = $dbi->map_param( |
|
3046 |
{id => 1, author => 'Ken', price => 1900}, |
|
test cleanup in progress
|
3047 |
id => '$table1.id', |
3048 |
author => ['$table1.author', sub { '%' . $_[0] . '%' }], |
|
3049 |
price => ['$table1.price', {if => sub { $_[0] eq 1900 }}] |
|
cleanup test
|
3050 |
); |
test cleanup in progress
|
3051 |
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%', |
3052 |
'$table1.price' => 1900}); |
|
test cleanup
|
3053 | |
cleanup test
|
3054 |
$param = $dbi->map_param( |
3055 |
{id => 0, author => 0, price => 0}, |
|
test cleanup in progress
|
3056 |
id => '$table1.id', |
3057 |
author => ['$table1.author', sub { '%' . $_[0] . '%' }], |
|
3058 |
price => ['$table1.price', sub { '%' . $_[0] . '%' }, |
|
cleanup test
|
3059 |
{if => sub { $_[0] eq 0 }}] |
3060 |
); |
|
test cleanup in progress
|
3061 |
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'}); |
test cleanup
|
3062 | |
cleanup test
|
3063 |
$param = $dbi->map_param( |
3064 |
{id => '', author => '', price => ''}, |
|
test cleanup in progress
|
3065 |
id => '$table1.id', |
3066 |
author => ['$table1.author', sub { '%' . $_[0] . '%' }], |
|
3067 |
price => ['$table1.price', sub { '%' . $_[0] . '%' }, |
|
cleanup test
|
3068 |
{if => sub { $_[0] eq 1 }}] |
3069 |
); |
|
3070 |
is_deeply($param, {}); |
|
test cleanup
|
3071 | |
cleanup test
|
3072 |
$param = $dbi->map_param( |
3073 |
{id => undef, author => undef, price => undef}, |
|
test cleanup in progress
|
3074 |
id => '$table1.id', |
3075 |
price => ['$table1.price', {if => 'exists'}] |
|
cleanup test
|
3076 |
); |
test cleanup in progress
|
3077 |
is_deeply($param, {'$table1.price' => undef}); |
test cleanup
|
3078 | |
cleanup test
|
3079 |
$param = $dbi->map_param( |
3080 |
{price => 'a'}, |
|
test cleanup in progress
|
3081 |
id => ['$table1.id', {if => 'exists'}], |
3082 |
price => ['$table1.price', sub { '%' . $_[0] }, {if => 'exists'}] |
|
cleanup test
|
3083 |
); |
test cleanup in progress
|
3084 |
is_deeply($param, {'$table1.price' => '%a'}); |
test cleanup
|
3085 | |
test cleanup
|
3086 |
test 'order'; |
3087 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3088 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
3089 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3090 |
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1); |
3091 |
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1); |
|
3092 |
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1); |
|
3093 |
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1); |
|
test cleanup
|
3094 |
my $order = $dbi->order; |
test cleanup in progress
|
3095 |
$order->prepend($key1, '$key2 desc'); |
3096 |
$result = $dbi->select(table => $table1, append => "$order"); |
|
3097 |
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}, |
|
3098 |
{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]); |
|
3099 |
$order->prepend('$key1 desc'); |
|
3100 |
$result = $dbi->select(table => $table1, append => "$order"); |
|
3101 |
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}, |
|
3102 |
{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]); |
|
test cleanup
|
3103 | |
3104 |
$order = $dbi->order; |
|
test cleanup in progress
|
3105 |
$order->prepend(['$table1-$key1'], [qw/$table1-$key2 desc/]); |
3106 |
$result = $dbi->select(table => $table1, |
|
3107 |
column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]], |
|
test cleanup
|
3108 |
append => "$order"); |
test cleanup in progress
|
3109 |
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3}, |
3110 |
{"$table1-$key1" => 1, "$table1-$key2" => 1}, |
|
3111 |
{"$table1-$key1" => 2, "$table1-$key2" => 4}, |
|
3112 |
{"$table1-$key1" => 2, "$table1-$key2" => 2}]); |
|
test cleanup
|
3113 | |
3114 |
test 'tag_parse'; |
|
3115 |
$dbi = DBIx::Custom->connect; |
|
3116 |
$dbi->tag_parse(0); |
|
test cleanup in progress
|
3117 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
3118 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3119 |
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1); |
3120 |
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})}; |
|
test cleanup
|
3121 |
ok($@); |
3122 | ||
3123 |
test 'last_sql'; |
|
3124 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3125 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
3126 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3127 |
$dbi->execute('select * from $table1'); |
3128 |
is($dbi->last_sql, "select * from $table1;"); |
|
test cleanup
|
3129 | |
3130 |
eval{$dbi->execute("aaa")}; |
|
3131 |
is($dbi->last_sql, 'aaa;'); |
|
3132 | ||
3133 |
test 'DBIx::Custom header'; |
|
3134 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3135 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
3136 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3137 |
$result = $dbi->execute("select $key1 as h1, $key2 as h2 from $table1"); |
test cleanup
|
3138 |
is_deeply($result->header, [qw/h1 h2/]); |
3139 | ||
3140 |
test 'Named placeholder :name(operater) syntax'; |
|
test cleanup in progress
|
3141 |
$dbi->execute('drop table $table1'); |
test cleanup
|
3142 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
3143 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
3144 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
test cleanup
|
3145 | |
test cleanup in progress
|
3146 |
$source = "select * from $table1 where :${key1}{=} and :${key2}{=}"; |
3147 |
$result = $dbi->execute($source, param => {$key1 => 1, $key2 => 2}); |
|
test cleanup
|
3148 |
$rows = $result->all; |
test cleanup in progress
|
3149 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]); |
test cleanup
|
3150 | |
test cleanup in progress
|
3151 |
$source = "select * from $table1 where :${key1}{ = } and :${key2}{=}"; |
3152 |
$result = $dbi->execute($source, param => {$key1 => 1, $key2 => 2}); |
|
test cleanup
|
3153 |
$rows = $result->all; |
test cleanup in progress
|
3154 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]); |
test cleanup
|
3155 | |
test cleanup in progress
|
3156 |
$source = "select * from $table1 where :${key1}{<} and :${key2}{=}"; |
3157 |
$result = $dbi->execute($source, param => {$key1 => 5, $key2 => 2}); |
|
test cleanup
|
3158 |
$rows = $result->all; |
test cleanup in progress
|
3159 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]); |
test cleanup
|
3160 | |
test cleanup in progress
|
3161 |
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}"; |
test cleanup
|
3162 |
$result = $dbi->execute( |
3163 |
$source, |
|
test cleanup in progress
|
3164 |
param => {"$table1.$key1" => 1, "$table1.$key2" => 1}, |
3165 |
filter => {'$table1.$key2' => sub { $_[0] * 2 }} |
|
test cleanup
|
3166 |
); |
3167 |
$rows = $result->all; |
|
test cleanup in progress
|
3168 |
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]); |
test cleanup
|
3169 | |
3170 |
test 'high perfomance way'; |
|
test cleanup in progress
|
3171 |
$dbi->execute('drop table $table1'); |
test cleanup
|
3172 |
$dbi->execute($create_table1_highperformance); |
3173 |
$rows = [ |
|
test cleanup in progress
|
3174 |
{$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7}, |
3175 |
{$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8}, |
|
test cleanup
|
3176 |
]; |
3177 |
{ |
|
3178 |
my $query; |
|
3179 |
foreach my $row (@$rows) { |
|
test cleanup in progress
|
3180 |
$query ||= $dbi->insert($row, table => $table1, query => 1); |
3181 |
$dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }}); |
|
test cleanup
|
3182 |
} |
test cleanup in progress
|
3183 |
is_deeply($dbi->select(table => $table1)->all, |
test cleanup
|
3184 |
[ |
test cleanup in progress
|
3185 |
{$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7}, |
3186 |
{$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8}, |
|
test cleanup
|
3187 |
] |
3188 |
); |
|
3189 |
} |
|
3190 | ||
test cleanup in progress
|
3191 |
$dbi->execute('drop table $table1'); |
test cleanup
|
3192 |
$dbi->execute($create_table1_highperformance); |
3193 |
$rows = [ |
|
test cleanup in progress
|
3194 |
{$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7}, |
3195 |
{$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8}, |
|
test cleanup
|
3196 |
]; |
3197 |
{ |
|
3198 |
my $query; |
|
3199 |
my $sth; |
|
3200 |
foreach my $row (@$rows) { |
|
test cleanup in progress
|
3201 |
$query ||= $dbi->insert($row, table => $table1, query => 1); |
test cleanup
|
3202 |
$sth ||= $query->sth; |
3203 |
$sth->execute(map { $row->{$_} } sort keys %$row); |
|
3204 |
} |
|
test cleanup in progress
|
3205 |
is_deeply($dbi->select(table => $table1)->all, |
test cleanup
|
3206 |
[ |
test cleanup in progress
|
3207 |
{$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7}, |
3208 |
{$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8}, |
|
test cleanup
|
3209 |
] |
3210 |
); |
|
3211 |
} |
|
3212 | ||
3213 |
test 'result'; |
|
3214 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3215 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
3216 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3217 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
3218 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup
|
3219 | |
test cleanup in progress
|
3220 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3221 |
@rows = (); |
3222 |
while (my $row = $result->fetch) { |
|
3223 |
push @rows, [@$row]; |
|
3224 |
} |
|
3225 |
is_deeply(\@rows, [[1, 2], [3, 4]]); |
|
3226 | ||
test cleanup in progress
|
3227 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3228 |
@rows = (); |
3229 |
while (my $row = $result->fetch_hash) { |
|
3230 |
push @rows, {%$row}; |
|
3231 |
} |
|
test cleanup in progress
|
3232 |
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
3233 | |
3234 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3235 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
3236 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3237 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
3238 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup
|
3239 | |
3240 |
test 'fetch_all'; |
|
test cleanup in progress
|
3241 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3242 |
$rows = $result->fetch_all; |
3243 |
is_deeply($rows, [[1, 2], [3, 4]]); |
|
3244 | ||
test cleanup in progress
|
3245 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3246 |
$rows = $result->fetch_hash_all; |
test cleanup in progress
|
3247 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
3248 | |
test cleanup in progress
|
3249 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3250 |
$result->dbi->filters({three_times => sub { $_[0] * 3}}); |
test cleanup in progress
|
3251 |
$result->filter({$key1 => 'three_times'}); |
test cleanup
|
3252 | |
3253 |
$rows = $result->fetch_all; |
|
3254 |
is_deeply($rows, [[3, 2], [9, 4]], "array"); |
|
3255 | ||
test cleanup in progress
|
3256 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3257 |
$result->dbi->filters({three_times => sub { $_[0] * 3}}); |
test cleanup in progress
|
3258 |
$result->filter({$key1 => 'three_times'}); |
test cleanup
|
3259 |
$rows = $result->fetch_hash_all; |
test cleanup in progress
|
3260 |
is_deeply($rows, [{$key1 => 3, $key2 => 2}, {$key1 => 9, $key2 => 4}], "hash"); |
test cleanup
|
3261 | |
3262 |
test "query_builder"; |
|
3263 |
$datas = [ |
|
3264 |
# Basic tests |
|
3265 |
{ name => 'placeholder basic', |
|
3266 |
source => "a {? k1} b {= k2} {<> k3} {> k4} {< k5} {>= k6} {<= k7} {like k8}", , |
|
3267 |
sql_expected => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?;", |
|
3268 |
columns_expected => [qw/k1 k2 k3 k4 k5 k6 k7 k8/] |
|
3269 |
}, |
|
3270 |
{ |
|
3271 |
name => 'placeholder in', |
|
3272 |
source => "{in k1 3};", |
|
3273 |
sql_expected => "k1 in (?, ?, ?);", |
|
3274 |
columns_expected => [qw/k1 k1 k1/] |
|
3275 |
}, |
|
3276 |
|
|
3277 |
# Table name |
|
3278 |
{ |
|
3279 |
name => 'placeholder with table name', |
|
3280 |
source => "{= a.k1} {= a.k2}", |
|
3281 |
sql_expected => "a.k1 = ? a.k2 = ?;", |
|
3282 |
columns_expected => [qw/a.k1 a.k2/] |
|
3283 |
}, |
|
3284 |
{ |
|
3285 |
name => 'placeholder in with table name', |
|
3286 |
source => "{in a.k1 2} {in b.k2 2}", |
|
3287 |
sql_expected => "a.k1 in (?, ?) b.k2 in (?, ?);", |
|
3288 |
columns_expected => [qw/a.k1 a.k1 b.k2 b.k2/] |
|
3289 |
}, |
|
3290 |
{ |
|
3291 |
name => 'not contain tag', |
|
3292 |
source => "aaa", |
|
3293 |
sql_expected => "aaa;", |
|
3294 |
columns_expected => [], |
|
3295 |
} |
|
3296 |
]; |
|
3297 | ||
3298 |
for (my $i = 0; $i < @$datas; $i++) { |
|
3299 |
my $data = $datas->[$i]; |
|
cleanup
|
3300 |
my $dbi = DBIx::Custom->new; |
3301 |
my $builder = $dbi->query_builder; |
|
test cleanup
|
3302 |
my $query = $builder->build_query($data->{source}); |
3303 |
is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql"); |
|
3304 |
is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns"); |
|
3305 |
} |
|
3306 | ||
cleanup
|
3307 |
$dbi = DBIx::Custom->new; |
3308 |
$builder = $dbi->query_builder; |
|
3309 |
$dbi->register_tag( |
|
test cleanup
|
3310 |
p => sub { |
3311 |
my @args = @_; |
|
3312 |
|
|
3313 |
my $expand = "? $args[0] $args[1]"; |
|
3314 |
my $columns = [2]; |
|
3315 |
return [$expand, $columns]; |
|
3316 |
} |
|
3317 |
); |
|
3318 | ||
3319 |
$query = $builder->build_query("{p a b}"); |
|
3320 |
is($query->{sql}, "? a b;", "register_tag sql"); |
|
3321 |
is_deeply($query->{columns}, [2], "register_tag columns"); |
|
3322 | ||
3323 |
eval{$builder->build_query('{? }')}; |
|
3324 |
like($@, qr/\QColumn name must be specified in tag "{? }"/, "? not arguments"); |
|
3325 | ||
3326 |
eval{$builder->build_query("{a }")}; |
|
3327 |
like($@, qr/\QTag "a" is not registered/, "tag not exist"); |
|
3328 | ||
cleanup
|
3329 |
$dbi->register_tag({ |
test cleanup
|
3330 |
q => 'string' |
3331 |
}); |
|
3332 | ||
3333 |
eval{$builder->build_query("{q}", {})}; |
|
3334 |
like($@, qr/Tag "q" must be sub reference/, "tag not code ref"); |
|
3335 | ||
cleanup
|
3336 |
$dbi->register_tag({ |
test cleanup
|
3337 |
r => sub {} |
3338 |
}); |
|
3339 | ||
3340 |
eval{$builder->build_query("{r}")}; |
|
3341 |
like($@, qr/\QTag "r" must return [STRING, ARRAY_REFERENCE]/, "tag return noting"); |
|
3342 | ||
cleanup
|
3343 |
$dbi->register_tag({ |
test cleanup
|
3344 |
s => sub { return ["a", ""]} |
3345 |
}); |
|
3346 | ||
3347 |
eval{$builder->build_query("{s}")}; |
|
3348 |
like($@, qr/\QTag "s" must return [STRING, ARRAY_REFERENCE]/, "tag return not array columns"); |
|
3349 | ||
cleanup
|
3350 |
$dbi->register_tag( |
test cleanup
|
3351 |
t => sub {return ["a", []]} |
3352 |
); |
|
3353 | ||
3354 | ||
cleanup
|
3355 |
$dbi->register_tag( |
test cleanup
|
3356 |
a => sub { |
3357 |
return ["? ? ?", ['']]; |
|
3358 |
} |
|
3359 |
); |
|
3360 |
eval{$builder->build_query("{a}")}; |
|
3361 |
like($@, qr/\QPlaceholder count/, "placeholder count is invalid"); |
|
3362 | ||
3363 | ||
3364 |
test 'Default tag Error case'; |
|
3365 |
eval{$builder->build_query("{= }")}; |
|
3366 |
like($@, qr/Column name must be specified in tag "{= }"/, "basic '=' : key not exist"); |
|
3367 | ||
3368 |
eval{$builder->build_query("{in }")}; |
|
3369 |
like($@, qr/Column name and count of values must be specified in tag "{in }"/, "in : key not exist"); |
|
3370 | ||
3371 |
eval{$builder->build_query("{in a}")}; |
|
3372 |
like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/, |
|
3373 |
"in : key not exist"); |
|
3374 | ||
3375 |
eval{$builder->build_query("{in a r}")}; |
|
3376 |
like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/, |
|
3377 |
"in : key not exist"); |
|
3378 | ||
3379 |
test 'variouse source'; |
|
3380 |
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d;"; |
|
3381 |
$query = $builder->build_query($source); |
|
3382 |
is($query->sql, 'a b = ? c { } { = ? } = ? d;', "basic : 1"); |
|
3383 | ||
3384 |
$source = "abc;"; |
|
3385 |
$query = $builder->build_query($source); |
|
3386 |
is($query->sql, 'abc;', "basic : 2"); |
|
3387 | ||
3388 |
$source = "{= a}"; |
|
3389 |
$query = $builder->build_query($source); |
|
3390 |
is($query->sql, 'a = ?;', "only tag"); |
|
3391 | ||
3392 |
$source = "000;"; |
|
3393 |
$query = $builder->build_query($source); |
|
3394 |
is($query->sql, '000;', "contain 0 value"); |
|
3395 | ||
3396 |
$source = "a {= b} }"; |
|
3397 |
eval{$builder->build_query($source)}; |
|
3398 |
like($@, qr/unexpected "}"/, "error : 1"); |
|
3399 | ||
3400 |
$source = "a {= {}"; |
|
3401 |
eval{$builder->build_query($source)}; |
|
3402 |
like($@, qr/unexpected "{"/, "error : 2"); |
|
3403 | ||
cleanup test
|
3404 |
test 'select() wrap option'; |
3405 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3406 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
3407 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3408 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
3409 |
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3}); |
|
cleanup test
|
3410 |
$rows = $dbi->select( |
test cleanup in progress
|
3411 |
table => $table1, |
3412 |
column => $key1, |
|
3413 |
wrap => ["select * from (', ') as t where $key1 = 1"] |
|
cleanup test
|
3414 |
)->all; |
test cleanup in progress
|
3415 |
is_deeply($rows, [{$key1 => 1}]); |
cleanup test
|
3416 | |
cleanup test
|
3417 |
eval { |
3418 |
$dbi->select( |
|
test cleanup in progress
|
3419 |
table => $table1, |
3420 |
column => $key1, |
|
cleanup test
|
3421 |
wrap => 'select * from (' |
3422 |
) |
|
3423 |
}; |
|
3424 |
like($@, qr/array/); |
|
3425 | ||
added EXPERIMENTAL execute m...
|
3426 |
test 'select() sqlfilter option'; |
3427 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3428 |
eval { $dbi->execute('drop table $table1') }; |
added EXPERIMENTAL execute m...
|
3429 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3430 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
3431 |
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3}); |
|
added EXPERIMENTAL execute m...
|
3432 |
$rows = $dbi->select( |
test cleanup in progress
|
3433 |
table => $table1, |
3434 |
column => $key1, |
|
added EXPERIMENTAL execute m...
|
3435 |
sqlfilter => sub { |
3436 |
my $sql = shift; |
|
test cleanup in progress
|
3437 |
$sql = "select * from ( $sql ) as t where $key1 = 1"; |
added EXPERIMENTAL execute m...
|
3438 |
return $sql; |
3439 |
} |
|
3440 |
)->all; |
|
test cleanup in progress
|
3441 |
is_deeply($rows, [{$key1 => 1}]); |
added EXPERIMENTAL execute m...
|
3442 | |
cleanup test
|
3443 |
test 'dbi method from model'; |
3444 |
$dbi = MyDBI9->connect; |
|
test cleanup in progress
|
3445 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
3446 |
$dbi->execute($create_table1); |
3447 |
$dbi->setup_model; |
|
test cleanup in progress
|
3448 |
$model = $dbi->model($table1); |
3449 |
eval{$model->execute('select * from $table1')}; |
|
cleanup test
|
3450 |
ok(!$@); |
3451 | ||
3452 |
test 'column table option'; |
|
3453 |
$dbi = MyDBI9->connect; |
|
test cleanup in progress
|
3454 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
3455 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3456 |
eval { $dbi->execute('drop table $table2') }; |
cleanup test
|
3457 |
$dbi->execute($create_table2); |
3458 |
$dbi->setup_model; |
|
test cleanup in progress
|
3459 |
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2);"); |
3460 |
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4);"); |
|
3461 |
$model = $dbi->model($table1); |
|
cleanup test
|
3462 |
$result = $model->select( |
3463 |
column => [ |
|
test cleanup in progress
|
3464 |
$model->column($table2, {alias => $table2_alias}) |
cleanup test
|
3465 |
], |
test cleanup in progress
|
3466 |
where => {"$table2_alias.$key3" => 4} |
cleanup test
|
3467 |
); |
3468 |
is_deeply($result->one, |
|
test cleanup in progress
|
3469 |
{"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4}); |
cleanup test
|
3470 | |
3471 |
$dbi->separator('__'); |
|
3472 |
$result = $model->select( |
|
3473 |
column => [ |
|
test cleanup in progress
|
3474 |
$model->column($table2, {alias => $table2_alias}) |
cleanup test
|
3475 |
], |
test cleanup in progress
|
3476 |
where => {"$table2_alias.$key3" => 4} |
cleanup test
|
3477 |
); |
3478 |
is_deeply($result->one, |
|
test cleanup in progress
|
3479 |
{"${table2_alias}__$key1" => 1, "{$table2_alias}__$key3" => 4}); |
cleanup test
|
3480 | |
3481 |
$dbi->separator('-'); |
|
3482 |
$result = $model->select( |
|
3483 |
column => [ |
|
test cleanup in progress
|
3484 |
$model->column($table2, {alias => $table2_alias}) |
cleanup test
|
3485 |
], |
test cleanup in progress
|
3486 |
where => {"$table2_alias.$key3" => 4} |
cleanup test
|
3487 |
); |
3488 |
is_deeply($result->one, |
|
test cleanup in progress
|
3489 |
{"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4}); |
cleanup test
|
3490 | |
3491 |
test 'create_model'; |
|
3492 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3493 |
eval { $dbi->execute('drop table $table1') }; |
3494 |
eval { $dbi->execute('drop table $table2') }; |
|
cleanup test
|
3495 |
$dbi->execute($create_table1); |
3496 |
$dbi->execute($create_table2); |
|
3497 | ||
3498 |
$dbi->create_model( |
|
test cleanup in progress
|
3499 |
table => $table1, |
cleanup test
|
3500 |
join => [ |
test cleanup in progress
|
3501 |
"left outer join $table2 on $table1.$key1 = $table2.$key1" |
cleanup test
|
3502 |
], |
test cleanup in progress
|
3503 |
primary_key => [$key1] |
cleanup test
|
3504 |
); |
3505 |
$model2 = $dbi->create_model( |
|
test cleanup in progress
|
3506 |
table => $table2 |
cleanup test
|
3507 |
); |
3508 |
$dbi->create_model( |
|
test cleanup in progress
|
3509 |
table => $table3, |
cleanup test
|
3510 |
filter => [ |
test cleanup in progress
|
3511 |
$key1 => {in => sub { uc $_[0] }} |
cleanup test
|
3512 |
] |
3513 |
); |
|
3514 |
$dbi->setup_model; |
|
test cleanup in progress
|
3515 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
3516 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3}); |
|
3517 |
$model = $dbi->model($table1); |
|
cleanup test
|
3518 |
$result = $model->select( |
test cleanup in progress
|
3519 |
column => [$model->mycolumn, $model->column($table2)], |
3520 |
where => {'$table1.$key1' => 1} |
|
cleanup test
|
3521 |
); |
3522 |
is_deeply($result->one, |
|
test cleanup in progress
|
3523 |
{$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3}); |
3524 |
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3}); |
|
cleanup test
|
3525 | |
3526 |
test 'model method'; |
|
3527 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3528 |
eval { $dbi->execute('drop table $table2') }; |
cleanup test
|
3529 |
$dbi->execute($create_table2); |
test cleanup in progress
|
3530 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3}); |
cleanup test
|
3531 |
$model = $dbi->create_model( |
test cleanup in progress
|
3532 |
table => $table2 |
cleanup test
|
3533 |
); |
3534 |
$model->method(foo => sub { shift->select(@_) }); |
|
test cleanup in progress
|
3535 |
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3}); |
cleanup test
|
3536 | |
cleanup test
|
3537 |
test 'update_param'; |
3538 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3539 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
3540 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
3541 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
3542 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
cleanup test
|
3543 | |
test cleanup in progress
|
3544 |
$param = {$key2 => 11}; |
cleanup test
|
3545 |
$update_param = $dbi->update_param($param); |
3546 |
$sql = <<"EOS"; |
|
test cleanup in progress
|
3547 |
update $table1 $update_param |
3548 |
where $key1 = 1 |
|
cleanup test
|
3549 |
EOS |
3550 |
$dbi->execute($sql, param => $param); |
|
test cleanup in progress
|
3551 |
$result = $dbi->execute("select * from $table1 order by $key1;", table => $table1); |
cleanup test
|
3552 |
$rows = $result->all; |
test cleanup in progress
|
3553 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
3554 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
cleanup test
|
3555 |
"basic"); |
3556 | ||
3557 | ||
3558 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3559 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
3560 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
3561 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
3562 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
cleanup test
|
3563 | |
test cleanup in progress
|
3564 |
$param = {$key2 => 11, $key3 => 33}; |
cleanup test
|
3565 |
$update_param = $dbi->update_param($param); |
3566 |
$sql = <<"EOS"; |
|
test cleanup in progress
|
3567 |
update $table1 $update_param |
3568 |
where $key1 = 1 |
|
cleanup test
|
3569 |
EOS |
3570 |
$dbi->execute($sql, param => $param); |
|
test cleanup in progress
|
3571 |
$result = $dbi->execute("select * from $table1 order by $key1;", table => $table1); |
cleanup test
|
3572 |
$rows = $result->all; |
test cleanup in progress
|
3573 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5}, |
3574 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
cleanup test
|
3575 |
"basic"); |
3576 | ||
3577 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3578 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
3579 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
3580 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
3581 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
cleanup test
|
3582 | |
test cleanup in progress
|
3583 |
$param = {$key2 => 11, $key3 => 33}; |
cleanup test
|
3584 |
$update_param = $dbi->update_param($param, {no_set => 1}); |
3585 |
$sql = <<"EOS"; |
|
test cleanup in progress
|
3586 |
update $table1 set $update_param |
3587 |
where $key1 = 1 |
|
cleanup test
|
3588 |
EOS |
3589 |
$dbi->execute($sql, param => $param); |
|
test cleanup in progress
|
3590 |
$result = $dbi->execute("select * from $table1 order by $key1;", table => $table1); |
cleanup test
|
3591 |
$rows = $result->all; |
test cleanup in progress
|
3592 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5}, |
3593 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
cleanup test
|
3594 |
"update param no_set"); |
3595 | ||
3596 |
|
|
3597 |
eval { $dbi->update_param({";" => 1}) }; |
|
3598 |
like($@, qr/not safety/); |
|
3599 | ||
3600 | ||
3601 |
test 'update_param'; |
|
3602 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3603 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
3604 |
$dbi->execute($create_table1_2); |
test cleanup in progress
|
3605 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
3606 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
cleanup test
|
3607 | |
test cleanup in progress
|
3608 |
$param = {$key2 => 11}; |
cleanup test
|
3609 |
$update_param = $dbi->assign_param($param); |
3610 |
$sql = <<"EOS"; |
|
test cleanup in progress
|
3611 |
update $table1 set $update_param |
3612 |
where $key1 = 1 |
|
cleanup test
|
3613 |
EOS |
test cleanup in progress
|
3614 |
$dbi->execute($sql, param => $param, table => $table1); |
3615 |
$result = $dbi->execute("select * from $table1 order by $key1;"); |
|
cleanup test
|
3616 |
$rows = $result->all; |
test cleanup in progress
|
3617 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
3618 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
cleanup test
|
3619 |
"basic"); |
3620 | ||
cleanup test
|
3621 |
test 'join'; |
3622 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3623 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
3624 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3625 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
3626 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
|
3627 |
eval { $dbi->execute('drop table $table2') }; |
|
cleanup test
|
3628 |
$dbi->execute($create_table2); |
test cleanup in progress
|
3629 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5}); |
3630 |
eval { $dbi->execute('drop table $table3') }; |
|
3631 |
$dbi->execute("create table $table3 ($key3 int, $key4 int);"); |
|
3632 |
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4}); |
|
cleanup test
|
3633 |
$rows = $dbi->select( |
test cleanup in progress
|
3634 |
table => $table1, |
3635 |
column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3", |
|
3636 |
where => {"$table1.$key2" => 2}, |
|
3637 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1"] |
|
cleanup test
|
3638 |
)->all; |
test cleanup in progress
|
3639 |
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]); |
cleanup test
|
3640 | |
3641 |
$rows = $dbi->select( |
|
test cleanup in progress
|
3642 |
table => $table1, |
3643 |
where => {$key1 => 1}, |
|
3644 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1"] |
|
cleanup test
|
3645 |
)->all; |
test cleanup in progress
|
3646 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
cleanup test
|
3647 | |
3648 |
eval { |
|
3649 |
$rows = $dbi->select( |
|
test cleanup in progress
|
3650 |
table => $table1, |
3651 |
column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3", |
|
3652 |
where => {'$table1.$key2' => 2}, |
|
3653 |
join => {"$table1.$key1" => "$table2.$key1"} |
|
cleanup test
|
3654 |
); |
3655 |
}; |
|
3656 |
like ($@, qr/array/); |
|
3657 | ||
3658 |
$rows = $dbi->select( |
|
test cleanup in progress
|
3659 |
table => $table1, |
3660 |
where => {$key1 => 1}, |
|
3661 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1", |
|
3662 |
"left outer join $table3 on $table2.$key3 = $table3.$key3"] |
|
cleanup test
|
3663 |
)->all; |
test cleanup in progress
|
3664 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
cleanup test
|
3665 | |
3666 |
$rows = $dbi->select( |
|
test cleanup in progress
|
3667 |
column => "$table3.$key4 as ${table3}__$key4", |
3668 |
table => $table1, |
|
3669 |
where => {'$table1.$key1' => 1}, |
|
3670 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1", |
|
3671 |
"left outer join $table3 on $table2.$key3 = $table3.$key3"] |
|
cleanup test
|
3672 |
)->all; |
test cleanup in progress
|
3673 |
is_deeply($rows, [{"${table3}__$key4" => 4}]); |
cleanup test
|
3674 | |
3675 |
$rows = $dbi->select( |
|
test cleanup in progress
|
3676 |
column => "$table1.$key1 as ${table1}__$key1", |
3677 |
table => $table1, |
|
3678 |
where => {'$table3.$key4' => 4}, |
|
3679 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1", |
|
3680 |
"left outer join $table3 on $table2.$key3 = $table3.$key3"] |
|
cleanup test
|
3681 |
)->all; |
test cleanup in progress
|
3682 |
is_deeply($rows, [{"${table1}__$key1" => 1}]); |
cleanup test
|
3683 | |
3684 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3685 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
3686 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3687 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
3688 |
eval { $dbi->execute('drop table $table2') }; |
|
cleanup test
|
3689 |
$dbi->execute($create_table2); |
test cleanup in progress
|
3690 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5}); |
cleanup test
|
3691 |
$rows = $dbi->select( |
test cleanup in progress
|
3692 |
table => $table1, |
3693 |
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", |
|
3694 |
where => {"$table1.$key2" => 2}, |
|
3695 |
join => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"], |
|
cleanup test
|
3696 |
)->all; |
test cleanup in progress
|
3697 |
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], |
cleanup test
|
3698 |
'quote'); |
3699 | ||
3700 | ||
3701 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3702 |
eval { $dbi->execute('drop table $table1') }; |
cleanup test
|
3703 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3704 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
cleanup test
|
3705 |
$sql = <<"EOS"; |
3706 |
left outer join ( |
|
test cleanup in progress
|
3707 |
select * from $table1 as t1 |
3708 |
where t1.$key2 = ( |
|
3709 |
select max(t2.$key2) from $table1 as t2 |
|
3710 |
where t1.$key1 = t2.$key1 |
|
cleanup test
|
3711 |
) |
test cleanup in progress
|
3712 |
) as latest_$table1 on $table1.$key1 = latest_$table1.$key1 |
cleanup test
|
3713 |
EOS |
3714 |
$join = [$sql]; |
|
3715 |
$rows = $dbi->select( |
|
test cleanup in progress
|
3716 |
table => $table1, |
3717 |
column => "latest_$table1.$key1 as latest_${table1}__$key1", |
|
cleanup test
|
3718 |
join => $join |
3719 |
)->all; |
|
test cleanup in progress
|
3720 |
is_deeply($rows, [{"latest_${table1}__$key1" => 1}]); |
cleanup test
|
3721 | |
3722 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3723 |
eval { $dbi->execute('drop table $table1') }; |
3724 |
eval { $dbi->execute('drop table $table2') }; |
|
cleanup test
|
3725 |
$dbi->execute($create_table1); |
3726 |
$dbi->execute($create_table2); |
|
test cleanup in progress
|
3727 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
3728 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4}); |
|
3729 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5}); |
|
cleanup test
|
3730 |
$result = $dbi->select( |
test cleanup in progress
|
3731 |
table => $table1, |
cleanup test
|
3732 |
join => [ |
test cleanup in progress
|
3733 |
"left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1" |
cleanup test
|
3734 |
] |
3735 |
); |
|
test cleanup in progress
|
3736 |
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]); |
cleanup test
|
3737 |
$result = $dbi->select( |
test cleanup in progress
|
3738 |
table => $table1, |
3739 |
column => [{$table2 => [$key3]}], |
|
cleanup test
|
3740 |
join => [ |
test cleanup in progress
|
3741 |
"left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1" |
cleanup test
|
3742 |
] |
3743 |
); |
|
test cleanup in progress
|
3744 |
is_deeply($result->all, [{'$table2.$key3' => 4}]); |
cleanup test
|
3745 |
$result = $dbi->select( |
test cleanup in progress
|
3746 |
table => $table1, |
3747 |
column => [{$table2 => [$key3]}], |
|
cleanup test
|
3748 |
join => [ |
test cleanup in progress
|
3749 |
"left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'" |
cleanup test
|
3750 |
] |
3751 |
); |
|
test cleanup in progress
|
3752 |
is_deeply($result->all, [{'$table2.$key3' => 4}]); |
cleanup test
|
3753 | |
3754 |
$dbi = DBIx::Custom->connect; |
|
test cleanup in progress
|
3755 |
eval { $dbi->execute('drop table $table1') }; |
3756 |
eval { $dbi->execute('drop table $table2') }; |
|
cleanup test
|
3757 |
$dbi->execute($create_table1); |
3758 |
$dbi->execute($create_table2); |
|
test cleanup in progress
|
3759 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
3760 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4}); |
|
3761 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5}); |
|
cleanup test
|
3762 |
$result = $dbi->select( |
test cleanup in progress
|
3763 |
table => $table1, |
3764 |
column => [{$table2 => [$key3]}], |
|
cleanup test
|
3765 |
join => [ |
3766 |
{ |
|
test cleanup in progress
|
3767 |
clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1", |
3768 |
table => [$table1, $table2] |
|
cleanup test
|
3769 |
} |
3770 |
] |
|
3771 |
); |
|
test cleanup in progress
|
3772 |
is_deeply($result->all, [{"$table2.$key3" => 4}]); |
cleanup test
|
3773 | |
test cleanup
|
3774 |
test 'Model class'; |
3775 |
use MyDBI1; |
|
3776 |
$dbi = MyDBI1->connect; |
|
test cleanup in progress
|
3777 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
3778 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3779 |
$model = $dbi->model($table1); |
3780 |
$model->insert({$key1 => 'a', $key2 => 'b'}); |
|
3781 |
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic'); |
|
3782 |
eval { $dbi->execute('drop table $table2') }; |
|
test cleanup
|
3783 |
$dbi->execute($create_table2); |
test cleanup in progress
|
3784 |
$model = $dbi->model($table2); |
3785 |
$model->insert({$key1 => 'a'}); |
|
3786 |
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic'); |
|
3787 |
is($dbi->models->{$table1}, $dbi->model($table1)); |
|
3788 |
is($dbi->models->{$table2}, $dbi->model($table2)); |
|
test cleanup
|
3789 | |
3790 |
$dbi = MyDBI4->connect; |
|
test cleanup in progress
|
3791 |
eval { $dbi->execute('drop table $table1') }; |
test cleanup
|
3792 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3793 |
$model = $dbi->model($table1); |
3794 |
$model->insert({$key1 => 'a', $key2 => 'b'}); |
|
3795 |
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic'); |
|
3796 |
eval { $dbi->execute('drop table $table2') }; |
|
test cleanup
|
3797 |
$dbi->execute($create_table2); |
test cleanup in progress
|
3798 |
$model = $dbi->model($table2); |
3799 |
$model->insert({$key1 => 'a'}); |
|
3800 |
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic'); |
|
test cleanup
|
3801 | |
3802 |
$dbi = MyDBI5->connect; |
|
test cleanup in progress
|
3803 |
eval { $dbi->execute('drop table $table1') }; |
3804 |
eval { $dbi->execute('drop table $table2') }; |
|
test cleanup
|
3805 |
$dbi->execute($create_table1); |
3806 |
$dbi->execute($create_table2); |
|
test cleanup in progress
|
3807 |
$model = $dbi->model($table2); |
3808 |
$model->insert({$key1 => 'a'}); |
|
3809 |
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model'); |
|
3810 |
$dbi->insert(table => $table1, param => {$key1 => 1}); |
|
3811 |
$model = $dbi->model($table1); |
|
3812 |
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model'); |
|
test cleanup
|
3813 | |
3814 |
test 'primary_key'; |
|
3815 |
use MyDBI1; |
|
3816 |
$dbi = MyDBI1->connect; |
|
test cleanup in progress
|
3817 |
$model = $dbi->model($table1); |
3818 |
$model->primary_key([$key1, $key2]); |
|
3819 |
is_deeply($model->primary_key, [$key1, $key2]); |
|
test cleanup
|
3820 | |
3821 |
test 'columns'; |
|
3822 |
use MyDBI1; |
|
3823 |
$dbi = MyDBI1->connect; |
|
test cleanup in progress
|
3824 |
$model = $dbi->model($table1); |
3825 |
$model->columns([$key1, $key2]); |
|
3826 |
is_deeply($model->columns, [$key1, $key2]); |
|
test cleanup
|
3827 | |
3828 |
test 'setup_model'; |
|
3829 |
use MyDBI1; |
|
3830 |
$dbi = MyDBI1->connect; |
|
test cleanup in progress
|
3831 |
eval { $dbi->execute('drop table $table1') }; |
3832 |
eval { $dbi->execute('drop table $table2') }; |
|
test cleanup
|
3833 | |
3834 |
$dbi->execute($create_table1); |
|
3835 |
$dbi->execute($create_table2); |
|
3836 |
$dbi->setup_model; |
|
test cleanup in progress
|
3837 |
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]); |
3838 |
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]); |
|
test cleanup
|
3839 | |
test cleanup
|
3840 | |
cleanup test
|
3841 | |
cleanup test
|
3842 |
1; |