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