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