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