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