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 }}); |
|
fixed sqlserver test bug
|
3006 |
$query = undef; |
fixed id option bug when col...
|
3007 |
is_deeply($dbi->select(table => $table1)->one, |
3008 |
{$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2}, |
|
3009 |
); |
|
3010 | ||
test cleanup
|
3011 |
test 'result'; |
3012 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
3013 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
3014 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3015 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
3016 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup
|
3017 | |
test cleanup in progress
|
3018 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3019 |
@rows = (); |
3020 |
while (my $row = $result->fetch) { |
|
3021 |
push @rows, [@$row]; |
|
3022 |
} |
|
3023 |
is_deeply(\@rows, [[1, 2], [3, 4]]); |
|
3024 | ||
test cleanup in progress
|
3025 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3026 |
@rows = (); |
3027 |
while (my $row = $result->fetch_hash) { |
|
3028 |
push @rows, {%$row}; |
|
3029 |
} |
|
test cleanup in progress
|
3030 |
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
3031 | |
3032 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
3033 |
eval { $dbi->execute("drop table $table1") }; |
test cleanup
|
3034 |
$dbi->execute($create_table1); |
test cleanup in progress
|
3035 |
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1); |
3036 |
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1); |
|
test cleanup
|
3037 | |
3038 |
test 'fetch_all'; |
|
test cleanup in progress
|
3039 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3040 |
$rows = $result->fetch_all; |
3041 |
is_deeply($rows, [[1, 2], [3, 4]]); |
|
3042 | ||
test cleanup in progress
|
3043 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3044 |
$rows = $result->fetch_hash_all; |
test cleanup in progress
|
3045 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]); |
test cleanup
|
3046 | |
test cleanup in progress
|
3047 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3048 |
$result->dbi->filters({three_times => sub { $_[0] * 3}}); |
test cleanup in progress
|
3049 |
$result->filter({$key1 => 'three_times'}); |
test cleanup
|
3050 | |
3051 |
$rows = $result->fetch_all; |
|
3052 |
is_deeply($rows, [[3, 2], [9, 4]], "array"); |
|
3053 | ||
test cleanup in progress
|
3054 |
$result = $dbi->select(table => $table1); |
test cleanup
|
3055 |
$result->dbi->filters({three_times => sub { $_[0] * 3}}); |
test cleanup in progress
|
3056 |
$result->filter({$key1 => 'three_times'}); |
test cleanup
|
3057 |
$rows = $result->fetch_hash_all; |
test cleanup in progress
|
3058 |
is_deeply($rows, [{$key1 => 3, $key2 => 2}, {$key1 => 9, $key2 => 4}], "hash"); |
test cleanup
|
3059 | |
3060 |
test "query_builder"; |
|
3061 |
$datas = [ |
|
3062 |
# Basic tests |
|
3063 |
{ name => 'placeholder basic', |
|
3064 |
source => "a {? k1} b {= k2} {<> k3} {> k4} {< k5} {>= k6} {<= k7} {like k8}", , |
|
cleanup test
|
3065 |
sql_expected => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?", |
test cleanup
|
3066 |
columns_expected => [qw/k1 k2 k3 k4 k5 k6 k7 k8/] |
3067 |
}, |
|
3068 |
{ |
|
3069 |
name => 'placeholder in', |
|
cleanup test
|
3070 |
source => "{in k1 3}", |
3071 |
sql_expected => "k1 in (?, ?, ?)", |
|
test cleanup
|
3072 |
columns_expected => [qw/k1 k1 k1/] |
3073 |
}, |
|
3074 |
|
|
3075 |
# Table name |
|
3076 |
{ |
|
3077 |
name => 'placeholder with table name', |
|
3078 |
source => "{= a.k1} {= a.k2}", |
|
cleanup test
|
3079 |
sql_expected => "a.k1 = ? a.k2 = ?", |
test cleanup
|
3080 |
columns_expected => [qw/a.k1 a.k2/] |
3081 |
}, |
|
3082 |
{ |
|
3083 |
name => 'placeholder in with table name', |
|
3084 |
source => "{in a.k1 2} {in b.k2 2}", |
|
cleanup test
|
3085 |
sql_expected => "a.k1 in (?, ?) b.k2 in (?, ?)", |
test cleanup
|
3086 |
columns_expected => [qw/a.k1 a.k1 b.k2 b.k2/] |
3087 |
}, |
|
3088 |
{ |
|
3089 |
name => 'not contain tag', |
|
3090 |
source => "aaa", |
|
cleanup test
|
3091 |
sql_expected => "aaa", |
test cleanup
|
3092 |
columns_expected => [], |
3093 |
} |
|
3094 |
]; |
|
3095 | ||
3096 |
for (my $i = 0; $i < @$datas; $i++) { |
|
3097 |
my $data = $datas->[$i]; |
|
cleanup
|
3098 |
my $dbi = DBIx::Custom->new; |
3099 |
my $builder = $dbi->query_builder; |
|
test cleanup
|
3100 |
my $query = $builder->build_query($data->{source}); |
3101 |
is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql"); |
|
3102 |
is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns"); |
|
3103 |
} |
|
3104 | ||
cleanup
|
3105 |
$dbi = DBIx::Custom->new; |
3106 |
$builder = $dbi->query_builder; |
|
3107 |
$dbi->register_tag( |
|
test cleanup
|
3108 |
p => sub { |
3109 |
my @args = @_; |
|
3110 |
|
|
3111 |
my $expand = "? $args[0] $args[1]"; |
|
3112 |
my $columns = [2]; |
|
3113 |
return [$expand, $columns]; |
|
3114 |
} |
|
3115 |
); |
|
3116 | ||
3117 |
$query = $builder->build_query("{p a b}"); |
|
cleanup test
|
3118 |
is($query->{sql}, "? a b", "register_tag sql"); |
test cleanup
|
3119 |
is_deeply($query->{columns}, [2], "register_tag columns"); |
3120 | ||
3121 |
eval{$builder->build_query('{? }')}; |
|
3122 |
like($@, qr/\QColumn name must be specified in tag "{? }"/, "? not arguments"); |
|
3123 | ||
3124 |
eval{$builder->build_query("{a }")}; |
|
3125 |
like($@, qr/\QTag "a" is not registered/, "tag not exist"); |
|
3126 | ||
cleanup
|
3127 |
$dbi->register_tag({ |
test cleanup
|
3128 |
q => 'string' |
3129 |
}); |
|
3130 | ||
3131 |
eval{$builder->build_query("{q}", {})}; |
|
3132 |
like($@, qr/Tag "q" must be sub reference/, "tag not code ref"); |
|
3133 | ||
cleanup
|
3134 |
$dbi->register_tag({ |
test cleanup
|
3135 |
r => sub {} |
3136 |
}); |
|
3137 | ||
3138 |
eval{$builder->build_query("{r}")}; |
|
3139 |
like($@, qr/\QTag "r" must return [STRING, ARRAY_REFERENCE]/, "tag return noting"); |
|
3140 | ||
cleanup
|
3141 |
$dbi->register_tag({ |
test cleanup
|
3142 |
s => sub { return ["a", ""]} |
3143 |
}); |
|
3144 | ||
3145 |
eval{$builder->build_query("{s}")}; |
|
3146 |
like($@, qr/\QTag "s" must return [STRING, ARRAY_REFERENCE]/, "tag return not array columns"); |
|
3147 | ||
cleanup
|
3148 |
$dbi->register_tag( |
test cleanup
|
3149 |
t => sub {return ["a", []]} |
3150 |
); |
|
3151 | ||
3152 | ||
cleanup test
|
3153 |
test 'Default tag Error case'; |
3154 |
eval{$builder->build_query("{= }")}; |
|
3155 |
like($@, qr/Column name must be specified in tag "{= }"/, "basic '=' : key not exist"); |
|
3156 | ||
3157 |
eval{$builder->build_query("{in }")}; |
|
3158 |
like($@, qr/Column name and count of values must be specified in tag "{in }"/, "in : key not exist"); |
|
3159 | ||
3160 |
eval{$builder->build_query("{in a}")}; |
|
3161 |
like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/, |
|
3162 |
"in : key not exist"); |
|
3163 | ||
3164 |
eval{$builder->build_query("{in a r}")}; |
|
3165 |
like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/, |
|
3166 |
"in : key not exist"); |
|
3167 | ||
3168 |
test 'variouse source'; |
|
3169 |
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d"; |
|
3170 |
$query = $builder->build_query($source); |
|
3171 |
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1"); |
|
3172 | ||
3173 |
$source = "abc"; |
|
3174 |
$query = $builder->build_query($source); |
|
3175 |
is($query->sql, 'abc', "basic : 2"); |
|
3176 | ||
3177 |
$source = "{= a}"; |
|
3178 |
$query = $builder->build_query($source); |
|
3179 |
is($query->sql, 'a = ?', "only tag"); |
|
3180 | ||
3181 |
$source = "000"; |
|
3182 |
$query = $builder->build_query($source); |
|
3183 |
is($query->sql, '000', "contain 0 value"); |
|
3184 | ||
3185 |
$source = "a {= b} }"; |
|
3186 |
eval{$builder->build_query($source)}; |
|
3187 |
like($@, qr/unexpected "}"/, "error : 1"); |
|
3188 | ||
3189 |
$source = "a {= {}"; |
|
3190 |
eval{$builder->build_query($source)}; |
|
3191 |
like($@, qr/unexpected "{"/, "error : 2"); |
|
3192 | ||
3193 |
test 'select() sqlfilter option'; |
|
3194 |
$dbi = DBIx::Custom->connect; |
|
cleanup test
|
3195 |
$dbi->user_table_info($user_table_info); |
cleanup test
|
3196 |
eval { $dbi->execute("drop table $table1") }; |
3197 |
$dbi->execute($create_table1); |
|
3198 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
|
3199 |
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3}); |
|
3200 |
$rows = $dbi->select( |
|
3201 |
table => $table1, |
|
3202 |
column => $key1, |
|
3203 |
sqlfilter => sub { |
|
3204 |
my $sql = shift; |
|
test cleanup
|
3205 |
$sql = "select * from ( $sql ) t where $key1 = 1"; |
cleanup test
|
3206 |
return $sql; |
3207 |
} |
|
3208 |
)->all; |
|
3209 |
is_deeply($rows, [{$key1 => 1}]); |
|
3210 | ||
sqlfilter option is renamed ...
|
3211 |
test 'select() after_build_sql option'; |
3212 |
$dbi = DBIx::Custom->connect; |
|
3213 |
$dbi->user_table_info($user_table_info); |
|
3214 |
eval { $dbi->execute("drop table $table1") }; |
|
3215 |
$dbi->execute($create_table1); |
|
3216 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
|
3217 |
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3}); |
|
3218 |
$rows = $dbi->select( |
|
3219 |
table => $table1, |
|
3220 |
column => $key1, |
|
3221 |
after_build_sql => sub { |
|
3222 |
my $sql = shift; |
|
3223 |
$sql = "select * from ( $sql ) t where $key1 = 1"; |
|
3224 |
return $sql; |
|
3225 |
} |
|
3226 |
)->all; |
|
3227 |
is_deeply($rows, [{$key1 => 1}]); |
|
3228 | ||
cleanup test
|
3229 |
test 'dbi method from model'; |
3230 |
$dbi = MyDBI9->connect; |
|
3231 |
eval { $dbi->execute("drop table $table1") }; |
|
3232 |
$dbi->execute($create_table1); |
|
3233 |
$dbi->setup_model; |
|
3234 |
$model = $dbi->model($table1); |
|
3235 |
eval{$model->execute("select * from $table1")}; |
|
3236 |
ok(!$@); |
|
3237 | ||
3238 |
test 'column table option'; |
|
3239 |
$dbi = MyDBI9->connect; |
|
cleanup test
|
3240 |
$dbi->user_table_info($user_table_info); |
cleanup test
|
3241 |
eval { $dbi->execute("drop table $table1") }; |
3242 |
$dbi->execute($create_table1); |
|
3243 |
eval { $dbi->execute("drop table $table2") }; |
|
3244 |
$dbi->execute($create_table2); |
|
3245 |
$dbi->setup_model; |
|
3246 |
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)"); |
|
3247 |
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)"); |
|
3248 |
$model = $dbi->model($table1); |
|
3249 |
$result = $model->select( |
|
3250 |
column => [ |
|
3251 |
$model->column($table2, {alias => $table2_alias}) |
|
3252 |
], |
|
3253 |
where => {"$table2_alias.$key3" => 4} |
|
3254 |
); |
|
3255 |
is_deeply($result->one, |
|
3256 |
{"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4}); |
|
3257 | ||
3258 |
$dbi->separator('__'); |
|
3259 |
$result = $model->select( |
|
3260 |
column => [ |
|
3261 |
$model->column($table2, {alias => $table2_alias}) |
|
3262 |
], |
|
3263 |
where => {"$table2_alias.$key3" => 4} |
|
3264 |
); |
|
3265 |
is_deeply($result->one, |
|
3266 |
{"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4}); |
|
3267 | ||
3268 |
$dbi->separator('-'); |
|
3269 |
$result = $model->select( |
|
3270 |
column => [ |
|
3271 |
$model->column($table2, {alias => $table2_alias}) |
|
3272 |
], |
|
3273 |
where => {"$table2_alias.$key3" => 4} |
|
3274 |
); |
|
3275 |
is_deeply($result->one, |
|
3276 |
{"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4}); |
|
3277 | ||
3278 |
test 'create_model'; |
|
3279 |
$dbi = DBIx::Custom->connect; |
|
cleanup test
|
3280 |
$dbi->user_table_info($user_table_info); |
cleanup test
|
3281 |
eval { $dbi->execute("drop table $table1") }; |
3282 |
eval { $dbi->execute("drop table $table2") }; |
|
3283 |
$dbi->execute($create_table1); |
|
3284 |
$dbi->execute($create_table2); |
|
3285 | ||
3286 |
$dbi->create_model( |
|
3287 |
table => $table1, |
|
3288 |
join => [ |
|
3289 |
"left outer join $table2 on $table1.$key1 = $table2.$key1" |
|
3290 |
], |
|
3291 |
primary_key => [$key1] |
|
3292 |
); |
|
3293 |
$model2 = $dbi->create_model( |
|
3294 |
table => $table2 |
|
3295 |
); |
|
3296 |
$dbi->create_model( |
|
3297 |
table => $table3, |
|
3298 |
filter => [ |
|
3299 |
$key1 => {in => sub { uc $_[0] }} |
|
3300 |
] |
|
3301 |
); |
|
3302 |
$dbi->setup_model; |
|
3303 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
|
3304 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3}); |
|
3305 |
$model = $dbi->model($table1); |
|
3306 |
$result = $model->select( |
|
3307 |
column => [$model->mycolumn, $model->column($table2)], |
|
3308 |
where => {"$table1.$key1" => 1} |
|
3309 |
); |
|
3310 |
is_deeply($result->one, |
|
3311 |
{$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3}); |
|
3312 |
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3}); |
|
3313 | ||
3314 |
test 'model method'; |
|
3315 |
$dbi = DBIx::Custom->connect; |
|
3316 |
eval { $dbi->execute("drop table $table2") }; |
|
3317 |
$dbi->execute($create_table2); |
|
3318 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3}); |
|
3319 |
$model = $dbi->create_model( |
|
3320 |
table => $table2 |
|
3321 |
); |
|
3322 |
$model->method(foo => sub { shift->select(@_) }); |
|
3323 |
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3}); |
|
- method method of DBIx::Cus...
|
3324 | |
3325 |
test 'model helper'; |
|
3326 |
$dbi = DBIx::Custom->connect; |
|
3327 |
eval { $dbi->execute("drop table $table2") }; |
|
3328 |
$dbi->execute($create_table2); |
|
3329 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3}); |
|
3330 |
$model = $dbi->create_model( |
|
3331 |
table => $table2 |
|
3332 |
); |
|
3333 |
$model->helper(foo => sub { shift->select(@_) }); |
|
3334 |
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3}); |
|
cleanup test
|
3335 | |
- update_param is DEPRECATED...
|
3336 |
test 'assign_clause'; |
cleanup test
|
3337 |
$dbi = DBIx::Custom->connect; |
3338 |
eval { $dbi->execute("drop table $table1") }; |
|
3339 |
$dbi->execute($create_table1_2); |
|
3340 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
|
3341 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
3342 | ||
3343 |
$param = {$key2 => 11}; |
|
- update_param is DEPRECATED...
|
3344 |
$assign_clause = $dbi->assign_clause($param); |
cleanup test
|
3345 |
$sql = <<"EOS"; |
- update_param is DEPRECATED...
|
3346 |
update $table1 set $assign_clause |
cleanup test
|
3347 |
where $key1 = 1 |
3348 |
EOS |
|
3349 |
$dbi->execute($sql, param => $param); |
|
3350 |
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1); |
|
3351 |
$rows = $result->all; |
|
3352 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
|
3353 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
3354 |
"basic"); |
|
3355 | ||
3356 | ||
3357 |
$dbi = DBIx::Custom->connect; |
|
3358 |
eval { $dbi->execute("drop table $table1") }; |
|
3359 |
$dbi->execute($create_table1_2); |
|
3360 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
|
3361 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
3362 | ||
3363 |
$param = {$key2 => 11, $key3 => 33}; |
|
- update_param is DEPRECATED...
|
3364 |
$assign_clause = $dbi->assign_clause($param); |
cleanup test
|
3365 |
$sql = <<"EOS"; |
- update_param is DEPRECATED...
|
3366 |
update $table1 set $assign_clause |
cleanup test
|
3367 |
where $key1 = 1 |
3368 |
EOS |
|
3369 |
$dbi->execute($sql, param => $param); |
|
3370 |
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1); |
|
3371 |
$rows = $result->all; |
|
3372 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5}, |
|
3373 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
3374 |
"basic"); |
|
3375 | ||
3376 |
$dbi = DBIx::Custom->connect; |
|
3377 |
eval { $dbi->execute("drop table $table1") }; |
|
3378 |
$dbi->execute($create_table1_2); |
|
3379 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
|
3380 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
3381 | ||
3382 |
$param = {$key2 => 11, $key3 => 33}; |
|
- update_param is DEPRECATED...
|
3383 |
$assign_clause = $dbi->update_param($param, {no_set => 1}); |
cleanup test
|
3384 |
$sql = <<"EOS"; |
- update_param is DEPRECATED...
|
3385 |
update $table1 set $assign_clause |
cleanup test
|
3386 |
where $key1 = 1 |
3387 |
EOS |
|
3388 |
$dbi->execute($sql, param => $param); |
|
3389 |
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1); |
|
3390 |
$rows = $result->all; |
|
3391 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5}, |
|
3392 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
3393 |
"update param no_set"); |
|
3394 | ||
3395 |
|
|
- update_param is DEPRECATED...
|
3396 |
eval { $dbi->assign_clause({";" => 1}) }; |
cleanup test
|
3397 |
like($@, qr/not safety/); |
3398 | ||
3399 |
$dbi = DBIx::Custom->connect; |
|
3400 |
eval { $dbi->execute("drop table $table1") }; |
|
3401 |
$dbi->execute($create_table1_2); |
|
3402 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}); |
|
3403 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
|
test cleanup
|
3404 | |
cleanup test
|
3405 |
$param = {$key2 => 11}; |
- update_param is DEPRECATED...
|
3406 |
$assign_clause = $dbi->assign_param($param); |
3407 |
$sql = <<"EOS"; |
|
3408 |
update $table1 set $assign_clause |
|
3409 |
where $key1 = 1 |
|
3410 |
EOS |
|
3411 |
$dbi->execute($sql, param => $param, table => $table1); |
|
3412 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
|
3413 |
$rows = $result->all; |
|
3414 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
|
3415 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
3416 |
"basic"); |
|
3417 | ||
3418 |
$param = {$key2 => 11}; |
|
3419 |
$assign_clause = $dbi->assign_clause($param); |
|
cleanup test
|
3420 |
$sql = <<"EOS"; |
- update_param is DEPRECATED...
|
3421 |
update $table1 set $assign_clause |
cleanup test
|
3422 |
where $key1 = 1 |
3423 |
EOS |
|
3424 |
$dbi->execute($sql, param => $param, table => $table1); |
|
3425 |
$result = $dbi->execute("select * from $table1 order by $key1"); |
|
3426 |
$rows = $result->all; |
|
3427 |
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
|
3428 |
{$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
3429 |
"basic"); |
|
test cleanup
|
3430 | |
cleanup test
|
3431 |
test 'Model class'; |
3432 |
$dbi = MyDBI1->connect; |
|
3433 |
eval { $dbi->execute("drop table $table1") }; |
|
3434 |
$dbi->execute($create_table1); |
|
3435 |
$model = $dbi->model($table1); |
|
3436 |
$model->insert({$key1 => 'a', $key2 => 'b'}); |
|
3437 |
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic'); |
|
3438 |
eval { $dbi->execute("drop table $table2") }; |
|
3439 |
$dbi->execute($create_table2); |
|
3440 |
$model = $dbi->model($table2); |
|
3441 |
$model->insert({$key1 => 'a'}); |
|
3442 |
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic'); |
|
3443 |
is($dbi->models->{$table1}, $dbi->model($table1)); |
|
3444 |
is($dbi->models->{$table2}, $dbi->model($table2)); |
|
3445 | ||
3446 |
$dbi = MyDBI4->connect; |
|
3447 |
eval { $dbi->execute("drop table $table1") }; |
|
3448 |
$dbi->execute($create_table1); |
|
3449 |
$model = $dbi->model($table1); |
|
3450 |
$model->insert({$key1 => 'a', $key2 => 'b'}); |
|
3451 |
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic'); |
|
3452 |
eval { $dbi->execute("drop table $table2") }; |
|
3453 |
$dbi->execute($create_table2); |
|
3454 |
$model = $dbi->model($table2); |
|
3455 |
$model->insert({$key1 => 'a'}); |
|
3456 |
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic'); |
|
3457 | ||
3458 |
$dbi = MyDBI5->connect; |
|
3459 |
eval { $dbi->execute("drop table $table1") }; |
|
3460 |
eval { $dbi->execute("drop table $table2") }; |
|
3461 |
$dbi->execute($create_table1); |
|
3462 |
$dbi->execute($create_table2); |
|
3463 |
$model = $dbi->model($table2); |
|
3464 |
$model->insert({$key1 => 'a'}); |
|
3465 |
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model'); |
|
3466 |
$dbi->insert(table => $table1, param => {$key1 => 1}); |
|
3467 |
$model = $dbi->model($table1); |
|
3468 |
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model'); |
|
3469 | ||
3470 |
test 'primary_key'; |
|
3471 |
$dbi = MyDBI1->connect; |
|
3472 |
$model = $dbi->model($table1); |
|
3473 |
$model->primary_key([$key1, $key2]); |
|
3474 |
is_deeply($model->primary_key, [$key1, $key2]); |
|
3475 | ||
3476 |
test 'columns'; |
|
3477 |
$dbi = MyDBI1->connect; |
|
3478 |
$model = $dbi->model($table1); |
|
3479 |
$model->columns([$key1, $key2]); |
|
3480 |
is_deeply($model->columns, [$key1, $key2]); |
|
cleanup test
|
3481 | |
cleanup test
|
3482 |
test 'setup_model'; |
3483 |
$dbi = MyDBI1->connect; |
|
cleanup test
|
3484 |
$dbi->user_table_info($user_table_info); |
finishied sqlite test cleanu...
|
3485 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3486 |
eval { $dbi->execute("drop table $table2") }; |
added EXPERIMENTAL execute m...
|
3487 | |
cleanup test
|
3488 |
$dbi->execute($create_table1); |
cleanup test
|
3489 |
$dbi->execute($create_table2); |
cleanup test
|
3490 |
$dbi->setup_model; |
cleanup test
|
3491 |
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]); |
3492 |
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]); |
|
cleanup test
|
3493 | |
cleanup test
|
3494 |
test 'each_column'; |
3495 |
$dbi = DBIx::Custom->connect; |
|
3496 |
eval { $dbi->execute("drop table ${q}table$p") }; |
|
finishied sqlite test cleanu...
|
3497 |
eval { $dbi->execute("drop table $table1") }; |
3498 |
eval { $dbi->execute("drop table $table2") }; |
|
cleanup test
|
3499 |
eval { $dbi->execute("drop table $table3") }; |
3500 |
$dbi->execute($create_table1_type); |
|
cleanup test
|
3501 |
$dbi->execute($create_table2); |
cleanup test
|
3502 | |
3503 |
$infos = []; |
|
3504 |
$dbi->each_column(sub { |
|
3505 |
my ($self, $table, $column, $cinfo) = @_; |
|
3506 |
|
|
3507 |
if ($table =~ /^table\d/i) { |
|
3508 |
my $info = [$table, $column, $cinfo->{COLUMN_NAME}]; |
|
3509 |
push @$infos, $info; |
|
3510 |
} |
|
3511 |
}); |
|
3512 |
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos]; |
|
3513 |
is_deeply($infos, |
|
3514 |
[ |
|
3515 |
[$table1, $key1, $key1], |
|
3516 |
[$table1, $key2, $key2], |
|
3517 |
[$table2, $key1, $key1], |
|
3518 |
[$table2, $key3, $key3] |
|
3519 |
] |
|
3520 |
|
|
cleanup test
|
3521 |
); |
cleanup test
|
3522 | |
cleanup test
|
3523 |
test 'each_table'; |
3524 |
$dbi = DBIx::Custom->connect; |
|
3525 |
eval { $dbi->execute("drop table $table1") }; |
|
3526 |
eval { $dbi->execute("drop table $table2") }; |
|
3527 |
$dbi->execute($create_table2); |
|
3528 |
$dbi->execute($create_table1_type); |
|
cleanup test
|
3529 | |
cleanup test
|
3530 |
$infos = []; |
3531 |
$dbi->each_table(sub { |
|
3532 |
my ($self, $table, $table_info) = @_; |
|
3533 |
|
|
3534 |
if ($table =~ /^table\d/i) { |
|
3535 |
my $info = [$table, $table_info->{TABLE_NAME}]; |
|
3536 |
push @$infos, $info; |
|
3537 |
} |
|
3538 |
}); |
|
3539 |
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos]; |
|
3540 |
is_deeply($infos, |
|
3541 |
[ |
|
3542 |
[$table1, $table1], |
|
3543 |
[$table2, $table2], |
|
3544 |
] |
|
cleanup test
|
3545 |
); |
3546 | ||
cleanup test
|
3547 |
$dbi = DBIx::Custom->connect; |
3548 |
eval { $dbi->execute("drop table $table1") }; |
|
3549 |
eval { $dbi->execute("drop table $table2") }; |
|
3550 |
$dbi->execute($create_table2); |
|
3551 |
$dbi->execute($create_table1_type); |
|
3552 | ||
3553 |
$infos = []; |
|
3554 |
$dbi->user_table_info($user_table_info); |
|
3555 |
$dbi->each_table(sub { |
|
3556 |
my ($self, $table, $table_info) = @_; |
|
3557 |
|
|
3558 |
if ($table =~ /^table\d/i) { |
|
3559 |
my $info = [$table, $table_info->{TABLE_NAME}]; |
|
3560 |
push @$infos, $info; |
|
3561 |
} |
|
3562 |
}); |
|
3563 |
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos]; |
|
3564 |
is_deeply($infos, |
|
3565 |
[ |
|
3566 |
[$table1, $table1], |
|
3567 |
[$table2, $table2], |
|
3568 |
[$table3, $table3], |
|
3569 |
] |
|
3570 |
); |
|
3571 | ||
cleanup test
|
3572 |
test 'type_rule into'; |
3573 |
eval { $dbi->execute("drop table $table1") }; |
|
3574 |
$dbi->execute($create_table1_type); |
|
cleanup
|
3575 |
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table); |
3576 | ||
3577 | ||
cleanup test
|
3578 |
$dbi = DBIx::Custom->connect; |
3579 |
eval { $dbi->execute("drop table $table1") }; |
|
3580 |
$dbi->execute($create_table1_type); |
|
3581 | ||
cleanup
|
3582 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3583 |
$dbi->type_rule( |
3584 |
into1 => { |
|
3585 |
$date_typename => sub { '2010-' . $_[0] } |
|
3586 |
} |
|
cleanup test
|
3587 |
); |
cleanup test
|
3588 |
$dbi->insert({$key1 => '01-01'}, table => $table1); |
3589 |
$result = $dbi->select(table => $table1); |
|
3590 |
like($result->one->{$key1}, qr/^2010-01-01/); |
|
cleanup test
|
3591 | |
3592 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
3593 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3594 |
$dbi->execute($create_table1_type); |
cleanup
|
3595 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3596 |
$dbi->type_rule( |
3597 |
into1 => [ |
|
3598 |
[$date_typename, $datetime_typename] => sub { |
|
3599 |
my $value = shift; |
|
3600 |
$value =~ s/02/03/g; |
|
3601 |
return $value; |
|
3602 |
} |
|
3603 |
] |
|
3604 |
); |
|
3605 |
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1); |
|
3606 |
$result = $dbi->select(table => $table1); |
|
3607 |
$row = $result->one; |
|
3608 |
like($row->{$key1}, qr/^2010-01-03/); |
|
3609 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
cleanup test
|
3610 | |
cleanup test
|
3611 |
$dbi = DBIx::Custom->connect; |
3612 |
eval { $dbi->execute("drop table $table1") }; |
|
3613 |
$dbi->execute($create_table1_type); |
|
3614 |
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1); |
|
cleanup
|
3615 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3616 |
$dbi->type_rule( |
3617 |
into1 => [ |
|
3618 |
[$date_typename, $datetime_typename] => sub { |
|
3619 |
my $value = shift; |
|
3620 |
$value =~ s/02/03/g; |
|
3621 |
return $value; |
|
3622 |
} |
|
3623 |
] |
|
cleanup test
|
3624 |
); |
cleanup test
|
3625 |
$result = $dbi->execute( |
3626 |
"select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2", |
|
3627 |
param => {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'} |
|
cleanup test
|
3628 |
); |
cleanup test
|
3629 |
$row = $result->one; |
3630 |
like($row->{$key1}, qr/^2010-01-03/); |
|
3631 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
3632 | ||
3633 |
$dbi = DBIx::Custom->connect; |
|
3634 |
eval { $dbi->execute("drop table $table1") }; |
|
3635 |
$dbi->execute($create_table1_type); |
|
3636 |
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1); |
|
cleanup
|
3637 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3638 |
$dbi->type_rule( |
3639 |
into1 => [ |
|
3640 |
[$date_typename, $datetime_typename] => sub { |
|
3641 |
my $value = shift; |
|
3642 |
$value =~ s/02/03/g; |
|
3643 |
return $value; |
|
3644 |
} |
|
cleanup test
|
3645 |
] |
3646 |
); |
|
cleanup test
|
3647 |
$result = $dbi->execute( |
3648 |
"select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2", |
|
3649 |
param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'}, |
|
3650 |
table => $table1 |
|
3651 |
); |
|
3652 |
$row = $result->one; |
|
3653 |
like($row->{$key1}, qr/^2010-01-03/); |
|
3654 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
|
3655 | ||
3656 |
$dbi = DBIx::Custom->connect; |
|
3657 |
eval { $dbi->execute("drop table $table1") }; |
|
3658 |
$dbi->execute($create_table1_type); |
|
3659 |
$dbi->register_filter(convert => sub { |
|
3660 |
my $value = shift || ''; |
|
3661 |
$value =~ s/02/03/; |
|
3662 |
return $value; |
|
3663 |
}); |
|
cleanup
|
3664 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3665 |
$dbi->type_rule( |
3666 |
from1 => { |
|
3667 |
$date_datatype => 'convert', |
|
3668 |
}, |
|
3669 |
into1 => { |
|
3670 |
$date_typename => 'convert', |
|
3671 |
} |
|
3672 |
); |
|
3673 |
$dbi->insert({$key1 => '2010-02-02'}, table => $table1); |
|
3674 |
$result = $dbi->select(table => $table1); |
|
3675 |
like($result->fetch->[0], qr/^2010-03-03/); |
|
3676 | ||
3677 |
test 'type_rule and filter order'; |
|
3678 |
$dbi = DBIx::Custom->connect; |
|
3679 |
eval { $dbi->execute("drop table $table1") }; |
|
3680 |
$dbi->execute($create_table1_type); |
|
cleanup
|
3681 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3682 |
$dbi->type_rule( |
3683 |
into1 => { |
|
3684 |
$date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
|
3685 |
}, |
|
3686 |
into2 => { |
|
3687 |
$date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v } |
|
3688 |
}, |
|
3689 |
from1 => { |
|
3690 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v } |
|
3691 |
}, |
|
3692 |
from2 => { |
|
3693 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v } |
|
3694 |
} |
|
3695 |
); |
|
3696 |
$dbi->insert({$key1 => '2010-01-03'}, |
|
3697 |
table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }}); |
|
3698 |
$result = $dbi->select(table => $table1); |
|
3699 |
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v }); |
|
3700 |
like($result->fetch_first->[0], qr/^2010-01-09/); |
|
3701 | ||
3702 | ||
3703 |
$dbi = DBIx::Custom->connect; |
|
3704 |
eval { $dbi->execute("drop table $table1") }; |
|
3705 |
$dbi->execute($create_table1_type); |
|
cleanup
|
3706 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3707 |
$dbi->type_rule( |
3708 |
from1 => { |
|
3709 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
3710 |
}, |
|
3711 |
from2 => { |
|
3712 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
|
3713 |
}, |
|
3714 |
); |
|
3715 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
3716 |
$result = $dbi->select(table => $table1); |
|
cleanup
|
3717 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3718 |
$result->type_rule( |
3719 |
from1 => { |
|
3720 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v } |
|
3721 |
}, |
|
3722 |
from2 => { |
|
3723 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v } |
|
3724 |
} |
|
cleanup test
|
3725 |
); |
cleanup test
|
3726 |
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v }); |
3727 |
like($result->fetch_first->[0], qr/^2010-01-09/); |
|
cleanup test
|
3728 | |
cleanup test
|
3729 |
test 'type_rule_off'; |
cleanup test
|
3730 |
$dbi = DBIx::Custom->connect; |
cleanup test
|
3731 |
eval { $dbi->execute("drop table $table1") }; |
3732 |
$dbi->execute($create_table1_type); |
|
cleanup
|
3733 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3734 |
$dbi->type_rule( |
3735 |
from1 => { |
|
3736 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
3737 |
}, |
|
3738 |
into1 => { |
|
3739 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
3740 |
} |
|
cleanup test
|
3741 |
); |
cleanup test
|
3742 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1); |
3743 |
$result = $dbi->select(table => $table1, type_rule_off => 1); |
|
3744 |
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/); |
|
cleanup test
|
3745 | |
cleanup test
|
3746 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
3747 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3748 |
$dbi->execute($create_table1_type); |
cleanup
|
3749 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3750 |
$dbi->type_rule( |
3751 |
from1 => { |
|
3752 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
3753 |
}, |
|
3754 |
into1 => { |
|
3755 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
3756 |
} |
|
3757 |
); |
|
3758 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1); |
|
3759 |
$result = $dbi->select(table => $table1, type_rule_off => 1); |
|
3760 |
like($result->one->{$key1}, qr/^2010-01-04/); |
|
cleanup test
|
3761 | |
3762 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
3763 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3764 |
$dbi->execute($create_table1_type); |
cleanup
|
3765 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3766 |
$dbi->type_rule( |
3767 |
from1 => { |
|
3768 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
|
3769 |
}, |
|
3770 |
into1 => { |
|
3771 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
3772 |
} |
|
3773 |
); |
|
3774 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
3775 |
$result = $dbi->select(table => $table1); |
|
3776 |
like($result->one->{$key1}, qr/^2010-01-05/); |
|
cleanup test
|
3777 | |
3778 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
3779 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3780 |
$dbi->execute($create_table1_type); |
cleanup
|
3781 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3782 |
$dbi->type_rule( |
3783 |
from1 => { |
|
3784 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
|
3785 |
}, |
|
3786 |
into1 => { |
|
3787 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
3788 |
} |
|
3789 |
); |
|
3790 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
3791 |
$result = $dbi->select(table => $table1); |
|
3792 |
like($result->fetch->[0], qr/2010-01-05/); |
|
cleanup test
|
3793 | |
3794 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
3795 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3796 |
$dbi->execute($create_table1_type); |
3797 |
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }); |
|
cleanup
|
3798 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3799 |
$dbi->type_rule( |
3800 |
into1 => { |
|
3801 |
$date_typename => 'ppp' |
|
3802 |
} |
|
3803 |
); |
|
3804 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
3805 |
$result = $dbi->select(table => $table1); |
|
3806 |
like($result->one->{$key1}, qr/^2010-01-04/); |
|
cleanup test
|
3807 | |
cleanup test
|
3808 |
eval{$dbi->type_rule( |
3809 |
into1 => { |
|
3810 |
$date_typename => 'pp' |
|
3811 |
} |
|
3812 |
)}; |
|
3813 |
like($@, qr/not registered/); |
|
cleanup test
|
3814 | |
cleanup test
|
3815 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
3816 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3817 |
$dbi->execute($create_table1_type); |
cleanup test
|
3818 |
eval { |
cleanup test
|
3819 |
$dbi->type_rule( |
3820 |
from1 => { |
|
3821 |
Date => sub { $_[0] * 2 }, |
|
3822 |
} |
|
cleanup test
|
3823 |
); |
3824 |
}; |
|
cleanup test
|
3825 |
like($@, qr/lower/); |
cleanup test
|
3826 | |
cleanup test
|
3827 |
eval { |
3828 |
$dbi->type_rule( |
|
3829 |
into1 => { |
|
3830 |
Date => sub { $_[0] * 2 }, |
|
3831 |
} |
|
3832 |
); |
|
3833 |
}; |
|
3834 |
like($@, qr/lower/); |
|
cleanup test
|
3835 | |
3836 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
3837 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3838 |
$dbi->execute($create_table1_type); |
cleanup
|
3839 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3840 |
$dbi->type_rule( |
3841 |
from1 => { |
|
3842 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v } |
|
3843 |
}, |
|
3844 |
into1 => { |
|
3845 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
3846 |
} |
|
3847 |
); |
|
3848 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
3849 |
$result = $dbi->select(table => $table1); |
|
3850 |
$result->type_rule_off; |
|
3851 |
like($result->one->{$key1}, qr/^2010-01-04/); |
|
cleanup test
|
3852 | |
3853 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
3854 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3855 |
$dbi->execute($create_table1_type); |
cleanup
|
3856 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3857 |
$dbi->type_rule( |
3858 |
from1 => { |
|
3859 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }, |
|
3860 |
$datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
3861 |
}, |
|
cleanup test
|
3862 |
); |
cleanup test
|
3863 |
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1); |
3864 |
$result = $dbi->select(table => $table1); |
|
3865 |
$result->type_rule( |
|
3866 |
from1 => { |
|
3867 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
3868 |
} |
|
cleanup test
|
3869 |
); |
cleanup test
|
3870 |
$row = $result->one; |
3871 |
like($row->{$key1}, qr/^2010-01-05/); |
|
3872 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
3873 | ||
3874 |
$result = $dbi->select(table => $table1); |
|
3875 |
$result->type_rule( |
|
3876 |
from1 => { |
|
3877 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
3878 |
} |
|
cleanup test
|
3879 |
); |
cleanup test
|
3880 |
$row = $result->one; |
3881 |
like($row->{$key1}, qr/2010-01-05/); |
|
3882 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
|
3883 | ||
3884 |
$result = $dbi->select(table => $table1); |
|
3885 |
$result->type_rule( |
|
3886 |
from1 => { |
|
3887 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
3888 |
} |
|
3889 |
); |
|
3890 |
$row = $result->one; |
|
3891 |
like($row->{$key1}, qr/2010-01-05/); |
|
3892 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
|
3893 | ||
3894 |
$result = $dbi->select(table => $table1); |
|
3895 |
$result->type_rule( |
|
3896 |
from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }] |
|
3897 |
); |
|
3898 |
$row = $result->one; |
|
3899 |
like($row->{$key1}, qr/2010-01-05/); |
|
3900 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
|
3901 | ||
3902 |
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }); |
|
3903 |
$result = $dbi->select(table => $table1); |
|
3904 |
$result->type_rule( |
|
3905 |
from1 => [$date_datatype => 'five'] |
|
3906 |
); |
|
3907 |
$row = $result->one; |
|
3908 |
like($row->{$key1}, qr/^2010-01-05/); |
|
3909 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
3910 | ||
3911 |
$result = $dbi->select(table => $table1); |
|
3912 |
$result->type_rule( |
|
3913 |
from1 => [$date_datatype => undef] |
|
3914 |
); |
|
3915 |
$row = $result->one; |
|
3916 |
like($row->{$key1}, qr/^2010-01-03/); |
|
3917 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
|
cleanup test
|
3918 | |
3919 |
$dbi = DBIx::Custom->connect; |
|
finishied sqlite test cleanu...
|
3920 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3921 |
$dbi->execute($create_table1_type); |
cleanup
|
3922 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3923 |
$dbi->type_rule( |
3924 |
from1 => { |
|
3925 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }, |
|
3926 |
}, |
|
cleanup test
|
3927 |
); |
cleanup test
|
3928 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
3929 |
$result = $dbi->select(table => $table1); |
|
3930 |
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }); |
|
3931 |
like($result->one->{$key1}, qr/^2010-01-05/); |
|
cleanup test
|
3932 | |
cleanup test
|
3933 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
3934 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3935 |
$dbi->execute($create_table1_type); |
cleanup
|
3936 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3937 |
$dbi->type_rule( |
3938 |
from1 => { |
|
3939 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
3940 |
}, |
|
3941 |
); |
|
3942 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1); |
|
3943 |
$result = $dbi->select(table => $table1); |
|
3944 |
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }); |
|
3945 |
like($result->fetch->[0], qr/^2010-01-05/); |
|
test cleanup
|
3946 | |
cleanup test
|
3947 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
3948 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3949 |
$dbi->execute($create_table1_type); |
cleanup
|
3950 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3951 |
$dbi->type_rule( |
3952 |
into1 => { |
|
3953 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
3954 |
}, |
|
3955 |
into2 => { |
|
3956 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
3957 |
}, |
|
3958 |
from1 => { |
|
3959 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v } |
|
3960 |
}, |
|
3961 |
from2 => { |
|
3962 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v } |
|
3963 |
} |
|
3964 |
); |
|
3965 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1); |
|
3966 |
$result = $dbi->select(table => $table1); |
|
3967 |
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/); |
|
3968 |
$result = $dbi->select(table => $table1); |
|
3969 |
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/); |
|
test cleanup
|
3970 | |
cleanup test
|
3971 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
3972 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3973 |
$dbi->execute($create_table1_type); |
cleanup
|
3974 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3975 |
$dbi->type_rule( |
3976 |
into1 => { |
|
3977 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
3978 |
}, |
|
3979 |
into2 => { |
|
3980 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
3981 |
}, |
|
3982 |
from1 => { |
|
3983 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v } |
|
3984 |
}, |
|
3985 |
from2 => { |
|
3986 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v } |
|
3987 |
} |
|
3988 |
); |
|
3989 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1); |
|
3990 |
$result = $dbi->select(table => $table1); |
|
3991 |
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/); |
|
3992 |
$result = $dbi->select(table => $table1); |
|
3993 |
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/); |
|
test cleanup
|
3994 | |
cleanup test
|
3995 |
$dbi = DBIx::Custom->connect; |
finishied sqlite test cleanu...
|
3996 |
eval { $dbi->execute("drop table $table1") }; |
cleanup test
|
3997 |
$dbi->execute($create_table1_type); |
cleanup
|
3998 |
$dbi->user_column_info($user_column_info); |
cleanup test
|
3999 |
$dbi->type_rule( |
4000 |
into1 => { |
|
4001 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v } |
|
4002 |
}, |
|
4003 |
into2 => { |
|
4004 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v } |
|
4005 |
}, |
|
4006 |
from1 => { |
|
4007 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v } |
|
4008 |
}, |
|
4009 |
from2 => { |
|
4010 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v } |
|
4011 |
} |
|
4012 |
); |
|
4013 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1); |
|
4014 |
$result = $dbi->select(table => $table1); |
|
4015 |
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/); |
|
4016 |
$result = $dbi->select(table => $table1); |
|
4017 |
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/); |
|
test cleanup
|
4018 | |
added memory leak check test
|
4019 |
test 'join'; |
4020 |
$dbi = DBIx::Custom->connect; |
|
4021 |
eval { $dbi->execute("drop table $table1") }; |
|
4022 |
$dbi->execute($create_table1); |
|
4023 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
|
4024 |
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4}); |
|
4025 |
eval { $dbi->execute("drop table $table2") }; |
|
4026 |
$dbi->execute($create_table2); |
|
4027 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5}); |
|
4028 |
eval { $dbi->execute("drop table $table3") }; |
|
4029 |
$dbi->execute("create table $table3 ($key3 int, $key4 int)"); |
|
4030 |
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4}); |
|
4031 |
$rows = $dbi->select( |
|
4032 |
table => $table1, |
|
4033 |
column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3", |
|
4034 |
where => {"$table1.$key2" => 2}, |
|
4035 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1"] |
|
4036 |
)->all; |
|
4037 |
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]); |
|
4038 | ||
4039 |
$rows = $dbi->select( |
|
4040 |
table => $table1, |
|
4041 |
where => {$key1 => 1}, |
|
4042 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1"] |
|
4043 |
)->all; |
|
4044 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
|
4045 | ||
4046 |
$rows = $dbi->select( |
|
4047 |
table => $table1, |
|
4048 |
where => {$key1 => 1}, |
|
4049 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1", |
|
4050 |
"left outer join $table3 on $table2.$key3 = $table3.$key3"] |
|
4051 |
)->all; |
|
4052 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]); |
|
4053 | ||
4054 |
$rows = $dbi->select( |
|
4055 |
column => "$table3.$key4 as ${table3}__$key4", |
|
4056 |
table => $table1, |
|
4057 |
where => {"$table1.$key1" => 1}, |
|
4058 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1", |
|
4059 |
"left outer join $table3 on $table2.$key3 = $table3.$key3"] |
|
4060 |
)->all; |
|
4061 |
is_deeply($rows, [{"${table3}__$key4" => 4}]); |
|
4062 | ||
4063 |
$rows = $dbi->select( |
|
4064 |
column => "$table1.$key1 as ${table1}__$key1", |
|
4065 |
table => $table1, |
|
4066 |
where => {"$table3.$key4" => 4}, |
|
4067 |
join => ["left outer join $table2 on $table1.$key1 = $table2.$key1", |
|
4068 |
"left outer join $table3 on $table2.$key3 = $table3.$key3"] |
|
4069 |
)->all; |
|
4070 |
is_deeply($rows, [{"${table1}__$key1" => 1}]); |
|
4071 | ||
4072 |
$dbi = DBIx::Custom->connect; |
|
4073 |
eval { $dbi->execute("drop table $table1") }; |
|
4074 |
$dbi->execute($create_table1); |
|
4075 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
|
4076 |
eval { $dbi->execute("drop table $table2") }; |
|
4077 |
$dbi->execute($create_table2); |
|
4078 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5}); |
|
4079 |
$rows = $dbi->select( |
|
4080 |
table => $table1, |
|
4081 |
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", |
|
4082 |
where => {"$table1.$key2" => 2}, |
|
4083 |
join => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"], |
|
4084 |
)->all; |
|
4085 |
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], |
|
4086 |
'quote'); |
|
4087 | ||
4088 | ||
4089 |
$dbi = DBIx::Custom->connect; |
|
4090 |
eval { $dbi->execute("drop table $table1") }; |
|
4091 |
$dbi->execute($create_table1); |
|
4092 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
|
4093 |
$sql = <<"EOS"; |
|
4094 |
left outer join ( |
|
4095 |
select * from $table1 t1 |
|
4096 |
where t1.$key2 = ( |
|
4097 |
select max(t2.$key2) from $table1 t2 |
|
4098 |
where t1.$key1 = t2.$key1 |
|
4099 |
) |
|
4100 |
) $table3 on $table1.$key1 = $table3.$key1 |
|
4101 |
EOS |
|
4102 |
$join = [$sql]; |
|
4103 |
$rows = $dbi->select( |
|
4104 |
table => $table1, |
|
4105 |
column => "$table3.$key1 as ${table3}__$key1", |
|
4106 |
join => $join |
|
4107 |
)->all; |
|
4108 |
is_deeply($rows, [{"${table3}__$key1" => 1}]); |
|
4109 | ||
4110 |
$dbi = DBIx::Custom->connect; |
|
4111 |
eval { $dbi->execute("drop table $table1") }; |
|
4112 |
eval { $dbi->execute("drop table $table2") }; |
|
4113 |
$dbi->execute($create_table1); |
|
4114 |
$dbi->execute($create_table2); |
|
4115 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
|
4116 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4}); |
|
4117 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5}); |
|
4118 |
$result = $dbi->select( |
|
4119 |
table => $table1, |
|
4120 |
join => [ |
|
4121 |
"left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1" |
|
4122 |
] |
|
4123 |
); |
|
4124 |
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]); |
|
4125 |
$result = $dbi->select( |
|
4126 |
table => $table1, |
|
4127 |
column => [{$table2 => [$key3]}], |
|
4128 |
join => [ |
|
4129 |
"left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1" |
|
4130 |
] |
|
4131 |
); |
|
4132 |
is_deeply($result->all, [{"$table2.$key3" => 4}]); |
|
4133 |
$result = $dbi->select( |
|
4134 |
table => $table1, |
|
4135 |
column => [{$table2 => [$key3]}], |
|
4136 |
join => [ |
|
4137 |
"left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'" |
|
4138 |
] |
|
4139 |
); |
|
4140 |
is_deeply($result->all, [{"$table2.$key3" => 4}]); |
|
4141 | ||
4142 |
$dbi = DBIx::Custom->connect; |
|
4143 |
eval { $dbi->execute("drop table $table1") }; |
|
4144 |
eval { $dbi->execute("drop table $table2") }; |
|
4145 |
$dbi->execute($create_table1); |
|
4146 |
$dbi->execute($create_table2); |
|
4147 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
|
4148 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4}); |
|
4149 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5}); |
|
4150 |
$result = $dbi->select( |
|
4151 |
table => $table1, |
|
4152 |
column => [{$table2 => [$key3]}], |
|
4153 |
join => [ |
|
4154 |
{ |
|
4155 |
clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1", |
|
4156 |
table => [$table1, $table2] |
|
4157 |
} |
|
4158 |
] |
|
4159 |
); |
|
4160 |
is_deeply($result->all, [{"$table2.$key3" => 4}]); |
|
4161 | ||
improved join clause parsing
|
4162 |
$dbi = DBIx::Custom->connect; |
4163 |
eval { $dbi->execute("drop table $table1") }; |
|
4164 |
eval { $dbi->execute("drop table $table2") }; |
|
4165 |
$dbi->execute($create_table1); |
|
4166 |
$dbi->execute($create_table2); |
|
4167 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
|
4168 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4}); |
|
4169 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1}); |
|
4170 |
$result = $dbi->select( |
|
4171 |
table => $table1, |
|
4172 |
column => [{$table2 => [$key3]}], |
|
4173 |
join => [ |
|
4174 |
"left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'" |
|
4175 |
] |
|
4176 |
); |
|
4177 |
is_deeply($result->all, [{"$table2.$key3" => 4}]); |
|
4178 | ||
4179 |
$dbi = DBIx::Custom->connect; |
|
4180 |
eval { $dbi->execute("drop table $table1") }; |
|
4181 |
eval { $dbi->execute("drop table $table2") }; |
|
4182 |
$dbi->execute($create_table1); |
|
4183 |
$dbi->execute($create_table2); |
|
4184 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
|
4185 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4}); |
|
4186 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1}); |
|
4187 |
$result = $dbi->select( |
|
4188 |
table => $table1, |
|
4189 |
column => [{$table2 => [$key3]}], |
|
4190 |
join => [ |
|
4191 |
"left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1" |
|
4192 |
] |
|
4193 |
); |
|
4194 |
is_deeply($result->all, [{"$table2.$key3" => 4}]); |
|
4195 | ||
added memory leak check test
|
4196 |
test 'columns'; |
4197 |
$dbi = MyDBI1->connect; |
|
4198 |
$model = $dbi->model($table1); |
|
4199 | ||
- added EXPERIMENTAL DBIx::C...
|
4200 |
test 'count'; |
4201 |
$dbi = DBIx::Custom->connect; |
|
4202 |
eval { $dbi->execute("drop table $table1") }; |
|
4203 |
$dbi->execute($create_table1); |
|
4204 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
|
4205 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 3}); |
|
4206 |
is($dbi->count(table => $table1), 2); |
|
4207 |
is($dbi->count(table => $table1, where => {$key2 => 2}), 1); |
|
4208 |
$model = $dbi->create_model(table => $table1); |
|
4209 |
is($model->count, 2); |
|
cleanup test
|
4210 | |
cleanup test
|
4211 |
1; |