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