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