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