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