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