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