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