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