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