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