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