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