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