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