removed register_format()
|
1 |
use Test::More; |
2 |
use strict; |
|
3 |
use warnings; |
|
4 | ||
5 |
use utf8; |
|
6 |
use Encode qw/encode_utf8 decode_utf8/; |
|
add experimental DBIx::Custo...
|
7 |
use Data::Dumper; |
removed register_format()
|
8 | |
9 |
BEGIN { |
|
10 |
eval { require DBD::SQLite; 1 } |
|
11 |
or plan skip_all => 'DBD::SQLite required'; |
|
12 |
eval { DBD::SQLite->VERSION >= 1.25 } |
|
13 |
or plan skip_all => 'DBD::SQLite >= 1.25 required'; |
|
14 | ||
15 |
plan 'no_plan'; |
|
16 |
use_ok('DBIx::Custom'); |
|
17 |
} |
|
18 | ||
removed experimental base_ta...
|
19 |
use FindBin; |
20 |
use lib "$FindBin::Bin/dbix-custom-core-sqlite"; |
|
21 | ||
removed register_format()
|
22 |
# Function for test name |
table object call dbi object...
|
23 |
sub test { print "# $_[0]\n" } |
removed register_format()
|
24 | |
25 |
# Constant varialbes for test |
|
26 |
my $CREATE_TABLE = { |
|
27 |
0 => 'create table table1 (key1 char(255), key2 char(255));', |
|
28 |
1 => 'create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));', |
|
added experimental iterate_a...
|
29 |
2 => 'create table table2 (key1 char(255), key3 char(255));', |
30 |
3 => 'create table table1 (key1 Date, key2 datetime);' |
|
removed register_format()
|
31 |
}; |
32 | ||
add tests
|
33 |
my $SELECT_SOURCES = { |
removed register_format()
|
34 |
0 => 'select * from table1;' |
35 |
}; |
|
36 | ||
37 |
my $DROP_TABLE = { |
|
38 |
0 => 'drop table table1' |
|
39 |
}; |
|
40 | ||
41 |
my $NEW_ARGS = { |
|
42 |
0 => {data_source => 'dbi:SQLite:dbname=:memory:'} |
|
43 |
}; |
|
44 | ||
45 |
# Variables |
|
46 |
my $dbi; |
|
47 |
my $sth; |
|
renamed build_query to creat...
|
48 |
my $source; |
49 |
my @sources; |
|
add tests
|
50 |
my $select_SOURCE; |
51 |
my $insert_SOURCE; |
|
52 |
my $update_SOURCE; |
|
removed register_format()
|
53 |
my $params; |
54 |
my $sql; |
|
55 |
my $result; |
|
56 |
my $row; |
|
57 |
my @rows; |
|
58 |
my $rows; |
|
59 |
my $query; |
|
60 |
my @queries; |
|
61 |
my $select_query; |
|
62 |
my $insert_query; |
|
63 |
my $update_query; |
|
64 |
my $ret_val; |
|
added experimental iterate_a...
|
65 |
my $infos; |
add feture. all model class ...
|
66 |
my $model; |
added experimental DBIx::Cus...
|
67 |
my $where; |
removed register_format()
|
68 | |
69 |
# Prepare table |
|
70 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
71 |
$dbi->execute($CREATE_TABLE->{0}); |
|
72 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
73 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
74 | ||
75 |
test 'DBIx::Custom::Result test'; |
|
renamed build_query to creat...
|
76 |
$source = "select key1, key2 from table1"; |
77 |
$query = $dbi->create_query($source); |
|
removed register_format()
|
78 |
$result = $dbi->execute($query); |
79 | ||
80 |
@rows = (); |
|
81 |
while (my $row = $result->fetch) { |
|
82 |
push @rows, [@$row]; |
|
83 |
} |
|
cleanup
|
84 |
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch"); |
removed register_format()
|
85 | |
86 |
$result = $dbi->execute($query); |
|
87 |
@rows = (); |
|
88 |
while (my $row = $result->fetch_hash) { |
|
89 |
push @rows, {%$row}; |
|
90 |
} |
|
cleanup
|
91 |
is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "fetch_hash"); |
removed register_format()
|
92 | |
93 |
$result = $dbi->execute($query); |
|
94 |
$rows = $result->fetch_all; |
|
cleanup
|
95 |
is_deeply($rows, [[1, 2], [3, 4]], "fetch_all"); |
removed register_format()
|
96 | |
97 |
$result = $dbi->execute($query); |
|
removed reconnect method
|
98 |
$rows = $result->fetch_hash_all; |
cleanup
|
99 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "fetch_hash_all"); |
removed register_format()
|
100 | |
101 |
test 'Insert query return value'; |
|
102 |
$dbi->execute($DROP_TABLE->{0}); |
|
103 |
$dbi->execute($CREATE_TABLE->{0}); |
|
renamed update tag to update...
|
104 |
$source = "insert into table1 {insert_param key1 key2}"; |
renamed build_query to creat...
|
105 |
$query = $dbi->create_query($source); |
removed register_format()
|
106 |
$ret_val = $dbi->execute($query, param => {key1 => 1, key2 => 2}); |
cleanup
|
107 |
ok($ret_val); |
removed register_format()
|
108 | |
109 | ||
110 |
test 'Direct query'; |
|
111 |
$dbi->execute($DROP_TABLE->{0}); |
|
112 |
$dbi->execute($CREATE_TABLE->{0}); |
|
add tests
|
113 |
$insert_SOURCE = "insert into table1 {insert_param key1 key2}"; |
114 |
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2}); |
|
115 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
removed register_format()
|
116 |
$rows = $result->fetch_hash_all; |
cleanup
|
117 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
removed register_format()
|
118 | |
119 |
test 'Filter basic'; |
|
120 |
$dbi->execute($DROP_TABLE->{0}); |
|
121 |
$dbi->execute($CREATE_TABLE->{0}); |
|
122 |
$dbi->register_filter(twice => sub { $_[0] * 2}, |
|
123 |
three_times => sub { $_[0] * 3}); |
|
124 | ||
add tests
|
125 |
$insert_SOURCE = "insert into table1 {insert_param key1 key2};"; |
126 |
$insert_query = $dbi->create_query($insert_SOURCE); |
|
removed register_format()
|
127 |
$insert_query->filter({key1 => 'twice'}); |
128 |
$dbi->execute($insert_query, param => {key1 => 1, key2 => 2}); |
|
add tests
|
129 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
130 |
$rows = $result->filter({key2 => 'three_times'})->fetch_hash_all; |
cleanup
|
131 |
is_deeply($rows, [{key1 => 2, key2 => 6}], "filter fetch_filter"); |
removed register_format()
|
132 |
$dbi->execute($DROP_TABLE->{0}); |
133 | ||
134 |
test 'Filter in'; |
|
135 |
$dbi->execute($CREATE_TABLE->{0}); |
|
add tests
|
136 |
$insert_SOURCE = "insert into table1 {insert_param key1 key2};"; |
137 |
$insert_query = $dbi->create_query($insert_SOURCE); |
|
removed register_format()
|
138 |
$dbi->execute($insert_query, param => {key1 => 2, key2 => 4}); |
add tests
|
139 |
$select_SOURCE = "select * from table1 where {in table1.key1 2} and {in table1.key2 2}"; |
140 |
$select_query = $dbi->create_query($select_SOURCE); |
|
removed register_format()
|
141 |
$select_query->filter({'table1.key1' => 'twice'}); |
142 |
$result = $dbi->execute($select_query, param => {'table1.key1' => [1,5], 'table1.key2' => [2,4]}); |
|
143 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
144 |
is_deeply($rows, [{key1 => 2, key2 => 4}], "filter"); |
removed register_format()
|
145 | |
146 |
test 'DBIx::Custom::SQLTemplate basic tag'; |
|
147 |
$dbi->execute($DROP_TABLE->{0}); |
|
148 |
$dbi->execute($CREATE_TABLE->{1}); |
|
149 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
150 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
151 | ||
renamed build_query to creat...
|
152 |
$source = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};"; |
153 |
$query = $dbi->create_query($source); |
|
removed register_format()
|
154 |
$result = $dbi->execute($query, param => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5}); |
155 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
156 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag1"); |
removed register_format()
|
157 | |
renamed build_query to creat...
|
158 |
$source = "select * from table1 where {<= key1} and {like key2};"; |
159 |
$query = $dbi->create_query($source); |
|
removed register_format()
|
160 |
$result = $dbi->execute($query, param => {key1 => 1, key2 => '%2%'}); |
161 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
162 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag2"); |
removed register_format()
|
163 | |
164 |
test 'DIB::Custom::SQLTemplate in tag'; |
|
165 |
$dbi->execute($DROP_TABLE->{0}); |
|
166 |
$dbi->execute($CREATE_TABLE->{1}); |
|
167 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
168 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
169 | ||
renamed build_query to creat...
|
170 |
$source = "select * from table1 where {in key1 2};"; |
171 |
$query = $dbi->create_query($source); |
|
removed register_format()
|
172 |
$result = $dbi->execute($query, param => {key1 => [9, 1]}); |
173 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
174 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic"); |
removed register_format()
|
175 | |
176 |
test 'DBIx::Custom::SQLTemplate insert tag'; |
|
177 |
$dbi->execute("delete from table1"); |
|
add tests
|
178 |
$insert_SOURCE = 'insert into table1 {insert_param key1 key2 key3 key4 key5}'; |
179 |
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
removed register_format()
|
180 | |
add tests
|
181 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
182 |
$rows = $result->fetch_hash_all; |
cleanup
|
183 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic"); |
removed register_format()
|
184 | |
185 |
test 'DBIx::Custom::SQLTemplate update tag'; |
|
186 |
$dbi->execute("delete from table1"); |
|
add tests
|
187 |
$insert_SOURCE = "insert into table1 {insert_param key1 key2 key3 key4 key5}"; |
188 |
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
189 |
$dbi->execute($insert_SOURCE, param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
removed register_format()
|
190 | |
add tests
|
191 |
$update_SOURCE = 'update table1 {update_param key1 key2 key3 key4} where {= key5}'; |
192 |
$dbi->execute($update_SOURCE, param => {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5}); |
|
removed register_format()
|
193 | |
add tests
|
194 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
195 |
$rows = $result->fetch_hash_all; |
196 |
is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5}, |
|
cleanup
|
197 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "basic"); |
removed register_format()
|
198 | |
199 |
test 'Error case'; |
|
200 |
eval {DBIx::Custom->connect(data_source => 'dbi:SQLit')}; |
|
cleanup
|
201 |
ok($@, "connect error"); |
removed register_format()
|
202 | |
203 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
renamed build_query to creat...
|
204 |
eval{$dbi->create_query("{p }")}; |
cleanup
|
205 |
ok($@, "create_query invalid SQL template"); |
removed register_format()
|
206 | |
207 |
test 'insert'; |
|
208 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
209 |
$dbi->execute($CREATE_TABLE->{0}); |
|
210 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
211 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
add tests
|
212 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
213 |
$rows = $result->fetch_hash_all; |
cleanup
|
214 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic"); |
removed register_format()
|
215 | |
216 |
$dbi->execute('delete from table1'); |
|
217 |
$dbi->register_filter( |
|
218 |
twice => sub { $_[0] * 2 }, |
|
219 |
three_times => sub { $_[0] * 3 } |
|
220 |
); |
|
renamed default_query_filter...
|
221 |
$dbi->default_bind_filter('twice'); |
removed register_format()
|
222 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => 'three_times'}); |
add tests
|
223 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
224 |
$rows = $result->fetch_hash_all; |
cleanup
|
225 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter"); |
renamed default_query_filter...
|
226 |
$dbi->default_bind_filter(undef); |
removed register_format()
|
227 | |
228 |
$dbi->execute($DROP_TABLE->{0}); |
|
229 |
$dbi->execute($CREATE_TABLE->{0}); |
|
230 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, append => ' '); |
|
231 |
$rows = $dbi->select(table => 'table1')->fetch_hash_all; |
|
232 |
is_deeply($rows, [{key1 => 1, key2 => 2}], 'insert append'); |
|
233 | ||
changed argument of tag proc...
|
234 |
eval{$dbi->insert(table => 'table1', noexist => 1)}; |
cleanup
|
235 |
like($@, qr/noexist/, "invalid argument"); |
changed argument of tag proc...
|
236 | |
select() where can't receive...
|
237 |
eval{$dbi->insert(table => 'table', param => {';' => 1})}; |
238 |
like($@, qr/safety/); |
|
changed argument of tag proc...
|
239 | |
removed register_format()
|
240 |
test 'update'; |
241 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
242 |
$dbi->execute($CREATE_TABLE->{1}); |
|
243 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
244 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
245 |
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1}); |
|
add tests
|
246 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
247 |
$rows = $result->fetch_hash_all; |
248 |
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5}, |
|
249 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
cleanup
|
250 |
"basic"); |
removed register_format()
|
251 |
|
252 |
$dbi->execute("delete from table1"); |
|
253 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
254 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
255 |
$dbi->update(table => 'table1', param => {key2 => 12}, where => {key2 => 2, key3 => 3}); |
|
add tests
|
256 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
257 |
$rows = $result->fetch_hash_all; |
258 |
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5}, |
|
259 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
cleanup
|
260 |
"update key same as search key"); |
removed register_format()
|
261 | |
add tests
|
262 |
$dbi->update(table => 'table1', param => {key2 => [12]}, where => {key2 => 2, key3 => 3}); |
263 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
264 |
$rows = $result->fetch_hash_all; |
|
265 |
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5}, |
|
266 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
cleanup
|
267 |
"update key same as search key : param is array ref"); |
add tests
|
268 | |
removed register_format()
|
269 |
$dbi->execute("delete from table1"); |
270 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
271 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
272 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
273 |
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1}, |
|
many changed
|
274 |
filter => {key2 => sub { $_[0] * 2 }}); |
add tests
|
275 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
276 |
$rows = $result->fetch_hash_all; |
277 |
is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5}, |
|
278 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
cleanup
|
279 |
"filter"); |
removed register_format()
|
280 | |
281 |
$result = $dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1}, append => ' '); |
|
282 | ||
changed argument of tag proc...
|
283 |
eval{$dbi->update(table => 'table1', noexist => 1)}; |
cleanup
|
284 |
like($@, qr/noexist/, "invalid argument"); |
changed argument of tag proc...
|
285 | |
286 |
eval{$dbi->update(table => 'table1')}; |
|
cleanup
|
287 |
like($@, qr/where/, "not contain where"); |
changed argument of tag proc...
|
288 | |
improved delete() and update...
|
289 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
290 |
$dbi->execute($CREATE_TABLE->{0}); |
|
291 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
292 |
$where = $dbi->where; |
|
293 |
$where->clause(['and', '{= key1}', '{= key2}']); |
|
294 |
$where->param({key1 => 1, key2 => 2}); |
|
295 |
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where); |
|
296 |
$result = $dbi->select(table => 'table1'); |
|
297 |
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'delete() where'); |
|
298 | ||
299 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
300 |
$dbi->execute($CREATE_TABLE->{0}); |
|
301 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
302 |
$where = $dbi->where; |
|
303 |
$where->clause(['and', '{= key2}']); |
|
304 |
$where->param({key2 => 2}); |
|
305 |
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where); |
|
306 |
$result = $dbi->select(table => 'table1'); |
|
307 |
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'delete() where'); |
|
changed argument of tag proc...
|
308 | |
select() where can't receive...
|
309 |
eval{$dbi->update(table => 'table1', param => {';' => 1})}; |
310 |
like($@, qr/safety/); |
|
311 | ||
312 |
eval{$dbi->update(table => 'table1', param => {'key1' => 1}, where => {';' => 1})}; |
|
313 |
like($@, qr/safety/); |
|
314 | ||
removed register_format()
|
315 |
test 'update_all'; |
316 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
317 |
$dbi->execute($CREATE_TABLE->{1}); |
|
318 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
319 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
320 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
321 |
$dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'}); |
|
add tests
|
322 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
323 |
$rows = $result->fetch_hash_all; |
324 |
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5}, |
|
325 |
{key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}], |
|
cleanup
|
326 |
"filter"); |
removed register_format()
|
327 | |
328 | ||
329 |
test 'delete'; |
|
330 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
331 |
$dbi->execute($CREATE_TABLE->{0}); |
|
332 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
333 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
334 |
$dbi->delete(table => 'table1', where => {key1 => 1}); |
|
add tests
|
335 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
336 |
$rows = $result->fetch_hash_all; |
cleanup
|
337 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "basic"); |
removed register_format()
|
338 | |
339 |
$dbi->execute("delete from table1;"); |
|
340 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
341 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
342 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
343 |
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'}); |
|
add tests
|
344 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
345 |
$rows = $result->fetch_hash_all; |
cleanup
|
346 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter"); |
removed register_format()
|
347 | |
348 |
$dbi->delete(table => 'table1', where => {key1 => 1}, append => ' '); |
|
349 | ||
350 |
$dbi->delete_all(table => 'table1'); |
|
351 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
352 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
353 |
$dbi->delete(table => 'table1', where => {key1 => 1, key2 => 2}); |
|
354 |
$rows = $dbi->select(table => 'table1')->fetch_hash_all; |
|
cleanup
|
355 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "delete multi key"); |
removed register_format()
|
356 | |
changed argument of tag proc...
|
357 |
eval{$dbi->delete(table => 'table1', noexist => 1)}; |
cleanup
|
358 |
like($@, qr/noexist/, "invalid argument"); |
changed argument of tag proc...
|
359 | |
improved delete() and update...
|
360 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
361 |
$dbi->execute($CREATE_TABLE->{0}); |
|
362 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
363 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
364 |
$where = $dbi->where; |
|
365 |
$where->clause(['and', '{= key1}', '{= key2}']); |
|
366 |
$where->param({ke1 => 1, key2 => 2}); |
|
367 |
$dbi->delete(table => 'table1', where => $where); |
|
368 |
$result = $dbi->select(table => 'table1'); |
|
369 |
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 4}], 'delete() where'); |
|
changed argument of tag proc...
|
370 | |
removed register_format()
|
371 |
test 'delete error'; |
372 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
373 |
$dbi->execute($CREATE_TABLE->{0}); |
|
374 |
eval{$dbi->delete(table => 'table1')}; |
|
make delete() using where ob...
|
375 |
like($@, qr/"where" must be specified/, |
cleanup
|
376 |
"where key-value pairs not specified"); |
removed register_format()
|
377 | |
select() where can't receive...
|
378 |
eval{$dbi->delete(table => 'table1', where => {';' => 1})}; |
379 |
like($@, qr/safety/); |
|
380 | ||
removed register_format()
|
381 |
test 'delete_all'; |
382 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
383 |
$dbi->execute($CREATE_TABLE->{0}); |
|
384 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
385 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
386 |
$dbi->delete_all(table => 'table1'); |
|
add tests
|
387 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
388 |
$rows = $result->fetch_hash_all; |
cleanup
|
389 |
is_deeply($rows, [], "basic"); |
removed register_format()
|
390 | |
391 | ||
392 |
test 'select'; |
|
393 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
394 |
$dbi->execute($CREATE_TABLE->{0}); |
|
395 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
396 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
397 |
$rows = $dbi->select(table => 'table1')->fetch_hash_all; |
|
398 |
is_deeply($rows, [{key1 => 1, key2 => 2}, |
|
cleanup
|
399 |
{key1 => 3, key2 => 4}], "table"); |
removed register_format()
|
400 | |
update document
|
401 |
$rows = $dbi->select(table => 'table1', column => ['key1'])->fetch_hash_all; |
cleanup
|
402 |
is_deeply($rows, [{key1 => 1}, {key1 => 3}], "table and columns and where key"); |
removed register_format()
|
403 | |
404 |
$rows = $dbi->select(table => 'table1', where => {key1 => 1})->fetch_hash_all; |
|
cleanup
|
405 |
is_deeply($rows, [{key1 => 1, key2 => 2}], "table and columns and where key"); |
removed register_format()
|
406 | |
update document
|
407 |
$rows = $dbi->select(table => 'table1', column => ['key1'], where => {key1 => 3})->fetch_hash_all; |
cleanup
|
408 |
is_deeply($rows, [{key1 => 3}], "table and columns and where key"); |
removed register_format()
|
409 | |
410 |
$rows = $dbi->select(table => 'table1', append => "order by key1 desc limit 1")->fetch_hash_all; |
|
cleanup
|
411 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "append statement"); |
removed register_format()
|
412 | |
413 |
$dbi->register_filter(decrement => sub { $_[0] - 1 }); |
|
update document
|
414 |
$rows = $dbi->select(table => 'table1', where => {key1 => 2}, filter => {key1 => 'decrement'}) |
removed register_format()
|
415 |
->fetch_hash_all; |
cleanup
|
416 |
is_deeply($rows, [{key1 => 1, key2 => 2}], "filter"); |
removed register_format()
|
417 | |
418 |
$dbi->execute($CREATE_TABLE->{2}); |
|
419 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5}); |
|
420 |
$rows = $dbi->select( |
|
421 |
table => [qw/table1 table2/], |
|
select method column option ...
|
422 |
column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3', |
removed register_format()
|
423 |
where => {'table1.key2' => 2}, |
added commit method
|
424 |
relation => {'table1.key1' => 'table2.key1'} |
removed register_format()
|
425 |
)->fetch_hash_all; |
cleanup
|
426 |
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "relation : exists where"); |
added commit method
|
427 | |
428 |
$rows = $dbi->select( |
|
429 |
table => [qw/table1 table2/], |
|
430 |
column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'], |
|
431 |
relation => {'table1.key1' => 'table2.key1'} |
|
432 |
)->fetch_hash_all; |
|
cleanup
|
433 |
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "relation : no exists where"); |
removed register_format()
|
434 | |
changed argument of tag proc...
|
435 |
eval{$dbi->select(table => 'table1', noexist => 1)}; |
cleanup
|
436 |
like($@, qr/noexist/, "invalid argument"); |
changed argument of tag proc...
|
437 | |
438 | ||
removed register_format()
|
439 |
test 'fetch filter'; |
440 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
441 |
$dbi->register_filter( |
|
442 |
twice => sub { $_[0] * 2 }, |
|
443 |
three_times => sub { $_[0] * 3 } |
|
444 |
); |
|
445 |
$dbi->default_fetch_filter('twice'); |
|
446 |
$dbi->execute($CREATE_TABLE->{0}); |
|
447 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
448 |
$result = $dbi->select(table => 'table1'); |
|
449 |
$result->filter({key1 => 'three_times'}); |
|
removed reconnect method
|
450 |
$row = $result->fetch_hash_first; |
cleanup
|
451 |
is_deeply($row, {key1 => 3, key2 => 4}, "default_fetch_filter and filter"); |
removed register_format()
|
452 | |
453 |
test 'filters'; |
|
454 |
$dbi = DBIx::Custom->new; |
|
455 | ||
update document
|
456 |
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')), |
cleanup
|
457 |
'あ', "decode_utf8"); |
removed register_format()
|
458 | |
459 |
is($dbi->filters->{encode_utf8}->('あ'), |
|
cleanup
|
460 |
encode_utf8('あ'), "encode_utf8"); |
removed register_format()
|
461 | |
added commit method
|
462 |
test 'transaction'; |
463 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
464 |
$dbi->execute($CREATE_TABLE->{0}); |
|
removed DBIx::Custom commit ...
|
465 |
$dbi->dbh->begin_work; |
added commit method
|
466 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
467 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3}); |
|
removed DBIx::Custom commit ...
|
468 |
$dbi->dbh->commit; |
added commit method
|
469 |
$result = $dbi->select(table => 'table1'); |
470 |
is_deeply(scalar $result->fetch_hash_all, [{key1 => 1, key2 => 2}, {key1 => 2, key2 => 3}], |
|
cleanup
|
471 |
"commit"); |
added commit method
|
472 | |
473 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
474 |
$dbi->execute($CREATE_TABLE->{0}); |
|
removed DBIx::Custom commit ...
|
475 |
$dbi->dbh->begin_work(0); |
added commit method
|
476 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
removed DBIx::Custom commit ...
|
477 |
$dbi->dbh->rollback; |
added commit method
|
478 | |
479 |
$result = $dbi->select(table => 'table1'); |
|
cleanup
|
480 |
ok(! $result->fetch_first, "rollback"); |
add cache attribute
|
481 | |
482 |
test 'cache'; |
|
483 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
484 |
$dbi->execute($CREATE_TABLE->{0}); |
|
renamed build_query to creat...
|
485 |
$source = 'select * from table1 where {= key1} and {= key2};'; |
486 |
$dbi->create_query($source); |
|
487 |
is_deeply($dbi->{_cached}->{$source}, |
|
add table tag
|
488 |
{sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2'], tables => []}, "cache"); |
add cache attribute
|
489 | |
490 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
491 |
$dbi->execute($CREATE_TABLE->{0}); |
|
492 |
$dbi->{_cached} = {}; |
|
493 |
$dbi->cache(0); |
|
494 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
495 |
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache'); |
|
496 | ||
add tests
|
497 |
test 'execute'; |
498 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
499 |
$dbi->execute($CREATE_TABLE->{0}); |
|
removed experimental registe...
|
500 |
{ |
501 |
local $Carp::Verbose = 0; |
|
502 |
eval{$dbi->execute('select * frm table1')}; |
|
cleanup
|
503 |
like($@, qr/\Qselect * frm table1;/, "fail prepare"); |
504 |
like($@, qr/\.t /, "fail : not verbose"); |
|
removed experimental registe...
|
505 |
} |
506 |
{ |
|
507 |
local $Carp::Verbose = 1; |
|
508 |
eval{$dbi->execute('select * frm table1')}; |
|
cleanup
|
509 |
like($@, qr/Custom.*\.t /s, "fail : verbose"); |
removed experimental registe...
|
510 |
} |
add tests
|
511 | |
512 |
eval{$dbi->execute('select * from table1', no_exists => 1)}; |
|
cleanup
|
513 |
like($@, qr/\Q"no_exists" is invalid argument/, "invald SQL"); |
add tests
|
514 | |
515 |
$query = $dbi->create_query('select * from table1 where {= key1}'); |
|
516 |
$dbi->dbh->disconnect; |
|
517 |
eval{$dbi->execute($query, param => {key1 => {a => 1}})}; |
|
cleanup
|
518 |
ok($@, "execute fail"); |
add tests
|
519 | |
removed experimental registe...
|
520 |
{ |
521 |
local $Carp::Verbose = 0; |
|
522 |
eval{$dbi->create_query('select * from table1 where {0 key1}')}; |
|
cleanup
|
523 |
like($@, qr/\Q.t /, "caller spec : not vebose"); |
removed experimental registe...
|
524 |
} |
525 |
{ |
|
526 |
local $Carp::Verbose = 1; |
|
527 |
eval{$dbi->create_query('select * from table1 where {0 key1}')}; |
|
cleanup
|
528 |
like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose"); |
removed experimental registe...
|
529 |
} |
cleanup
|
530 | |
531 | ||
532 |
test 'transaction'; |
|
533 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
534 |
$dbi->execute($CREATE_TABLE->{0}); |
|
535 | ||
536 |
$dbi->begin_work; |
|
537 | ||
538 |
eval { |
|
539 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
540 |
die "Error"; |
|
541 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
542 |
}; |
|
543 | ||
544 |
$dbi->rollback if $@; |
|
545 | ||
546 |
$result = $dbi->select(table => 'table1'); |
|
547 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
548 |
is_deeply($rows, [], "rollback"); |
cleanup
|
549 | |
550 |
$dbi->begin_work; |
|
551 | ||
552 |
eval { |
|
553 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
554 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
555 |
}; |
|
556 | ||
557 |
$dbi->commit unless $@; |
|
558 | ||
559 |
$result = $dbi->select(table => 'table1'); |
|
560 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
561 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "commit"); |
cleanup
|
562 | |
563 |
$dbi->dbh->{AutoCommit} = 0; |
|
564 |
eval{ $dbi->begin_work }; |
|
cleanup
|
565 |
ok($@, "exception"); |
cleanup
|
566 |
$dbi->dbh->{AutoCommit} = 1; |
567 | ||
added helper method
|
568 | |
renamed helper to method.
|
569 |
test 'method'; |
added helper method
|
570 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
renamed helper to method.
|
571 |
$dbi->method( |
added helper method
|
572 |
one => sub { 1 } |
573 |
); |
|
renamed helper to method.
|
574 |
$dbi->method( |
added helper method
|
575 |
two => sub { 2 } |
576 |
); |
|
renamed helper to method.
|
577 |
$dbi->method({ |
added helper method
|
578 |
twice => sub { |
579 |
my $self = shift; |
|
580 |
return $_[0] * 2; |
|
581 |
} |
|
582 |
}); |
|
583 | ||
cleanup
|
584 |
is($dbi->one, 1, "first"); |
585 |
is($dbi->two, 2, "second"); |
|
586 |
is($dbi->twice(5), 10 , "second"); |
|
added helper method
|
587 | |
588 |
eval {$dbi->XXXXXX}; |
|
autoload DBI method
|
589 |
ok($@, "not exists"); |
added helper method
|
590 | |
renamed auto_filter to apply...
|
591 |
test 'out filter'; |
added auto_filter method
|
592 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
593 |
$dbi->execute($CREATE_TABLE->{0}); |
|
594 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
595 |
$dbi->register_filter(three_times => sub { $_[0] * 3}); |
|
renamed auto_filter to apply...
|
596 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
597 |
'table1', 'key1' => {out => 'twice', in => 'three_times'}, |
598 |
'key2' => {out => 'three_times', in => 'twice'}); |
|
added auto_filter method
|
599 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
600 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
601 |
$row = $result->fetch_hash_first; |
|
cleanup
|
602 |
is_deeply($row, {key1 => 2, key2 => 6}, "insert"); |
renamed auto_filter to apply...
|
603 |
$result = $dbi->select(table => 'table1'); |
604 |
$row = $result->fetch_hash_first; |
|
cleanup
|
605 |
is_deeply($row, {key1 => 6, key2 => 12}, "insert"); |
added auto_filter method
|
606 | |
fix bug : filter can't over...
|
607 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
608 |
$dbi->execute($CREATE_TABLE->{0}); |
|
609 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
610 |
$dbi->register_filter(three_times => sub { $_[0] * 3}); |
|
611 |
$dbi->apply_filter( |
|
612 |
'table1', 'key1' => {out => 'twice', in => 'three_times'}, |
|
613 |
'key2' => {out => 'three_times', in => 'twice'}); |
|
614 |
$dbi->apply_filter( |
|
615 |
'table1', 'key1' => {out => undef} |
|
616 |
); |
|
617 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
618 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
619 |
$row = $result->fetch_hash_first; |
|
620 |
is_deeply($row, {key1 => 1, key2 => 6}, "insert"); |
|
621 | ||
added auto_filter method
|
622 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
623 |
$dbi->execute($CREATE_TABLE->{0}); |
|
624 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
renamed auto_filter to apply...
|
625 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
626 |
'table1', 'key1' => {out => 'twice', in => 'twice'} |
added auto_filter method
|
627 |
); |
renamed auto_filter to apply...
|
628 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => undef}); |
added auto_filter method
|
629 |
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2}); |
630 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
631 |
$row = $result->fetch_hash_first; |
|
cleanup
|
632 |
is_deeply($row, {key1 => 4, key2 => 2}, "update"); |
added auto_filter method
|
633 | |
634 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
635 |
$dbi->execute($CREATE_TABLE->{0}); |
|
636 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
renamed auto_filter to apply...
|
637 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
638 |
'table1', 'key1' => {out => 'twice', in => 'twice'} |
added auto_filter method
|
639 |
); |
renamed auto_filter to apply...
|
640 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1=> undef}); |
added auto_filter method
|
641 |
$dbi->delete(table => 'table1', where => {key1 => 1}); |
642 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
643 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
644 |
is_deeply($rows, [], "delete"); |
added auto_filter method
|
645 | |
646 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
647 |
$dbi->execute($CREATE_TABLE->{0}); |
|
648 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
renamed auto_filter to apply...
|
649 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
650 |
'table1', 'key1' => {out => 'twice', in => 'twice'} |
added auto_filter method
|
651 |
); |
renamed auto_filter to apply...
|
652 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef}); |
added auto_filter method
|
653 |
$result = $dbi->select(table => 'table1', where => {key1 => 1}); |
654 |
$result->filter({'key2' => 'twice'}); |
|
655 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
656 |
is_deeply($rows, [{key1 => 4, key2 => 4}], "select"); |
added auto_filter method
|
657 | |
658 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
659 |
$dbi->execute($CREATE_TABLE->{0}); |
|
660 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
renamed auto_filter to apply...
|
661 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
662 |
'table1', 'key1' => {out => 'twice', in => 'twice'} |
added auto_filter method
|
663 |
); |
renamed auto_filter to apply...
|
664 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef}); |
added auto_filter method
|
665 |
$result = $dbi->execute("select * from table1 where {= key1} and {= key2};", |
666 |
param => {key1 => 1, key2 => 2}, |
|
renamed auto_filter to apply...
|
667 |
table => ['table1']); |
added auto_filter method
|
668 |
$rows = $result->fetch_hash_all; |
cleanup
|
669 |
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute"); |
added auto_filter method
|
670 | |
add table tag
|
671 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
672 |
$dbi->execute($CREATE_TABLE->{0}); |
|
673 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
674 |
$dbi->apply_filter( |
|
675 |
'table1', 'key1' => {out => 'twice', in => 'twice'} |
|
676 |
); |
|
677 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef}); |
|
678 |
$result = $dbi->execute("select * from {table table1} where {= key1} and {= key2};", |
|
679 |
param => {key1 => 1, key2 => 2}); |
|
680 |
$rows = $result->fetch_hash_all; |
|
681 |
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute table tag"); |
|
682 | ||
added auto_filter method
|
683 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
684 |
$dbi->execute($CREATE_TABLE->{0}); |
|
685 |
$dbi->execute($CREATE_TABLE->{2}); |
|
686 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
687 |
$dbi->register_filter(three_times => sub { $_[0] * 3 }); |
|
renamed auto_filter to apply...
|
688 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
689 |
'table1', 'key2' => {out => 'twice', in => 'twice'} |
added auto_filter method
|
690 |
); |
renamed auto_filter to apply...
|
691 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
692 |
'table2', 'key3' => {out => 'three_times', in => 'three_times'} |
added auto_filter method
|
693 |
); |
renamed auto_filter to apply...
|
694 |
$dbi->insert(table => 'table1', param => {key1 => 5, key2 => 2}, filter => {key2 => undef}); |
695 |
$dbi->insert(table => 'table2', param => {key1 => 5, key3 => 6}, filter => {key3 => undef}); |
|
added auto_filter method
|
696 |
$result = $dbi->select( |
697 |
table => ['table1', 'table2'], |
|
698 |
column => ['key2', 'key3'], |
|
699 |
where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'}); |
|
700 | ||
701 |
$result->filter({'key2' => 'twice'}); |
|
702 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
703 |
is_deeply($rows, [{key2 => 4, key3 => 18}], "select : join"); |
added auto_filter method
|
704 | |
705 |
$result = $dbi->select( |
|
706 |
table => ['table1', 'table2'], |
|
707 |
column => ['key2', 'key3'], |
|
708 |
where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'}); |
|
709 | ||
710 |
$result->filter({'key2' => 'twice'}); |
|
711 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
712 |
is_deeply($rows, [{key2 => 4, key3 => 18}], "select : join : omit"); |
added auto_filter method
|
713 | |
pod fix
|
714 |
test 'each_column'; |
added experimental iterate_a...
|
715 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
716 |
$dbi->execute($CREATE_TABLE->{2}); |
|
717 |
$dbi->execute($CREATE_TABLE->{3}); |
|
718 | ||
719 |
$infos = []; |
|
pod fix
|
720 |
$dbi->each_column(sub { |
removed experimental txn_sco...
|
721 |
my ($self, $table, $column, $cinfo) = @_; |
added experimental iterate_a...
|
722 |
|
723 |
if ($table =~ /^table/) { |
|
724 |
my $info = [$table, $column, $cinfo->{COLUMN_NAME}]; |
|
725 |
push @$infos, $info; |
|
726 |
} |
|
727 |
}); |
|
728 |
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos]; |
|
729 |
is_deeply($infos, |
|
730 |
[ |
|
731 |
['table1', 'key1', 'key1'], |
|
732 |
['table1', 'key2', 'key2'], |
|
733 |
['table2', 'key1', 'key1'], |
|
734 |
['table2', 'key3', 'key3'] |
|
735 |
] |
|
cleanup
|
736 |
|
added experimental iterate_a...
|
737 |
); |
added auto_filter method
|
738 | |
add examples
|
739 |
test 'limit'; |
740 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
741 |
$dbi->execute($CREATE_TABLE->{0}); |
|
742 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
743 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4}); |
|
744 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6}); |
|
renamed DBIx::Custom::TagPro...
|
745 |
$dbi->register_tag( |
add examples
|
746 |
limit => sub { |
747 |
my ($count, $offset) = @_; |
|
748 |
|
|
749 |
my $s = ''; |
|
750 |
$s .= "limit $count"; |
|
751 |
$s .= " offset $offset" if defined $offset; |
|
752 |
|
|
753 |
return [$s, []]; |
|
754 |
} |
|
755 |
); |
|
756 |
$rows = $dbi->select( |
|
757 |
table => 'table1', |
|
758 |
where => {key1 => 1}, |
|
759 |
append => "order by key2 {limit 1 0}" |
|
760 |
)->fetch_hash_all; |
|
cleanup
|
761 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
add examples
|
762 |
$rows = $dbi->select( |
763 |
table => 'table1', |
|
764 |
where => {key1 => 1}, |
|
765 |
append => "order by key2 {limit 2 1}" |
|
766 |
)->fetch_hash_all; |
|
cleanup
|
767 |
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]); |
add examples
|
768 |
$rows = $dbi->select( |
769 |
table => 'table1', |
|
770 |
where => {key1 => 1}, |
|
771 |
append => "order by key2 {limit 1}" |
|
772 |
)->fetch_hash_all; |
|
cleanup
|
773 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
added insert, update, update...
|
774 | |
remove DBIx::Custom::Model
|
775 |
test 'connect super'; |
776 |
{ |
|
777 |
package MyDBI; |
|
778 |
|
|
779 |
use base 'DBIx::Custom'; |
|
780 |
sub connect { |
|
781 |
my $self = shift->SUPER::connect(@_); |
|
782 |
|
|
783 |
return $self; |
|
784 |
} |
|
785 |
|
|
786 |
sub new { |
|
cleanup
|
787 |
my $self = shift->SUPER::new(@_); |
remove DBIx::Custom::Model
|
788 |
|
789 |
return $self; |
|
790 |
} |
|
791 |
} |
|
792 | ||
793 |
$dbi = MyDBI->connect($NEW_ARGS->{0}); |
|
794 |
$dbi->execute($CREATE_TABLE->{0}); |
|
795 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
cleanup
|
796 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1); |
remove DBIx::Custom::Model
|
797 | |
798 |
$dbi = MyDBI->new($NEW_ARGS->{0}); |
|
cleanup
|
799 |
$dbi->connect; |
remove DBIx::Custom::Model
|
800 |
$dbi->execute($CREATE_TABLE->{0}); |
801 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
cleanup
|
802 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1); |
added experimental DBIx::Cus...
|
803 | |
cleanup
|
804 |
{ |
805 |
package MyDBI2; |
|
806 |
|
|
807 |
use base 'DBIx::Custom'; |
|
808 |
sub connect { |
|
809 |
my $self = shift->SUPER::new(@_); |
|
810 |
$self->connect; |
|
811 |
|
|
812 |
return $self; |
|
813 |
} |
|
814 |
} |
|
815 | ||
816 |
$dbi = MyDBI->connect($NEW_ARGS->{0}); |
|
817 |
$dbi->execute($CREATE_TABLE->{0}); |
|
818 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
819 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1); |
|
added experimental DBIx::Cus...
|
820 | |
821 |
test 'end_filter'; |
|
822 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
823 |
$dbi->execute($CREATE_TABLE->{0}); |
|
824 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
825 |
$result = $dbi->select(table => 'table1'); |
|
826 |
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 }); |
|
827 |
$result->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 }); |
|
828 |
$row = $result->fetch_first; |
|
829 |
is_deeply($row, [6, 40]); |
|
830 | ||
all filter can receive array...
|
831 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
832 |
$dbi->execute($CREATE_TABLE->{0}); |
|
833 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
834 |
$result = $dbi->select(table => 'table1'); |
|
835 |
$result->filter([qw/key1 key2/] => sub { $_[0] * 2 }); |
|
836 |
$result->end_filter([[qw/key1 key2/] => sub { $_[0] * 3 }]); |
|
837 |
$row = $result->fetch_first; |
|
838 |
is_deeply($row, [6, 12]); |
|
839 | ||
840 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
841 |
$dbi->execute($CREATE_TABLE->{0}); |
|
842 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
843 |
$result = $dbi->select(table => 'table1'); |
|
844 |
$result->filter([[qw/key1 key2/] => sub { $_[0] * 2 }]); |
|
845 |
$result->end_filter([qw/key1 key2/] => sub { $_[0] * 3 }); |
|
846 |
$row = $result->fetch_first; |
|
847 |
is_deeply($row, [6, 12]); |
|
848 | ||
many changed
|
849 |
$dbi->register_filter(five_times => sub { $_[0] * 5 }); |
added experimental DBIx::Cus...
|
850 |
$result = $dbi->select(table => 'table1'); |
851 |
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 }); |
|
many changed
|
852 |
$result->end_filter({key1 => sub { $_[0] * 3 }, key2 => 'five_times' }); |
added experimental DBIx::Cus...
|
853 |
$row = $result->fetch_hash_first; |
854 |
is_deeply($row, {key1 => 6, key2 => 40}); |
|
fix select method empty wher...
|
855 | |
fix bug : filter can't over...
|
856 |
$dbi->register_filter(five_times => sub { $_[0] * 5 }); |
857 |
$dbi->apply_filter('table1', |
|
858 |
key1 => {end => sub { $_[0] * 3 } }, |
|
859 |
key2 => {end => 'five_times'} |
|
860 |
); |
|
861 |
$result = $dbi->select(table => 'table1'); |
|
862 |
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 }); |
|
863 |
$row = $result->fetch_hash_first; |
|
864 |
is_deeply($row, {key1 => 6, key2 => 40}, 'apply_filter'); |
|
865 | ||
866 |
$dbi->register_filter(five_times => sub { $_[0] * 5 }); |
|
867 |
$dbi->apply_filter('table1', |
|
868 |
key1 => {end => sub { $_[0] * 3 } }, |
|
869 |
key2 => {end => 'five_times'} |
|
870 |
); |
|
871 |
$result = $dbi->select(table => 'table1'); |
|
872 |
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 }); |
|
873 |
$result->filter(key1 => undef); |
|
874 |
$result->end_filter(key1 => undef); |
|
875 |
$row = $result->fetch_hash_first; |
|
876 |
is_deeply($row, {key1 => 1, key2 => 40}, 'apply_filter overwrite'); |
|
fix select method empty wher...
|
877 | |
added experimental DBIx::Cus...
|
878 |
test 'remove_end_filter and remove_filter'; |
added experimental DBIx::Cus...
|
879 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
880 |
$dbi->execute($CREATE_TABLE->{0}); |
|
881 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
882 |
$result = $dbi->select(table => 'table1'); |
|
added experimental DBIx::Cus...
|
883 |
$row = $result |
884 |
->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 }) |
|
885 |
->remove_filter |
|
886 |
->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 }) |
|
added experimental DBIx::Cus...
|
887 |
->remove_end_filter |
888 |
->fetch_first; |
|
added experimental DBIx::Cus...
|
889 |
is_deeply($row, [1, 2]); |
added experimental DBIx::Cus...
|
890 | |
fix select method empty wher...
|
891 |
test 'empty where select'; |
892 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
893 |
$dbi->execute($CREATE_TABLE->{0}); |
|
894 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
895 |
$result = $dbi->select(table => 'table1', where => {}); |
|
896 |
$row = $result->fetch_hash_first; |
|
897 |
is_deeply($row, {key1 => 1, key2 => 2}); |
|
898 | ||
added experimental sugar met...
|
899 |
test 'select query option'; |
900 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
901 |
$dbi->execute($CREATE_TABLE->{0}); |
|
902 |
$query = $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, query => 1); |
|
903 |
is(ref $query, 'DBIx::Custom::Query'); |
|
904 |
$query = $dbi->update(table => 'table1', where => {key1 => 1}, param => {key2 => 2}, query => 1); |
|
905 |
is(ref $query, 'DBIx::Custom::Query'); |
|
906 |
$query = $dbi->delete(table => 'table1', where => {key1 => 1}, query => 1); |
|
907 |
is(ref $query, 'DBIx::Custom::Query'); |
|
908 |
$query = $dbi->select(table => 'table1', where => {key1 => 1, key2 => 2}, query => 1); |
|
909 |
is(ref $query, 'DBIx::Custom::Query'); |
|
910 | ||
added experimental DBIx::Cus...
|
911 |
test 'DBIx::Custom::Where'; |
experimental extended select...
|
912 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
913 |
$dbi->execute($CREATE_TABLE->{0}); |
|
914 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
915 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
renamed DBIx::Custom::TagPro...
|
916 |
$where = $dbi->where->clause(['and', '{= key1}', '{= key2}']); |
917 |
is("$where", "where ( {= key1} and {= key2} )", 'no param'); |
|
918 | ||
added experimental DBIx::Cus...
|
919 |
$where = $dbi->where |
added test
|
920 |
->clause(['and', '{= key1}', '{= key2}']) |
added experimental DBIx::Cus...
|
921 |
->param({key1 => 1}); |
added test
|
922 | |
experimental extended select...
|
923 |
$result = $dbi->select( |
924 |
table => 'table1', |
|
added experimental DBIx::Cus...
|
925 |
where => $where |
experimental extended select...
|
926 |
); |
927 |
$row = $result->fetch_hash_all; |
|
928 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
|
929 | ||
added experimental DBIx::Cus...
|
930 |
$where = $dbi->where |
added test
|
931 |
->clause(['and', '{= key1}', '{= key2}']) |
added experimental DBIx::Cus...
|
932 |
->param({key1 => 1, key2 => 2}); |
experimental extended select...
|
933 |
$result = $dbi->select( |
934 |
table => 'table1', |
|
added experimental DBIx::Cus...
|
935 |
where => $where |
experimental extended select...
|
936 |
); |
937 |
$row = $result->fetch_hash_all; |
|
938 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
|
939 | ||
added experimental DBIx::Cus...
|
940 |
$where = $dbi->where |
added test
|
941 |
->clause(['and', '{= key1}', '{= key2}']) |
added experimental DBIx::Cus...
|
942 |
->param({}); |
experimental extended select...
|
943 |
$result = $dbi->select( |
944 |
table => 'table1', |
|
added experimental DBIx::Cus...
|
945 |
where => $where, |
experimental extended select...
|
946 |
); |
947 |
$row = $result->fetch_hash_all; |
|
948 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]); |
|
949 | ||
added experimental DBIx::Cus...
|
950 |
$where = $dbi->where |
added test
|
951 |
->clause(['and', ['or', '{> key1}', '{< key1}'], '{= key2}']) |
added experimental DBIx::Cus...
|
952 |
->param({key1 => [0, 3], key2 => 2}); |
experimental extended select...
|
953 |
$result = $dbi->select( |
954 |
table => 'table1', |
|
added experimental DBIx::Cus...
|
955 |
where => $where, |
added experimental not_exist...
|
956 |
); |
experimental extended select...
|
957 |
$row = $result->fetch_hash_all; |
958 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
|
959 | ||
added experimental DBIx::Cus...
|
960 |
$where = $dbi->where; |
961 |
$result = $dbi->select( |
|
962 |
table => 'table1', |
|
963 |
where => $where |
|
964 |
); |
|
965 |
$row = $result->fetch_hash_all; |
|
966 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]); |
|
967 | ||
experimental extended select...
|
968 |
eval { |
added experimental DBIx::Cus...
|
969 |
$where = $dbi->where |
added test
|
970 |
->clause(['uuu']); |
experimental extended select...
|
971 |
$result = $dbi->select( |
972 |
table => 'table1', |
|
added experimental DBIx::Cus...
|
973 |
where => $where |
experimental extended select...
|
974 |
); |
975 |
}; |
|
976 |
ok($@); |
|
977 | ||
added experimental DBIx::Cus...
|
978 |
$where = $dbi->where; |
979 |
is("$where", ''); |
|
980 | ||
added test
|
981 |
$where = $dbi->where |
982 |
->clause(['or', ('{= key1}') x 2]) |
|
983 |
->param({key1 => [1, 3]}); |
|
984 |
$result = $dbi->select( |
|
985 |
table => 'table1', |
|
986 |
where => $where, |
|
987 |
); |
|
988 |
$row = $result->fetch_hash_all; |
|
989 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]); |
|
990 | ||
991 |
$where = $dbi->where |
|
992 |
->clause(['or', ('{= key1}') x 2]) |
|
993 |
->param({key1 => [1]}); |
|
994 |
$result = $dbi->select( |
|
995 |
table => 'table1', |
|
996 |
where => $where, |
|
997 |
); |
|
998 |
$row = $result->fetch_hash_all; |
|
999 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
|
1000 | ||
1001 |
$where = $dbi->where |
|
1002 |
->clause(['or', ('{= key1}') x 2]) |
|
1003 |
->param({key1 => 1}); |
|
1004 |
$result = $dbi->select( |
|
1005 |
table => 'table1', |
|
1006 |
where => $where, |
|
1007 |
); |
|
1008 |
$row = $result->fetch_hash_all; |
|
1009 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
|
added experimental DBIx::Cus...
|
1010 | |
many changed
|
1011 |
$where = $dbi->where |
1012 |
->clause('{= key1}') |
|
1013 |
->param({key1 => 1}); |
|
1014 |
$result = $dbi->select( |
|
1015 |
table => 'table1', |
|
1016 |
where => $where, |
|
1017 |
); |
|
1018 |
$row = $result->fetch_hash_all; |
|
1019 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
|
1020 | ||
1021 |
$where = $dbi->where |
|
1022 |
->clause('{= key1} {= key2}') |
|
1023 |
->param({key1 => 1}); |
|
1024 |
eval{$where->to_string}; |
|
1025 |
like($@, qr/one column/); |
|
1026 | ||
added experimental not_exist...
|
1027 |
$where = $dbi->where |
1028 |
->clause('{= key1}') |
|
1029 |
->param([]); |
|
1030 |
eval{$where->to_string}; |
|
1031 |
like($@, qr/Parameter/); |
|
1032 | ||
1033 |
$where = $dbi->where |
|
1034 |
->clause(['or', ('{= key1}') x 3]) |
|
1035 |
->param({key1 => [$dbi->not_exists, 1, 3]}); |
|
1036 |
$result = $dbi->select( |
|
1037 |
table => 'table1', |
|
1038 |
where => $where, |
|
1039 |
); |
|
1040 |
$row = $result->fetch_hash_all; |
|
1041 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists'); |
|
1042 | ||
1043 |
$where = $dbi->where |
|
1044 |
->clause(['or', ('{= key1}') x 3]) |
|
1045 |
->param({key1 => [1, $dbi->not_exists, 3]}); |
|
1046 |
$result = $dbi->select( |
|
1047 |
table => 'table1', |
|
1048 |
where => $where, |
|
1049 |
); |
|
1050 |
$row = $result->fetch_hash_all; |
|
1051 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists'); |
|
1052 | ||
1053 |
$where = $dbi->where |
|
1054 |
->clause(['or', ('{= key1}') x 3]) |
|
1055 |
->param({key1 => [1, 3, $dbi->not_exists]}); |
|
1056 |
$result = $dbi->select( |
|
1057 |
table => 'table1', |
|
1058 |
where => $where, |
|
1059 |
); |
|
1060 |
$row = $result->fetch_hash_all; |
|
1061 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists'); |
|
1062 | ||
1063 |
$where = $dbi->where |
|
1064 |
->clause(['or', ('{= key1}') x 3]) |
|
1065 |
->param({key1 => [1, $dbi->not_exists, $dbi->not_exists]}); |
|
1066 |
$result = $dbi->select( |
|
1067 |
table => 'table1', |
|
1068 |
where => $where, |
|
1069 |
); |
|
1070 |
$row = $result->fetch_hash_all; |
|
1071 |
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists'); |
|
1072 | ||
1073 |
$where = $dbi->where |
|
1074 |
->clause(['or', ('{= key1}') x 3]) |
|
1075 |
->param({key1 => [$dbi->not_exists, 1, $dbi->not_exists]}); |
|
1076 |
$result = $dbi->select( |
|
1077 |
table => 'table1', |
|
1078 |
where => $where, |
|
1079 |
); |
|
1080 |
$row = $result->fetch_hash_all; |
|
1081 |
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists'); |
|
1082 | ||
1083 |
$where = $dbi->where |
|
1084 |
->clause(['or', ('{= key1}') x 3]) |
|
1085 |
->param({key1 => [$dbi->not_exists, $dbi->not_exists, 1]}); |
|
1086 |
$result = $dbi->select( |
|
1087 |
table => 'table1', |
|
1088 |
where => $where, |
|
1089 |
); |
|
1090 |
$row = $result->fetch_hash_all; |
|
1091 |
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists'); |
|
1092 | ||
1093 |
$where = $dbi->where |
|
1094 |
->clause(['or', ('{= key1}') x 3]) |
|
1095 |
->param({key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]}); |
|
1096 |
$result = $dbi->select( |
|
1097 |
table => 'table1', |
|
1098 |
where => $where, |
|
1099 |
); |
|
1100 |
$row = $result->fetch_hash_all; |
|
1101 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists'); |
|
1102 | ||
make delete() using where ob...
|
1103 |
$where = $dbi->where |
1104 |
->clause(['or', ('{= key1}') x 3]) |
|
1105 |
->param({key1 => []}); |
|
1106 |
$result = $dbi->select( |
|
1107 |
table => 'table1', |
|
1108 |
where => $where, |
|
1109 |
); |
|
1110 |
$row = $result->fetch_hash_all; |
|
1111 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists'); |
|
1112 | ||
1113 |
$where = $dbi->where |
|
1114 |
->clause(['and', '{> key1}', '{< key1}' ]) |
|
1115 |
->param({key1 => [2, $dbi->not_exists]}); |
|
1116 |
$result = $dbi->select( |
|
1117 |
table => 'table1', |
|
1118 |
where => $where, |
|
1119 |
); |
|
1120 |
$row = $result->fetch_hash_all; |
|
1121 |
is_deeply($row, [{key1 => 3, key2 => 4}], 'not_exists'); |
|
1122 | ||
1123 |
$where = $dbi->where |
|
1124 |
->clause(['and', '{> key1}', '{< key1}' ]) |
|
1125 |
->param({key1 => [$dbi->not_exists, 2]}); |
|
1126 |
$result = $dbi->select( |
|
1127 |
table => 'table1', |
|
1128 |
where => $where, |
|
1129 |
); |
|
1130 |
$row = $result->fetch_hash_all; |
|
1131 |
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists'); |
|
1132 | ||
1133 |
$where = $dbi->where |
|
1134 |
->clause(['and', '{> key1}', '{< key1}' ]) |
|
1135 |
->param({key1 => [$dbi->not_exists, $dbi->not_exists]}); |
|
1136 |
$result = $dbi->select( |
|
1137 |
table => 'table1', |
|
1138 |
where => $where, |
|
1139 |
); |
|
1140 |
$row = $result->fetch_hash_all; |
|
1141 |
is_deeply($row, [{key1 => 1, key2 => 2},{key1 => 3, key2 => 4}], 'not_exists'); |
|
1142 | ||
1143 |
$where = $dbi->where |
|
1144 |
->clause(['and', '{> key1}', '{< key1}' ]) |
|
1145 |
->param({key1 => [0, 2]}); |
|
1146 |
$result = $dbi->select( |
|
1147 |
table => 'table1', |
|
1148 |
where => $where, |
|
1149 |
); |
|
1150 |
$row = $result->fetch_hash_all; |
|
1151 |
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists'); |
|
1152 | ||
renamed dbi_options to dbi_o...
|
1153 |
test 'dbi_option default'; |
added experimental DBIx::Cus...
|
1154 |
$dbi = DBIx::Custom->new; |
renamed dbi_options to dbi_o...
|
1155 |
is_deeply($dbi->dbi_option, {}); |
added experimental DBIx::Cus...
|
1156 | |
added register_tag_processor
|
1157 |
test 'register_tag_processor'; |
1158 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1159 |
$dbi->register_tag_processor( |
|
1160 |
a => sub { 1 } |
|
1161 |
); |
|
1162 |
is($dbi->query_builder->tag_processors->{a}->(), 1); |
|
added experimental DBIx::Cus...
|
1163 | |
renamed DBIx::Custom::TagPro...
|
1164 |
test 'register_tag'; |
1165 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1166 |
$dbi->register_tag( |
|
1167 |
b => sub { 2 } |
|
1168 |
); |
|
1169 |
is($dbi->query_builder->tags->{b}->(), 2); |
|
1170 | ||
added table not specified ex...
|
1171 |
test 'table not specify exception'; |
1172 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1173 |
eval {$dbi->insert}; |
|
1174 |
like($@, qr/table/); |
|
1175 |
eval {$dbi->update}; |
|
1176 |
like($@, qr/table/); |
|
1177 |
eval {$dbi->delete}; |
|
1178 |
like($@, qr/table/); |
|
1179 |
eval {$dbi->select}; |
|
1180 |
like($@, qr/table/); |
|
many changed
|
1181 | |
1182 | ||
1183 |
test 'more tests'; |
|
1184 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1185 |
eval{$dbi->apply_filter('table', 'column', [])}; |
|
1186 |
like($@, qr/apply_filter/); |
|
1187 | ||
1188 |
eval{$dbi->apply_filter('table', 'column', {outer => 2})}; |
|
1189 |
like($@, qr/apply_filter/); |
|
1190 | ||
1191 |
$dbi->apply_filter( |
|
1192 | ||
1193 |
); |
|
1194 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1195 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1196 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1197 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
1198 |
$dbi->apply_filter('table1', 'key2', |
|
1199 |
{in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }}); |
|
1200 |
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->fetch_hash_all; |
|
1201 |
is_deeply($rows, [{key1 => 1, key2 => 6}]); |
|
1202 | ||
1203 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1204 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1205 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1206 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
1207 |
$dbi->apply_filter('table1', 'key2', {}); |
|
1208 |
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->fetch_hash_all; |
|
1209 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
|
1210 | ||
1211 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1212 |
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})}; |
|
1213 |
like($@, qr/not registered/); |
|
1214 |
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})}; |
|
1215 |
like($@, qr/not registered/); |
|
renamed helper to method.
|
1216 |
$dbi->method({one => sub { 1 }}); |
many changed
|
1217 |
is($dbi->one, 1); |
1218 | ||
1219 |
eval{DBIx::Custom->connect()}; |
|
1220 |
like($@, qr/connect/); |
|
1221 | ||
1222 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1223 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1224 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1225 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, |
|
1226 |
filter => {key1 => 'twice'}); |
|
1227 |
$row = $dbi->select(table => 'table1')->fetch_hash_first; |
|
1228 |
is_deeply($row, {key1 => 2, key2 => 2}); |
|
1229 |
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, |
|
1230 |
filter => {key1 => 'no'}) }; |
|
1231 |
like($@, qr//); |
|
1232 | ||
1233 |
$dbi->register_filter(one => sub { }); |
|
1234 |
$dbi->default_fetch_filter('one'); |
|
1235 |
ok($dbi->default_fetch_filter); |
|
1236 |
$dbi->default_bind_filter('one'); |
|
1237 |
ok($dbi->default_bind_filter); |
|
1238 |
eval{$dbi->default_fetch_filter('no')}; |
|
1239 |
like($@, qr/not registered/); |
|
1240 |
eval{$dbi->default_bind_filter('no')}; |
|
1241 |
like($@, qr/not registered/); |
|
1242 |
$dbi->default_bind_filter(undef); |
|
1243 |
ok(!defined $dbi->default_bind_filter); |
|
1244 |
$dbi->default_fetch_filter(undef); |
|
1245 |
ok(!defined $dbi->default_fetch_filter); |
|
1246 |
eval {$dbi->execute('select * from table1 {= author') }; |
|
1247 |
like($@, qr/Tag not finished/); |
|
1248 | ||
1249 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1250 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1251 |
$dbi->register_filter(one => sub { 1 }); |
|
1252 |
$result = $dbi->select(table => 'table1'); |
|
1253 |
eval {$result->filter(key1 => 'no')}; |
|
1254 |
like($@, qr/not registered/); |
|
1255 |
eval {$result->end_filter(key1 => 'no')}; |
|
1256 |
like($@, qr/not registered/); |
|
1257 |
$result->default_filter(undef); |
|
1258 |
ok(!defined $result->default_filter); |
|
1259 |
$result->default_filter('one'); |
|
1260 |
is($result->default_filter->(), 1); |
|
1261 | ||
renamed dbi_options to dbi_o...
|
1262 |
test 'dbi_option'; |
1263 |
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:', |
|
1264 |
dbi_option => {PrintError => 1}); |
|
1265 |
ok($dbi->dbh->{PrintError}); |
|
1266 |
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:', |
|
1267 |
dbi_options => {PrintError => 1}); |
|
1268 |
ok($dbi->dbh->{PrintError}); |
|
1269 | ||
added experimental DBIx::Cus...
|
1270 |
test 'DBIx::Custom::Result stash()'; |
1271 |
$result = DBIx::Custom::Result->new; |
|
1272 |
is_deeply($result->stash, {}, 'default'); |
|
1273 |
$result->stash->{foo} = 1; |
|
1274 |
is($result->stash->{foo}, 1, 'get and set'); |
|
table object call dbi object...
|
1275 | |
fix bug : filter can't over...
|
1276 |
test 'filter __ expression'; |
1277 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1278 |
$dbi->execute('create table company (id, name, location_id)'); |
|
1279 |
$dbi->execute('create table location (id, name)'); |
|
1280 |
$dbi->apply_filter('location', |
|
1281 |
name => {in => sub { uc $_[0] } } |
|
1282 |
); |
|
1283 | ||
1284 |
$dbi->insert(table => 'company', param => {id => 1, name => 'a', location_id => 2}); |
|
1285 |
$dbi->insert(table => 'location', param => {id => 2, name => 'b'}); |
|
1286 | ||
1287 |
$result = $dbi->select( |
|
1288 |
table => ['company', 'location'], relation => {'company.location_id' => 'location.id'}, |
|
1289 |
column => ['location.name as location__name'] |
|
1290 |
); |
|
1291 |
is($result->fetch_first->[0], 'B'); |
|
1292 | ||
add experimental DBIx::Custo...
|
1293 |
$result = $dbi->select( |
1294 |
table => 'company', relation => {'company.location_id' => 'location.id'}, |
|
1295 |
column => ['location.name as location__name'] |
|
1296 |
); |
|
1297 |
is($result->fetch_first->[0], 'B'); |
|
1298 | ||
add experimental selection o...
|
1299 |
test 'selection'; |
1300 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1301 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1302 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1303 |
$result = $dbi->select(selection => '* from table1', where => {key1 => 1}); |
|
1304 |
is_deeply($result->fetch_hash_all, [{key1 => 1, key2 => 2}]); |
|
removed experimental base_ta...
|
1305 | |
add feture. all model class ...
|
1306 |
test 'Model class'; |
removed experimental base_ta...
|
1307 |
use MyDBI1; |
1308 |
$dbi = MyDBI1->connect($NEW_ARGS->{0}); |
|
1309 |
$dbi->execute("create table book (title, author)"); |
|
add feture. all model class ...
|
1310 |
$model = $dbi->model('book'); |
1311 |
$model->insert({title => 'a', author => 'b'}); |
|
1312 |
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic'); |
|
removed experimental base_ta...
|
1313 |
$dbi->execute("create table company (name)"); |
add feture. all model class ...
|
1314 |
$model = $dbi->model('company'); |
1315 |
$model->insert({name => 'a'}); |
|
1316 |
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic'); |
|
add models() attribute
|
1317 |
is($dbi->models->{'book'}, $dbi->model('book')); |
1318 |
is($dbi->models->{'company'}, $dbi->model('company')); |
|
removed experimental base_ta...
|
1319 | |
add feture. all model class ...
|
1320 |
$dbi->model('book'); |
1321 |
eval{$dbi->model('book')->no_exists}; |
|
removed experimental base_ta...
|
1322 |
like($@, qr/locate/); |
1323 | ||
1324 |
{ |
|
1325 |
package MyDBI4; |
|
1326 | ||
1327 |
use strict; |
|
1328 |
use warnings; |
|
1329 | ||
1330 |
use base 'DBIx::Custom'; |
|
1331 | ||
1332 |
sub connect { |
|
1333 |
my $self = shift->SUPER::connect(@_); |
|
1334 |
|
|
add feture. all model class ...
|
1335 |
$self->include_model( |
1336 |
MyModel2 => [ |
|
removed experimental base_ta...
|
1337 |
'book', |
add experimental DBIx::Custo...
|
1338 |
{class => 'Company', name => 'company'} |
removed experimental base_ta...
|
1339 |
] |
1340 |
); |
|
1341 |
} |
|
1342 | ||
add feture. all model class ...
|
1343 |
package MyModel2::Base1; |
removed experimental base_ta...
|
1344 | |
1345 |
use strict; |
|
1346 |
use warnings; |
|
1347 | ||
add feture. all model class ...
|
1348 |
use base 'DBIx::Custom::Model'; |
removed experimental base_ta...
|
1349 | |
add feture. all model class ...
|
1350 |
package MyModel2::book; |
removed experimental base_ta...
|
1351 | |
1352 |
use strict; |
|
1353 |
use warnings; |
|
1354 | ||
add feture. all model class ...
|
1355 |
use base 'MyModel2::Base1'; |
removed experimental base_ta...
|
1356 | |
1357 |
sub insert { |
|
1358 |
my ($self, $param) = @_; |
|
1359 |
|
|
1360 |
return $self->SUPER::insert(param => $param); |
|
1361 |
} |
|
1362 | ||
1363 |
sub list { shift->select; } |
|
1364 | ||
add feture. all model class ...
|
1365 |
package MyModel2::Company; |
removed experimental base_ta...
|
1366 | |
1367 |
use strict; |
|
1368 |
use warnings; |
|
1369 | ||
add feture. all model class ...
|
1370 |
use base 'MyModel2::Base1'; |
removed experimental base_ta...
|
1371 | |
1372 |
sub insert { |
|
1373 |
my ($self, $param) = @_; |
|
1374 |
|
|
1375 |
return $self->SUPER::insert(param => $param); |
|
1376 |
} |
|
1377 | ||
1378 |
sub list { shift->select; } |
|
1379 |
} |
|
1380 |
$dbi = MyDBI4->connect($NEW_ARGS->{0}); |
|
1381 |
$dbi->execute("create table book (title, author)"); |
|
add feture. all model class ...
|
1382 |
$model = $dbi->model('book'); |
1383 |
$model->insert({title => 'a', author => 'b'}); |
|
1384 |
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic'); |
|
removed experimental base_ta...
|
1385 |
$dbi->execute("create table company (name)"); |
add feture. all model class ...
|
1386 |
$model = $dbi->model('company'); |
1387 |
$model->insert({name => 'a'}); |
|
1388 |
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic'); |
|
1389 | ||
1390 |
{ |
|
1391 |
package MyDBI5; |
|
1392 | ||
1393 |
use strict; |
|
1394 |
use warnings; |
|
1395 | ||
1396 |
use base 'DBIx::Custom'; |
|
1397 | ||
1398 |
sub connect { |
|
1399 |
my $self = shift->SUPER::connect(@_); |
|
1400 |
|
|
1401 |
$self->include_model('MyModel4'); |
|
1402 |
} |
|
1403 |
} |
|
1404 |
$dbi = MyDBI5->connect($NEW_ARGS->{0}); |
|
1405 |
$dbi->execute("create table company (name)"); |
|
1406 |
$model = $dbi->model('company'); |
|
1407 |
$model->insert({name => 'a'}); |
|
1408 |
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'include all model'); |
|
1409 |
$model = $dbi->model('book'); |
|
1410 |
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'include all model'); |
|
1411 | ||
add DBIx::Custom::Model fore...
|
1412 |
test 'primary_key'; |
1413 |
use MyDBI1; |
|
1414 |
$dbi = MyDBI1->connect($NEW_ARGS->{0}); |
|
1415 |
$model = $dbi->model('book'); |
|
1416 |
$model->primary_key(['id', 'number']); |
|
1417 |
is_deeply($model->primary_key, ['id', 'number']); |
|
1418 | ||
add DBIx::Custom::Model colu...
|
1419 |
test 'columns'; |
1420 |
use MyDBI1; |
|
1421 |
$dbi = MyDBI1->connect($NEW_ARGS->{0}); |
|
1422 |
$model = $dbi->model('book'); |
|
1423 |
$model->columns(['id', 'number']); |
|
1424 |
is_deeply($model->columns, ['id', 'number']); |
|
add feture. all model class ...
|
1425 | |
add experimental setup_model...
|
1426 |
test 'setup_model'; |
1427 |
use MyDBI1; |
|
1428 |
$dbi = MyDBI1->connect($NEW_ARGS->{0}); |
|
1429 |
$dbi->execute('create table book (id)'); |
|
1430 |
$dbi->execute('create table company (id, name);'); |
|
1431 |
$dbi->execute('create table test (id, name, primary key (id, name));'); |
|
1432 |
$dbi->setup_model; |
|
1433 |
is_deeply($dbi->model('book')->columns, ['id']); |
|
1434 |
is_deeply($dbi->model('company')->columns, ['id', 'name']); |
|
add experimental update_at()...
|
1435 | |
1436 |
test 'delete_at'; |
|
1437 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1438 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1439 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1440 |
$dbi->delete_at( |
|
1441 |
table => 'table1', |
|
1442 |
primary_key => ['key1', 'key2'], |
|
1443 |
where => [1, 2], |
|
1444 |
); |
|
1445 |
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []); |
|
1446 | ||
1447 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1448 |
$dbi->delete_at( |
|
1449 |
table => 'table1', |
|
1450 |
primary_key => 'key1', |
|
1451 |
where => 1, |
|
1452 |
); |
|
1453 |
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []); |
|
1454 | ||
- added experimental DBIx::C...
|
1455 |
test 'insert_at'; |
1456 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1457 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1458 |
$dbi->insert_at( |
|
1459 |
primary_key => ['key1', 'key2'], |
|
1460 |
table => 'table1', |
|
1461 |
where => [1, 2], |
|
1462 |
param => {key3 => 3} |
|
1463 |
); |
|
1464 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1); |
|
1465 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2); |
|
1466 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 3); |
|
1467 | ||
1468 |
$dbi->delete_all(table => 'table1'); |
|
add experimental update_at()...
|
1469 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
- added experimental DBIx::C...
|
1470 |
$dbi->insert_at( |
1471 |
primary_key => 'key1', |
|
add experimental update_at()...
|
1472 |
table => 'table1', |
- added experimental DBIx::C...
|
1473 |
where => 1, |
1474 |
param => {key2 => 2, key3 => 3} |
|
add experimental update_at()...
|
1475 |
); |
1476 | ||
- added experimental DBIx::C...
|
1477 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1); |
1478 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2); |
|
1479 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 3); |
|
1480 | ||
1481 |
eval { |
|
1482 |
$dbi->insert_at( |
|
1483 |
table => 'table1', |
|
1484 |
primary_key => ['key1', 'key2'], |
|
1485 |
where => {}, |
|
1486 |
param => {key1 => 1, key2 => 2, key3 => 3}, |
|
1487 |
); |
|
1488 |
}; |
|
1489 |
like($@, qr/must be/); |
|
add experimental update_at()...
|
1490 | |
1491 |
test 'update_at'; |
|
1492 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1493 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1494 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1495 |
$dbi->update_at( |
|
1496 |
table => 'table1', |
|
1497 |
primary_key => ['key1', 'key2'], |
|
1498 |
where => [1, 2], |
|
1499 |
param => {key3 => 4} |
|
1500 |
); |
|
1501 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1); |
|
1502 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2); |
|
1503 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 4); |
|
1504 | ||
1505 |
$dbi->delete_all(table => 'table1'); |
|
1506 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1507 |
$dbi->update_at( |
|
1508 |
table => 'table1', |
|
1509 |
primary_key => 'key1', |
|
1510 |
where => 1, |
|
1511 |
param => {key3 => 4} |
|
1512 |
); |
|
1513 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1); |
|
1514 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2); |
|
1515 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 4); |
|
1516 | ||
1517 |
test 'select_at'; |
|
1518 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1519 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1520 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1521 |
$result = $dbi->select_at( |
|
1522 |
table => 'table1', |
|
1523 |
primary_key => ['key1', 'key2'], |
|
1524 |
where => [1, 2] |
|
1525 |
); |
|
1526 |
$row = $result->fetch_hash_first; |
|
1527 |
is($row->{key1}, 1); |
|
1528 |
is($row->{key2}, 2); |
|
1529 |
is($row->{key3}, 3); |
|
1530 | ||
1531 |
$dbi->delete_all(table => 'table1'); |
|
1532 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1533 |
$result = $dbi->select_at( |
|
1534 |
table => 'table1', |
|
1535 |
primary_key => 'key1', |
|
1536 |
where => 1, |
|
1537 |
); |
|
1538 |
$row = $result->fetch_hash_first; |
|
1539 |
is($row->{key1}, 1); |
|
1540 |
is($row->{key2}, 2); |
|
1541 |
is($row->{key3}, 3); |
|
1542 | ||
1543 |
$dbi->delete_all(table => 'table1'); |
|
1544 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1545 |
$result = $dbi->select_at( |
|
1546 |
table => 'table1', |
|
1547 |
primary_key => ['key1', 'key2'], |
|
1548 |
param => {key1 => 1, key2 => 2}, |
|
1549 |
); |
|
1550 |
$row = $result->fetch_hash_first; |
|
1551 |
is($row->{key1}, 1); |
|
1552 |
is($row->{key2}, 2); |
|
1553 |
is($row->{key3}, 3); |
|
1554 | ||
- added experimental DBIx::C...
|
1555 |
eval { |
1556 |
$result = $dbi->select_at( |
|
1557 |
table => 'table1', |
|
1558 |
primary_key => ['key1', 'key2'], |
|
1559 |
where => {}, |
|
1560 |
param => {key1 => 1, key2 => 2}, |
|
1561 |
); |
|
1562 |
}; |
|
1563 |
like($@, qr/must be/); |
|
1564 | ||
1565 |
eval { |
|
1566 |
$result = $dbi->update_at( |
|
1567 |
table => 'table1', |
|
1568 |
primary_key => ['key1', 'key2'], |
|
1569 |
where => {}, |
|
1570 |
param => {key1 => 1, key2 => 2}, |
|
1571 |
); |
|
1572 |
}; |
|
1573 |
like($@, qr/must be/); |
|
1574 | ||
1575 |
eval { |
|
1576 |
$result = $dbi->delete_at( |
|
1577 |
table => 'table1', |
|
1578 |
primary_key => ['key1', 'key2'], |
|
1579 |
where => {}, |
|
1580 |
param => {key1 => 1, key2 => 2}, |
|
1581 |
); |
|
1582 |
}; |
|
1583 |
like($@, qr/must be/); |
|
add experimental update_at()...
|
1584 | |
add experimental DBIx::Custo...
|
1585 |
test 'columns'; |
1586 |
use MyDBI1; |
|
1587 |
$dbi = MyDBI1->connect($NEW_ARGS->{0}); |
|
1588 |
$model = $dbi->model('book'); |
|
1589 |
$model->relation({'book.id' => 'company.id'}); |
|
1590 |
is_deeply($model->relation, {'book.id' => 'company.id'}); |
|
add experimental DBIx::Custo...
|
1591 | |
1592 | ||
1593 |
test 'model delete_at'; |
|
1594 |
{ |
|
1595 |
package MyDBI6; |
|
1596 |
|
|
1597 |
use base 'DBIx::Custom'; |
|
1598 |
|
|
1599 |
sub connect { |
|
1600 |
my $self = shift->SUPER::connect(@_); |
|
1601 |
|
|
1602 |
$self->include_model('MyModel5'); |
|
1603 |
|
|
1604 |
return $self; |
|
1605 |
} |
|
1606 |
} |
|
1607 |
$dbi = MyDBI6->connect($NEW_ARGS->{0}); |
|
1608 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1609 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1610 |
$dbi->model('table1')->delete_at(where => [1, 2]); |
|
1611 |
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []); |
|
add experimental DBIx::Custo...
|
1612 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
1613 |
$dbi->model('table1_1')->delete_at(where => [1, 2]); |
|
1614 |
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []); |
|
1615 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1616 |
$dbi->model('table1_3')->delete_at(where => [1, 2]); |
|
1617 |
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []); |
|
add experimental DBIx::Custo...
|
1618 | |
- added experimental DBIx::C...
|
1619 |
test 'model insert_at'; |
1620 |
$dbi = MyDBI6->connect($NEW_ARGS->{0}); |
|
1621 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1622 |
$dbi->model('table1')->insert_at( |
|
1623 |
where => [1, 2], |
|
1624 |
param => {key3 => 3} |
|
1625 |
); |
|
1626 |
$result = $dbi->model('table1')->select; |
|
1627 |
$row = $result->fetch_hash_first; |
|
1628 |
is($row->{key1}, 1); |
|
1629 |
is($row->{key2}, 2); |
|
1630 |
is($row->{key3}, 3); |
|
add experimental DBIx::Custo...
|
1631 | |
- added experimental DBIx::C...
|
1632 |
test 'model update_at'; |
add experimental DBIx::Custo...
|
1633 |
$dbi = MyDBI6->connect($NEW_ARGS->{0}); |
1634 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1635 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1636 |
$dbi->model('table1')->update_at( |
|
1637 |
where => [1, 2], |
|
1638 |
param => {key3 => 4} |
|
1639 |
); |
|
1640 |
$result = $dbi->model('table1')->select; |
|
1641 |
$row = $result->fetch_hash_first; |
|
1642 |
is($row->{key1}, 1); |
|
1643 |
is($row->{key2}, 2); |
|
1644 |
is($row->{key3}, 4); |
|
1645 | ||
- added experimental DBIx::C...
|
1646 |
test 'model select_at'; |
add experimental DBIx::Custo...
|
1647 |
$dbi = MyDBI6->connect($NEW_ARGS->{0}); |
1648 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1649 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1650 |
$result = $dbi->model('table1')->select_at(where => [1, 2]); |
|
1651 |
$row = $result->fetch_hash_first; |
|
1652 |
is($row->{key1}, 1); |
|
1653 |
is($row->{key2}, 2); |
|
1654 |
is($row->{key3}, 3); |
|
DBIx::Custom::Model select()...
|
1655 | |
1656 | ||
1657 |
test 'model select relation'; |
|
1658 |
{ |
|
1659 |
package MyDBI7; |
|
1660 |
|
|
1661 |
use base 'DBIx::Custom'; |
|
1662 |
|
|
1663 |
sub connect { |
|
1664 |
my $self = shift->SUPER::connect(@_); |
|
1665 |
|
|
1666 |
$self->include_model('MyModel6'); |
|
1667 |
|
|
add experimental DBIx::Custo...
|
1668 |
|
DBIx::Custom::Model select()...
|
1669 |
return $self; |
1670 |
} |
|
1671 |
} |
|
1672 |
$dbi = MyDBI7->connect($NEW_ARGS->{0}); |
|
1673 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1674 |
$dbi->execute($CREATE_TABLE->{2}); |
|
1675 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1676 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3}); |
|
1677 |
$result = $dbi->model('table1')->select(column => ['key3'], where => {'table1.key1' => 1}); |
|
1678 |
is($result->fetch_hash_first->{key3}, 3); |
|
1679 |
$result = $dbi->model('table1')->select_at(column => ['key3'], where => [1]); |
|
1680 |
is($result->fetch_hash_first->{key3}, 3); |
|
add experimental DBIx::Custo...
|
1681 |
$dbi->execute('create table table3 (key1);'); |
1682 |
$dbi->model('table3')->insert(param => {key1 => 'a'}); |
|
1683 |
is_deeply($dbi->model('table3')->select(where => {key1 => 'a'})->fetch_hash_first, |
|
1684 |
{key1 => 'A'}); |
|
add experimental DBIx::Custo...
|
1685 | |
1686 |
test 'column_clause'; |
|
1687 |
$dbi = MyDBI7->connect($NEW_ARGS->{0}); |
|
1688 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1689 |
$dbi->execute($CREATE_TABLE->{2}); |
|
1690 |
$dbi->setup_model; |
|
1691 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1692 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3}); |
|
1693 |
$model = $dbi->model('table1'); |
|
1694 |
$result = $model->select(column => $model->column_clause, where => {'table1.key1' => 1}); |
|
1695 |
is_deeply($result->fetch_hash_first, {key1 => 1, key2 => 2}); |
|
1696 |
$result = $model->select(column => $model->column_clause(remove => ['key1']), where => {'table1.key1' => 1}); |
|
1697 |
is_deeply($result->fetch_hash_first, {key2 => 2}); |
|
1698 |
$result = $model->select(column => $model->column_clause(add => ['key3']), where => {'table1.key1' => 1}); |
|
1699 |
is_deeply($result->fetch_hash_first, {key1 => 1, key2 => 2, key3 => 3}); |
|
1700 | ||
1701 |