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