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