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