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