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