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/; |
|
7 | ||
8 |
BEGIN { |
|
9 |
eval { require DBD::SQLite; 1 } |
|
10 |
or plan skip_all => 'DBD::SQLite required'; |
|
11 |
eval { DBD::SQLite->VERSION >= 1.25 } |
|
12 |
or plan skip_all => 'DBD::SQLite >= 1.25 required'; |
|
13 | ||
14 |
plan 'no_plan'; |
|
15 |
use_ok('DBIx::Custom'); |
|
16 |
} |
|
17 | ||
18 |
# Function for test name |
|
table object call dbi object...
|
19 |
sub test { print "# $_[0]\n" } |
removed register_format()
|
20 | |
21 |
# Constant varialbes for test |
|
22 |
my $CREATE_TABLE = { |
|
23 |
0 => 'create table table1 (key1 char(255), key2 char(255));', |
|
24 |
1 => 'create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));', |
|
added experimental iterate_a...
|
25 |
2 => 'create table table2 (key1 char(255), key3 char(255));', |
26 |
3 => 'create table table1 (key1 Date, key2 datetime);' |
|
removed register_format()
|
27 |
}; |
28 | ||
add tests
|
29 |
my $SELECT_SOURCES = { |
removed register_format()
|
30 |
0 => 'select * from table1;' |
31 |
}; |
|
32 | ||
33 |
my $DROP_TABLE = { |
|
34 |
0 => 'drop table table1' |
|
35 |
}; |
|
36 | ||
37 |
my $NEW_ARGS = { |
|
38 |
0 => {data_source => 'dbi:SQLite:dbname=:memory:'} |
|
39 |
}; |
|
40 | ||
41 |
# Variables |
|
42 |
my $dbi; |
|
43 |
my $sth; |
|
renamed build_query to creat...
|
44 |
my $source; |
45 |
my @sources; |
|
add tests
|
46 |
my $select_SOURCE; |
47 |
my $insert_SOURCE; |
|
48 |
my $update_SOURCE; |
|
removed register_format()
|
49 |
my $params; |
50 |
my $sql; |
|
51 |
my $result; |
|
52 |
my $row; |
|
53 |
my @rows; |
|
54 |
my $rows; |
|
55 |
my $query; |
|
56 |
my @queries; |
|
57 |
my $select_query; |
|
58 |
my $insert_query; |
|
59 |
my $update_query; |
|
60 |
my $ret_val; |
|
added experimental iterate_a...
|
61 |
my $infos; |
added experimental DBIx::Cus...
|
62 |
my $table; |
added experimental DBIx::Cus...
|
63 |
my $where; |
removed register_format()
|
64 | |
65 |
# Prepare table |
|
66 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
67 |
$dbi->execute($CREATE_TABLE->{0}); |
|
68 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
69 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
70 | ||
71 |
test 'DBIx::Custom::Result test'; |
|
renamed build_query to creat...
|
72 |
$source = "select key1, key2 from table1"; |
73 |
$query = $dbi->create_query($source); |
|
removed register_format()
|
74 |
$result = $dbi->execute($query); |
75 | ||
76 |
@rows = (); |
|
77 |
while (my $row = $result->fetch) { |
|
78 |
push @rows, [@$row]; |
|
79 |
} |
|
cleanup
|
80 |
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch"); |
removed register_format()
|
81 | |
82 |
$result = $dbi->execute($query); |
|
83 |
@rows = (); |
|
84 |
while (my $row = $result->fetch_hash) { |
|
85 |
push @rows, {%$row}; |
|
86 |
} |
|
cleanup
|
87 |
is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "fetch_hash"); |
removed register_format()
|
88 | |
89 |
$result = $dbi->execute($query); |
|
90 |
$rows = $result->fetch_all; |
|
cleanup
|
91 |
is_deeply($rows, [[1, 2], [3, 4]], "fetch_all"); |
removed register_format()
|
92 | |
93 |
$result = $dbi->execute($query); |
|
removed reconnect method
|
94 |
$rows = $result->fetch_hash_all; |
cleanup
|
95 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "fetch_hash_all"); |
removed register_format()
|
96 | |
97 |
test 'Insert query return value'; |
|
98 |
$dbi->execute($DROP_TABLE->{0}); |
|
99 |
$dbi->execute($CREATE_TABLE->{0}); |
|
renamed update tag to update...
|
100 |
$source = "insert into table1 {insert_param key1 key2}"; |
renamed build_query to creat...
|
101 |
$query = $dbi->create_query($source); |
removed register_format()
|
102 |
$ret_val = $dbi->execute($query, param => {key1 => 1, key2 => 2}); |
cleanup
|
103 |
ok($ret_val); |
removed register_format()
|
104 | |
105 | ||
106 |
test 'Direct query'; |
|
107 |
$dbi->execute($DROP_TABLE->{0}); |
|
108 |
$dbi->execute($CREATE_TABLE->{0}); |
|
add tests
|
109 |
$insert_SOURCE = "insert into table1 {insert_param key1 key2}"; |
110 |
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2}); |
|
111 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
removed register_format()
|
112 |
$rows = $result->fetch_hash_all; |
cleanup
|
113 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
removed register_format()
|
114 | |
115 |
test 'Filter basic'; |
|
116 |
$dbi->execute($DROP_TABLE->{0}); |
|
117 |
$dbi->execute($CREATE_TABLE->{0}); |
|
118 |
$dbi->register_filter(twice => sub { $_[0] * 2}, |
|
119 |
three_times => sub { $_[0] * 3}); |
|
120 | ||
add tests
|
121 |
$insert_SOURCE = "insert into table1 {insert_param key1 key2};"; |
122 |
$insert_query = $dbi->create_query($insert_SOURCE); |
|
removed register_format()
|
123 |
$insert_query->filter({key1 => 'twice'}); |
124 |
$dbi->execute($insert_query, param => {key1 => 1, key2 => 2}); |
|
add tests
|
125 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
126 |
$rows = $result->filter({key2 => 'three_times'})->fetch_hash_all; |
cleanup
|
127 |
is_deeply($rows, [{key1 => 2, key2 => 6}], "filter fetch_filter"); |
removed register_format()
|
128 |
$dbi->execute($DROP_TABLE->{0}); |
129 | ||
130 |
test 'Filter in'; |
|
131 |
$dbi->execute($CREATE_TABLE->{0}); |
|
add tests
|
132 |
$insert_SOURCE = "insert into table1 {insert_param key1 key2};"; |
133 |
$insert_query = $dbi->create_query($insert_SOURCE); |
|
removed register_format()
|
134 |
$dbi->execute($insert_query, param => {key1 => 2, key2 => 4}); |
add tests
|
135 |
$select_SOURCE = "select * from table1 where {in table1.key1 2} and {in table1.key2 2}"; |
136 |
$select_query = $dbi->create_query($select_SOURCE); |
|
removed register_format()
|
137 |
$select_query->filter({'table1.key1' => 'twice'}); |
138 |
$result = $dbi->execute($select_query, param => {'table1.key1' => [1,5], 'table1.key2' => [2,4]}); |
|
139 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
140 |
is_deeply($rows, [{key1 => 2, key2 => 4}], "filter"); |
removed register_format()
|
141 | |
142 |
test 'DBIx::Custom::SQLTemplate basic tag'; |
|
143 |
$dbi->execute($DROP_TABLE->{0}); |
|
144 |
$dbi->execute($CREATE_TABLE->{1}); |
|
145 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
146 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
147 | ||
renamed build_query to creat...
|
148 |
$source = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};"; |
149 |
$query = $dbi->create_query($source); |
|
removed register_format()
|
150 |
$result = $dbi->execute($query, param => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5}); |
151 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
152 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag1"); |
removed register_format()
|
153 | |
renamed build_query to creat...
|
154 |
$source = "select * from table1 where {<= key1} and {like key2};"; |
155 |
$query = $dbi->create_query($source); |
|
removed register_format()
|
156 |
$result = $dbi->execute($query, param => {key1 => 1, key2 => '%2%'}); |
157 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
158 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag2"); |
removed register_format()
|
159 | |
160 |
test 'DIB::Custom::SQLTemplate in tag'; |
|
161 |
$dbi->execute($DROP_TABLE->{0}); |
|
162 |
$dbi->execute($CREATE_TABLE->{1}); |
|
163 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
164 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
165 | ||
renamed build_query to creat...
|
166 |
$source = "select * from table1 where {in key1 2};"; |
167 |
$query = $dbi->create_query($source); |
|
removed register_format()
|
168 |
$result = $dbi->execute($query, param => {key1 => [9, 1]}); |
169 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
170 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic"); |
removed register_format()
|
171 | |
172 |
test 'DBIx::Custom::SQLTemplate insert tag'; |
|
173 |
$dbi->execute("delete from table1"); |
|
add tests
|
174 |
$insert_SOURCE = 'insert into table1 {insert_param key1 key2 key3 key4 key5}'; |
175 |
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
removed register_format()
|
176 | |
add tests
|
177 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
178 |
$rows = $result->fetch_hash_all; |
cleanup
|
179 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic"); |
removed register_format()
|
180 | |
181 |
test 'DBIx::Custom::SQLTemplate update tag'; |
|
182 |
$dbi->execute("delete from table1"); |
|
add tests
|
183 |
$insert_SOURCE = "insert into table1 {insert_param key1 key2 key3 key4 key5}"; |
184 |
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
185 |
$dbi->execute($insert_SOURCE, param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
removed register_format()
|
186 | |
add tests
|
187 |
$update_SOURCE = 'update table1 {update_param key1 key2 key3 key4} where {= key5}'; |
188 |
$dbi->execute($update_SOURCE, param => {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5}); |
|
removed register_format()
|
189 | |
add tests
|
190 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
191 |
$rows = $result->fetch_hash_all; |
192 |
is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5}, |
|
cleanup
|
193 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "basic"); |
removed register_format()
|
194 | |
195 |
test 'Error case'; |
|
196 |
eval {DBIx::Custom->connect(data_source => 'dbi:SQLit')}; |
|
cleanup
|
197 |
ok($@, "connect error"); |
removed register_format()
|
198 | |
199 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
renamed build_query to creat...
|
200 |
eval{$dbi->create_query("{p }")}; |
cleanup
|
201 |
ok($@, "create_query invalid SQL template"); |
removed register_format()
|
202 | |
203 |
test 'insert'; |
|
204 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
205 |
$dbi->execute($CREATE_TABLE->{0}); |
|
206 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
207 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
add tests
|
208 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
209 |
$rows = $result->fetch_hash_all; |
cleanup
|
210 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic"); |
removed register_format()
|
211 | |
212 |
$dbi->execute('delete from table1'); |
|
213 |
$dbi->register_filter( |
|
214 |
twice => sub { $_[0] * 2 }, |
|
215 |
three_times => sub { $_[0] * 3 } |
|
216 |
); |
|
renamed default_query_filter...
|
217 |
$dbi->default_bind_filter('twice'); |
removed register_format()
|
218 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => 'three_times'}); |
add tests
|
219 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
220 |
$rows = $result->fetch_hash_all; |
cleanup
|
221 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter"); |
renamed default_query_filter...
|
222 |
$dbi->default_bind_filter(undef); |
removed register_format()
|
223 | |
224 |
$dbi->execute($DROP_TABLE->{0}); |
|
225 |
$dbi->execute($CREATE_TABLE->{0}); |
|
226 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, append => ' '); |
|
227 |
$rows = $dbi->select(table => 'table1')->fetch_hash_all; |
|
228 |
is_deeply($rows, [{key1 => 1, key2 => 2}], 'insert append'); |
|
229 | ||
changed argument of tag proc...
|
230 |
eval{$dbi->insert(table => 'table1', noexist => 1)}; |
cleanup
|
231 |
like($@, qr/noexist/, "invalid argument"); |
changed argument of tag proc...
|
232 | |
select() where can't receive...
|
233 |
eval{$dbi->insert(table => 'table', param => {';' => 1})}; |
234 |
like($@, qr/safety/); |
|
changed argument of tag proc...
|
235 | |
removed register_format()
|
236 |
test 'update'; |
237 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
238 |
$dbi->execute($CREATE_TABLE->{1}); |
|
239 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
240 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
241 |
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1}); |
|
add tests
|
242 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
243 |
$rows = $result->fetch_hash_all; |
244 |
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5}, |
|
245 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
cleanup
|
246 |
"basic"); |
removed register_format()
|
247 |
|
248 |
$dbi->execute("delete from table1"); |
|
249 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
250 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
251 |
$dbi->update(table => 'table1', param => {key2 => 12}, where => {key2 => 2, key3 => 3}); |
|
add tests
|
252 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
253 |
$rows = $result->fetch_hash_all; |
254 |
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5}, |
|
255 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
cleanup
|
256 |
"update key same as search key"); |
removed register_format()
|
257 | |
add tests
|
258 |
$dbi->update(table => 'table1', param => {key2 => [12]}, where => {key2 => 2, key3 => 3}); |
259 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
260 |
$rows = $result->fetch_hash_all; |
|
261 |
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5}, |
|
262 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
cleanup
|
263 |
"update key same as search key : param is array ref"); |
add tests
|
264 | |
removed register_format()
|
265 |
$dbi->execute("delete from table1"); |
266 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
267 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
268 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
269 |
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1}, |
|
many changed
|
270 |
filter => {key2 => sub { $_[0] * 2 }}); |
add tests
|
271 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
272 |
$rows = $result->fetch_hash_all; |
273 |
is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5}, |
|
274 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
cleanup
|
275 |
"filter"); |
removed register_format()
|
276 | |
277 |
$result = $dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1}, append => ' '); |
|
278 | ||
changed argument of tag proc...
|
279 |
eval{$dbi->update(table => 'table1', noexist => 1)}; |
cleanup
|
280 |
like($@, qr/noexist/, "invalid argument"); |
changed argument of tag proc...
|
281 | |
282 |
eval{$dbi->update(table => 'table1')}; |
|
cleanup
|
283 |
like($@, qr/where/, "not contain where"); |
changed argument of tag proc...
|
284 | |
improved delete() and update...
|
285 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
286 |
$dbi->execute($CREATE_TABLE->{0}); |
|
287 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
288 |
$where = $dbi->where; |
|
289 |
$where->clause(['and', '{= key1}', '{= key2}']); |
|
290 |
$where->param({key1 => 1, key2 => 2}); |
|
291 |
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where); |
|
292 |
$result = $dbi->select(table => 'table1'); |
|
293 |
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'delete() where'); |
|
294 | ||
295 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
296 |
$dbi->execute($CREATE_TABLE->{0}); |
|
297 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
298 |
$where = $dbi->where; |
|
299 |
$where->clause(['and', '{= key2}']); |
|
300 |
$where->param({key2 => 2}); |
|
301 |
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where); |
|
302 |
$result = $dbi->select(table => 'table1'); |
|
303 |
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'delete() where'); |
|
changed argument of tag proc...
|
304 | |
select() where can't receive...
|
305 |
eval{$dbi->update(table => 'table1', param => {';' => 1})}; |
306 |
like($@, qr/safety/); |
|
307 | ||
308 |
eval{$dbi->update(table => 'table1', param => {'key1' => 1}, where => {';' => 1})}; |
|
309 |
like($@, qr/safety/); |
|
310 | ||
removed register_format()
|
311 |
test 'update_all'; |
312 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
313 |
$dbi->execute($CREATE_TABLE->{1}); |
|
314 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
315 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
316 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
317 |
$dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'}); |
|
add tests
|
318 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
319 |
$rows = $result->fetch_hash_all; |
320 |
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5}, |
|
321 |
{key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}], |
|
cleanup
|
322 |
"filter"); |
removed register_format()
|
323 | |
324 | ||
325 |
test 'delete'; |
|
326 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
327 |
$dbi->execute($CREATE_TABLE->{0}); |
|
328 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
329 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
330 |
$dbi->delete(table => 'table1', where => {key1 => 1}); |
|
add tests
|
331 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
332 |
$rows = $result->fetch_hash_all; |
cleanup
|
333 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "basic"); |
removed register_format()
|
334 | |
335 |
$dbi->execute("delete from table1;"); |
|
336 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
337 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
338 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
339 |
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'}); |
|
add tests
|
340 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
341 |
$rows = $result->fetch_hash_all; |
cleanup
|
342 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter"); |
removed register_format()
|
343 | |
344 |
$dbi->delete(table => 'table1', where => {key1 => 1}, append => ' '); |
|
345 | ||
346 |
$dbi->delete_all(table => 'table1'); |
|
347 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
348 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
349 |
$dbi->delete(table => 'table1', where => {key1 => 1, key2 => 2}); |
|
350 |
$rows = $dbi->select(table => 'table1')->fetch_hash_all; |
|
cleanup
|
351 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "delete multi key"); |
removed register_format()
|
352 | |
changed argument of tag proc...
|
353 |
eval{$dbi->delete(table => 'table1', noexist => 1)}; |
cleanup
|
354 |
like($@, qr/noexist/, "invalid argument"); |
changed argument of tag proc...
|
355 | |
improved delete() and update...
|
356 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
357 |
$dbi->execute($CREATE_TABLE->{0}); |
|
358 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
359 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
360 |
$where = $dbi->where; |
|
361 |
$where->clause(['and', '{= key1}', '{= key2}']); |
|
362 |
$where->param({ke1 => 1, key2 => 2}); |
|
363 |
$dbi->delete(table => 'table1', where => $where); |
|
364 |
$result = $dbi->select(table => 'table1'); |
|
365 |
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 4}], 'delete() where'); |
|
changed argument of tag proc...
|
366 | |
removed register_format()
|
367 |
test 'delete error'; |
368 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
369 |
$dbi->execute($CREATE_TABLE->{0}); |
|
370 |
eval{$dbi->delete(table => 'table1')}; |
|
make delete() using where ob...
|
371 |
like($@, qr/"where" must be specified/, |
cleanup
|
372 |
"where key-value pairs not specified"); |
removed register_format()
|
373 | |
select() where can't receive...
|
374 |
eval{$dbi->delete(table => 'table1', where => {';' => 1})}; |
375 |
like($@, qr/safety/); |
|
376 | ||
removed register_format()
|
377 |
test 'delete_all'; |
378 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
379 |
$dbi->execute($CREATE_TABLE->{0}); |
|
380 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
381 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
382 |
$dbi->delete_all(table => 'table1'); |
|
add tests
|
383 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
removed register_format()
|
384 |
$rows = $result->fetch_hash_all; |
cleanup
|
385 |
is_deeply($rows, [], "basic"); |
removed register_format()
|
386 | |
387 | ||
388 |
test 'select'; |
|
389 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
390 |
$dbi->execute($CREATE_TABLE->{0}); |
|
391 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
392 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
393 |
$rows = $dbi->select(table => 'table1')->fetch_hash_all; |
|
394 |
is_deeply($rows, [{key1 => 1, key2 => 2}, |
|
cleanup
|
395 |
{key1 => 3, key2 => 4}], "table"); |
removed register_format()
|
396 | |
update document
|
397 |
$rows = $dbi->select(table => 'table1', column => ['key1'])->fetch_hash_all; |
cleanup
|
398 |
is_deeply($rows, [{key1 => 1}, {key1 => 3}], "table and columns and where key"); |
removed register_format()
|
399 | |
400 |
$rows = $dbi->select(table => 'table1', where => {key1 => 1})->fetch_hash_all; |
|
cleanup
|
401 |
is_deeply($rows, [{key1 => 1, key2 => 2}], "table and columns and where key"); |
removed register_format()
|
402 | |
update document
|
403 |
$rows = $dbi->select(table => 'table1', column => ['key1'], where => {key1 => 3})->fetch_hash_all; |
cleanup
|
404 |
is_deeply($rows, [{key1 => 3}], "table and columns and where key"); |
removed register_format()
|
405 | |
406 |
$rows = $dbi->select(table => 'table1', append => "order by key1 desc limit 1")->fetch_hash_all; |
|
cleanup
|
407 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "append statement"); |
removed register_format()
|
408 | |
409 |
$dbi->register_filter(decrement => sub { $_[0] - 1 }); |
|
update document
|
410 |
$rows = $dbi->select(table => 'table1', where => {key1 => 2}, filter => {key1 => 'decrement'}) |
removed register_format()
|
411 |
->fetch_hash_all; |
cleanup
|
412 |
is_deeply($rows, [{key1 => 1, key2 => 2}], "filter"); |
removed register_format()
|
413 | |
414 |
$dbi->execute($CREATE_TABLE->{2}); |
|
415 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5}); |
|
416 |
$rows = $dbi->select( |
|
417 |
table => [qw/table1 table2/], |
|
update document
|
418 |
column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'], |
removed register_format()
|
419 |
where => {'table1.key2' => 2}, |
added commit method
|
420 |
relation => {'table1.key1' => 'table2.key1'} |
removed register_format()
|
421 |
)->fetch_hash_all; |
cleanup
|
422 |
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "relation : exists where"); |
added commit method
|
423 | |
424 |
$rows = $dbi->select( |
|
425 |
table => [qw/table1 table2/], |
|
426 |
column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'], |
|
427 |
relation => {'table1.key1' => 'table2.key1'} |
|
428 |
)->fetch_hash_all; |
|
cleanup
|
429 |
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "relation : no exists where"); |
removed register_format()
|
430 | |
changed argument of tag proc...
|
431 |
eval{$dbi->select(table => 'table1', noexist => 1)}; |
cleanup
|
432 |
like($@, qr/noexist/, "invalid argument"); |
changed argument of tag proc...
|
433 | |
434 | ||
removed register_format()
|
435 |
test 'fetch filter'; |
436 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
437 |
$dbi->register_filter( |
|
438 |
twice => sub { $_[0] * 2 }, |
|
439 |
three_times => sub { $_[0] * 3 } |
|
440 |
); |
|
441 |
$dbi->default_fetch_filter('twice'); |
|
442 |
$dbi->execute($CREATE_TABLE->{0}); |
|
443 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
444 |
$result = $dbi->select(table => 'table1'); |
|
445 |
$result->filter({key1 => 'three_times'}); |
|
removed reconnect method
|
446 |
$row = $result->fetch_hash_first; |
cleanup
|
447 |
is_deeply($row, {key1 => 3, key2 => 4}, "default_fetch_filter and filter"); |
removed register_format()
|
448 | |
449 |
test 'filters'; |
|
450 |
$dbi = DBIx::Custom->new; |
|
451 | ||
update document
|
452 |
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')), |
cleanup
|
453 |
'あ', "decode_utf8"); |
removed register_format()
|
454 | |
455 |
is($dbi->filters->{encode_utf8}->('あ'), |
|
cleanup
|
456 |
encode_utf8('あ'), "encode_utf8"); |
removed register_format()
|
457 | |
added commit method
|
458 |
test 'transaction'; |
459 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
460 |
$dbi->execute($CREATE_TABLE->{0}); |
|
removed DBIx::Custom commit ...
|
461 |
$dbi->dbh->begin_work; |
added commit method
|
462 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
463 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3}); |
|
removed DBIx::Custom commit ...
|
464 |
$dbi->dbh->commit; |
added commit method
|
465 |
$result = $dbi->select(table => 'table1'); |
466 |
is_deeply(scalar $result->fetch_hash_all, [{key1 => 1, key2 => 2}, {key1 => 2, key2 => 3}], |
|
cleanup
|
467 |
"commit"); |
added commit method
|
468 | |
469 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
470 |
$dbi->execute($CREATE_TABLE->{0}); |
|
removed DBIx::Custom commit ...
|
471 |
$dbi->dbh->begin_work(0); |
added commit method
|
472 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
removed DBIx::Custom commit ...
|
473 |
$dbi->dbh->rollback; |
added commit method
|
474 | |
475 |
$result = $dbi->select(table => 'table1'); |
|
cleanup
|
476 |
ok(! $result->fetch_first, "rollback"); |
add cache attribute
|
477 | |
478 |
test 'cache'; |
|
479 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
480 |
$dbi->execute($CREATE_TABLE->{0}); |
|
renamed build_query to creat...
|
481 |
$source = 'select * from table1 where {= key1} and {= key2};'; |
482 |
$dbi->create_query($source); |
|
483 |
is_deeply($dbi->{_cached}->{$source}, |
|
cleanup
|
484 |
{sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2']}, "cache"); |
add cache attribute
|
485 | |
486 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
487 |
$dbi->execute($CREATE_TABLE->{0}); |
|
488 |
$dbi->{_cached} = {}; |
|
489 |
$dbi->cache(0); |
|
490 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
491 |
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache'); |
|
492 | ||
add tests
|
493 |
test 'execute'; |
494 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
495 |
$dbi->execute($CREATE_TABLE->{0}); |
|
removed experimental registe...
|
496 |
{ |
497 |
local $Carp::Verbose = 0; |
|
498 |
eval{$dbi->execute('select * frm table1')}; |
|
cleanup
|
499 |
like($@, qr/\Qselect * frm table1;/, "fail prepare"); |
500 |
like($@, qr/\.t /, "fail : not verbose"); |
|
removed experimental registe...
|
501 |
} |
502 |
{ |
|
503 |
local $Carp::Verbose = 1; |
|
504 |
eval{$dbi->execute('select * frm table1')}; |
|
cleanup
|
505 |
like($@, qr/Custom.*\.t /s, "fail : verbose"); |
removed experimental registe...
|
506 |
} |
add tests
|
507 | |
508 |
eval{$dbi->execute('select * from table1', no_exists => 1)}; |
|
cleanup
|
509 |
like($@, qr/\Q"no_exists" is invalid argument/, "invald SQL"); |
add tests
|
510 | |
511 |
$query = $dbi->create_query('select * from table1 where {= key1}'); |
|
512 |
$dbi->dbh->disconnect; |
|
513 |
eval{$dbi->execute($query, param => {key1 => {a => 1}})}; |
|
cleanup
|
514 |
ok($@, "execute fail"); |
add tests
|
515 | |
removed experimental registe...
|
516 |
{ |
517 |
local $Carp::Verbose = 0; |
|
518 |
eval{$dbi->create_query('select * from table1 where {0 key1}')}; |
|
cleanup
|
519 |
like($@, qr/\Q.t /, "caller spec : not vebose"); |
removed experimental registe...
|
520 |
} |
521 |
{ |
|
522 |
local $Carp::Verbose = 1; |
|
523 |
eval{$dbi->create_query('select * from table1 where {0 key1}')}; |
|
cleanup
|
524 |
like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose"); |
removed experimental registe...
|
525 |
} |
cleanup
|
526 | |
527 | ||
528 |
test 'transaction'; |
|
529 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
530 |
$dbi->execute($CREATE_TABLE->{0}); |
|
531 | ||
532 |
$dbi->begin_work; |
|
533 | ||
534 |
eval { |
|
535 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
536 |
die "Error"; |
|
537 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
538 |
}; |
|
539 | ||
540 |
$dbi->rollback if $@; |
|
541 | ||
542 |
$result = $dbi->select(table => 'table1'); |
|
543 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
544 |
is_deeply($rows, [], "rollback"); |
cleanup
|
545 | |
546 |
$dbi->begin_work; |
|
547 | ||
548 |
eval { |
|
549 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
550 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
551 |
}; |
|
552 | ||
553 |
$dbi->commit unless $@; |
|
554 | ||
555 |
$result = $dbi->select(table => 'table1'); |
|
556 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
557 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "commit"); |
cleanup
|
558 | |
559 |
$dbi->dbh->{AutoCommit} = 0; |
|
560 |
eval{ $dbi->begin_work }; |
|
cleanup
|
561 |
ok($@, "exception"); |
cleanup
|
562 |
$dbi->dbh->{AutoCommit} = 1; |
563 | ||
added helper method
|
564 | |
renamed helper to method.
|
565 |
test 'method'; |
added helper method
|
566 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
renamed helper to method.
|
567 |
$dbi->method( |
added helper method
|
568 |
one => sub { 1 } |
569 |
); |
|
renamed helper to method.
|
570 |
$dbi->method( |
added helper method
|
571 |
two => sub { 2 } |
572 |
); |
|
renamed helper to method.
|
573 |
$dbi->method({ |
added helper method
|
574 |
twice => sub { |
575 |
my $self = shift; |
|
576 |
return $_[0] * 2; |
|
577 |
} |
|
578 |
}); |
|
579 | ||
cleanup
|
580 |
is($dbi->one, 1, "first"); |
581 |
is($dbi->two, 2, "second"); |
|
582 |
is($dbi->twice(5), 10 , "second"); |
|
added helper method
|
583 | |
584 |
eval {$dbi->XXXXXX}; |
|
autoload DBI method
|
585 |
ok($@, "not exists"); |
added helper method
|
586 | |
renamed auto_filter to apply...
|
587 |
test 'out filter'; |
added auto_filter method
|
588 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
589 |
$dbi->execute($CREATE_TABLE->{0}); |
|
590 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
591 |
$dbi->register_filter(three_times => sub { $_[0] * 3}); |
|
renamed auto_filter to apply...
|
592 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
593 |
'table1', 'key1' => {out => 'twice', in => 'three_times'}, |
594 |
'key2' => {out => 'three_times', in => 'twice'}); |
|
added auto_filter method
|
595 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
596 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
597 |
$row = $result->fetch_hash_first; |
|
cleanup
|
598 |
is_deeply($row, {key1 => 2, key2 => 6}, "insert"); |
renamed auto_filter to apply...
|
599 |
$result = $dbi->select(table => 'table1'); |
600 |
$row = $result->fetch_hash_first; |
|
cleanup
|
601 |
is_deeply($row, {key1 => 6, key2 => 12}, "insert"); |
added auto_filter method
|
602 | |
603 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
604 |
$dbi->execute($CREATE_TABLE->{0}); |
|
605 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
renamed auto_filter to apply...
|
606 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
607 |
'table1', 'key1' => {out => 'twice', in => 'twice'} |
added auto_filter method
|
608 |
); |
renamed auto_filter to apply...
|
609 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => undef}); |
added auto_filter method
|
610 |
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2}); |
611 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
612 |
$row = $result->fetch_hash_first; |
|
cleanup
|
613 |
is_deeply($row, {key1 => 4, key2 => 2}, "update"); |
added auto_filter method
|
614 | |
615 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
616 |
$dbi->execute($CREATE_TABLE->{0}); |
|
617 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
renamed auto_filter to apply...
|
618 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
619 |
'table1', 'key1' => {out => 'twice', in => 'twice'} |
added auto_filter method
|
620 |
); |
renamed auto_filter to apply...
|
621 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1=> undef}); |
added auto_filter method
|
622 |
$dbi->delete(table => 'table1', where => {key1 => 1}); |
623 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
624 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
625 |
is_deeply($rows, [], "delete"); |
added auto_filter method
|
626 | |
627 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
628 |
$dbi->execute($CREATE_TABLE->{0}); |
|
629 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
renamed auto_filter to apply...
|
630 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
631 |
'table1', 'key1' => {out => 'twice', in => 'twice'} |
added auto_filter method
|
632 |
); |
renamed auto_filter to apply...
|
633 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef}); |
added auto_filter method
|
634 |
$result = $dbi->select(table => 'table1', where => {key1 => 1}); |
635 |
$result->filter({'key2' => 'twice'}); |
|
636 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
637 |
is_deeply($rows, [{key1 => 4, key2 => 4}], "select"); |
added auto_filter method
|
638 | |
639 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
640 |
$dbi->execute($CREATE_TABLE->{0}); |
|
641 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
renamed auto_filter to apply...
|
642 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
643 |
'table1', 'key1' => {out => 'twice', in => 'twice'} |
added auto_filter method
|
644 |
); |
renamed auto_filter to apply...
|
645 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef}); |
added auto_filter method
|
646 |
$result = $dbi->execute("select * from table1 where {= key1} and {= key2};", |
647 |
param => {key1 => 1, key2 => 2}, |
|
renamed auto_filter to apply...
|
648 |
table => ['table1']); |
added auto_filter method
|
649 |
$rows = $result->fetch_hash_all; |
cleanup
|
650 |
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute"); |
added auto_filter method
|
651 | |
652 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
653 |
$dbi->execute($CREATE_TABLE->{0}); |
|
654 |
$dbi->execute($CREATE_TABLE->{2}); |
|
655 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
656 |
$dbi->register_filter(three_times => sub { $_[0] * 3 }); |
|
renamed auto_filter to apply...
|
657 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
658 |
'table1', 'key2' => {out => 'twice', in => 'twice'} |
added auto_filter method
|
659 |
); |
renamed auto_filter to apply...
|
660 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
661 |
'table2', 'key3' => {out => 'three_times', in => 'three_times'} |
added auto_filter method
|
662 |
); |
renamed auto_filter to apply...
|
663 |
$dbi->insert(table => 'table1', param => {key1 => 5, key2 => 2}, filter => {key2 => undef}); |
664 |
$dbi->insert(table => 'table2', param => {key1 => 5, key3 => 6}, filter => {key3 => undef}); |
|
added auto_filter method
|
665 |
$result = $dbi->select( |
666 |
table => ['table1', 'table2'], |
|
667 |
column => ['key2', 'key3'], |
|
668 |
where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'}); |
|
669 | ||
670 |
$result->filter({'key2' => 'twice'}); |
|
671 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
672 |
is_deeply($rows, [{key2 => 4, key3 => 18}], "select : join"); |
added auto_filter method
|
673 | |
674 |
$result = $dbi->select( |
|
675 |
table => ['table1', 'table2'], |
|
676 |
column => ['key2', 'key3'], |
|
677 |
where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'}); |
|
678 | ||
679 |
$result->filter({'key2' => 'twice'}); |
|
680 |
$rows = $result->fetch_hash_all; |
|
cleanup
|
681 |
is_deeply($rows, [{key2 => 4, key3 => 18}], "select : join : omit"); |
added auto_filter method
|
682 | |
pod fix
|
683 |
test 'each_column'; |
added experimental iterate_a...
|
684 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
685 |
$dbi->execute($CREATE_TABLE->{2}); |
|
686 |
$dbi->execute($CREATE_TABLE->{3}); |
|
687 | ||
688 |
$infos = []; |
|
pod fix
|
689 |
$dbi->each_column(sub { |
removed experimental txn_sco...
|
690 |
my ($self, $table, $column, $cinfo) = @_; |
added experimental iterate_a...
|
691 |
|
692 |
if ($table =~ /^table/) { |
|
693 |
my $info = [$table, $column, $cinfo->{COLUMN_NAME}]; |
|
694 |
push @$infos, $info; |
|
695 |
} |
|
696 |
}); |
|
697 |
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos]; |
|
698 |
is_deeply($infos, |
|
699 |
[ |
|
700 |
['table1', 'key1', 'key1'], |
|
701 |
['table1', 'key2', 'key2'], |
|
702 |
['table2', 'key1', 'key1'], |
|
703 |
['table2', 'key3', 'key3'] |
|
704 |
] |
|
cleanup
|
705 |
|
added experimental iterate_a...
|
706 |
); |
added auto_filter method
|
707 | |
remove DBIx::Custom::Model
|
708 |
test 'table'; |
709 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
710 |
$dbi->execute($CREATE_TABLE->{0}); |
|
711 |
$table = $dbi->table('table1'); |
|
simplified DBIx::Custom::Mod...
|
712 |
$table->insert(param => {key1 => 1, key2 => 2}); |
713 |
$table->insert(param => {key1 => 3, key2 => 4}); |
|
added experimental DBIx::Cus...
|
714 |
$rows = $table->select->fetch_hash_all; |
715 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], |
|
cleanup
|
716 |
"select"); |
simplified DBIx::Custom::Mod...
|
717 |
$rows = $table->select(where => {key2 => 2}, append => 'order by key1', |
718 |
column => ['key1', 'key2'])->fetch_hash_all; |
|
added experimental DBIx::Cus...
|
719 |
is_deeply($rows, [{key1 => 1, key2 => 2}], |
cleanup
|
720 |
"insert insert select"); |
simplified DBIx::Custom::Mod...
|
721 |
$table->update(param => {key1 => 3}, where => {key2 => 2}); |
722 |
$table->update(param => {key1 => 5}, where => {key2 => 4}); |
|
723 |
$rows = $table->select(where => {key2 => 2})->fetch_hash_all; |
|
added experimental DBIx::Cus...
|
724 |
is_deeply($rows, [{key1 => 3, key2 => 2}], |
cleanup
|
725 |
"update"); |
simplified DBIx::Custom::Mod...
|
726 |
$table->delete(where => {key2 => 2}); |
added experimental DBIx::Cus...
|
727 |
$rows = $table->select->fetch_hash_all; |
cleanup
|
728 |
is_deeply($rows, [{key1 => 5, key2 => 4}], "delete"); |
simplified DBIx::Custom::Mod...
|
729 |
$table->update_all(param => {key1 => 3}); |
730 |
$rows = $table->select->fetch_hash_all; |
|
cleanup
|
731 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "update_all"); |
added experimental DBIx::Cus...
|
732 |
$table->delete_all; |
733 |
$rows = $table->select->fetch_hash_all; |
|
cleanup
|
734 |
is_deeply($rows, [], "delete_all"); |
added insert, update, update...
|
735 | |
remove DBIx::Custom::Model
|
736 |
$dbi->dbh->do($CREATE_TABLE->{2}); |
renamed experimental DBIx::C...
|
737 |
$dbi->table('table2')->method( |
738 |
ppp => sub { |
|
739 |
my $self = shift; |
|
remove DBIx::Custom::Model
|
740 |
|
renamed experimental DBIx::C...
|
741 |
return $self->name; |
742 |
} |
|
743 |
); |
|
744 |
is($dbi->table('table2')->ppp, 'table2', "method"); |
|
remove DBIx::Custom::Model
|
745 | |
renamed experimental DBIx::C...
|
746 |
$dbi->table('table2')->method({ |
747 |
qqq => sub { |
|
748 |
my $self = shift; |
|
many changed
|
749 |
|
renamed experimental DBIx::C...
|
750 |
return $self->name; |
751 |
} |
|
752 |
}); |
|
753 |
is($dbi->table('table2')->qqq, 'table2', "method"); |
|
many changed
|
754 | |
755 | ||
add examples
|
756 |
test 'limit'; |
757 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
758 |
$dbi->execute($CREATE_TABLE->{0}); |
|
759 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
760 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4}); |
|
761 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6}); |
|
renamed DBIx::Custom::TagPro...
|
762 |
$dbi->register_tag( |
add examples
|
763 |
limit => sub { |
764 |
my ($count, $offset) = @_; |
|
765 |
|
|
766 |
my $s = ''; |
|
767 |
$s .= "limit $count"; |
|
768 |
$s .= " offset $offset" if defined $offset; |
|
769 |
|
|
770 |
return [$s, []]; |
|
771 |
} |
|
772 |
); |
|
773 |
$rows = $dbi->select( |
|
774 |
table => 'table1', |
|
775 |
where => {key1 => 1}, |
|
776 |
append => "order by key2 {limit 1 0}" |
|
777 |
)->fetch_hash_all; |
|
cleanup
|
778 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
add examples
|
779 |
$rows = $dbi->select( |
780 |
table => 'table1', |
|
781 |
where => {key1 => 1}, |
|
782 |
append => "order by key2 {limit 2 1}" |
|
783 |
)->fetch_hash_all; |
|
cleanup
|
784 |
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]); |
add examples
|
785 |
$rows = $dbi->select( |
786 |
table => 'table1', |
|
787 |
where => {key1 => 1}, |
|
788 |
append => "order by key2 {limit 1}" |
|
789 |
)->fetch_hash_all; |
|
cleanup
|
790 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
added insert, update, update...
|
791 | |
remove DBIx::Custom::Model
|
792 |
test 'connect super'; |
793 |
{ |
|
794 |
package MyDBI; |
|
795 |
|
|
796 |
use base 'DBIx::Custom'; |
|
797 |
sub connect { |
|
798 |
my $self = shift->SUPER::connect(@_); |
|
799 |
|
|
800 |
return $self; |
|
801 |
} |
|
802 |
|
|
803 |
sub new { |
|
cleanup
|
804 |
my $self = shift->SUPER::new(@_); |
remove DBIx::Custom::Model
|
805 |
|
806 |
return $self; |
|
807 |
} |
|
808 |
} |
|
809 | ||
810 |
$dbi = MyDBI->connect($NEW_ARGS->{0}); |
|
811 |
$dbi->execute($CREATE_TABLE->{0}); |
|
812 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
cleanup
|
813 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1); |
remove DBIx::Custom::Model
|
814 | |
815 |
$dbi = MyDBI->new($NEW_ARGS->{0}); |
|
cleanup
|
816 |
$dbi->connect; |
remove DBIx::Custom::Model
|
817 |
$dbi->execute($CREATE_TABLE->{0}); |
818 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
cleanup
|
819 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1); |
added experimental DBIx::Cus...
|
820 | |
cleanup
|
821 |
{ |
822 |
package MyDBI2; |
|
823 |
|
|
824 |
use base 'DBIx::Custom'; |
|
825 |
sub connect { |
|
826 |
my $self = shift->SUPER::new(@_); |
|
827 |
$self->connect; |
|
828 |
|
|
829 |
return $self; |
|
830 |
} |
|
831 |
} |
|
832 | ||
833 |
$dbi = MyDBI->connect($NEW_ARGS->{0}); |
|
834 |
$dbi->execute($CREATE_TABLE->{0}); |
|
835 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
836 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1); |
|
added experimental DBIx::Cus...
|
837 | |
838 |
test 'end_filter'; |
|
839 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
840 |
$dbi->execute($CREATE_TABLE->{0}); |
|
841 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
842 |
$result = $dbi->select(table => 'table1'); |
|
843 |
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 }); |
|
844 |
$result->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 }); |
|
845 |
$row = $result->fetch_first; |
|
846 |
is_deeply($row, [6, 40]); |
|
847 | ||
many changed
|
848 |
$dbi->register_filter(five_times => sub { $_[0] * 5 }); |
added experimental DBIx::Cus...
|
849 |
$result = $dbi->select(table => 'table1'); |
850 |
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 }); |
|
many changed
|
851 |
$result->end_filter({key1 => sub { $_[0] * 3 }, key2 => 'five_times' }); |
added experimental DBIx::Cus...
|
852 |
$row = $result->fetch_hash_first; |
853 |
is_deeply($row, {key1 => 6, key2 => 40}); |
|
fix select method empty wher...
|
854 | |
855 | ||
856 |
test 'empty where select'; |
|
857 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
858 |
$dbi->execute($CREATE_TABLE->{0}); |
|
859 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
860 |
$result = $dbi->select(table => 'table1', where => {}); |
|
861 |
$row = $result->fetch_hash_first; |
|
862 |
is_deeply($row, {key1 => 1, key2 => 2}); |
|
863 | ||
added experimental sugar met...
|
864 |
test 'select query option'; |
865 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
866 |
$dbi->execute($CREATE_TABLE->{0}); |
|
867 |
$query = $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, query => 1); |
|
868 |
is(ref $query, 'DBIx::Custom::Query'); |
|
869 |
$query = $dbi->update(table => 'table1', where => {key1 => 1}, param => {key2 => 2}, query => 1); |
|
870 |
is(ref $query, 'DBIx::Custom::Query'); |
|
871 |
$query = $dbi->delete(table => 'table1', where => {key1 => 1}, query => 1); |
|
872 |
is(ref $query, 'DBIx::Custom::Query'); |
|
873 |
$query = $dbi->select(table => 'table1', where => {key1 => 1, key2 => 2}, query => 1); |
|
874 |
is(ref $query, 'DBIx::Custom::Query'); |
|
875 | ||
added experimental DBIx::Cus...
|
876 |
test 'DBIx::Custom::Where'; |
experimental extended select...
|
877 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
878 |
$dbi->execute($CREATE_TABLE->{0}); |
|
879 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
880 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
renamed DBIx::Custom::TagPro...
|
881 |
$where = $dbi->where->clause(['and', '{= key1}', '{= key2}']); |
882 |
is("$where", "where ( {= key1} and {= key2} )", 'no param'); |
|
883 | ||
added experimental DBIx::Cus...
|
884 |
$where = $dbi->where |
added test
|
885 |
->clause(['and', '{= key1}', '{= key2}']) |
added experimental DBIx::Cus...
|
886 |
->param({key1 => 1}); |
added test
|
887 | |
experimental extended select...
|
888 |
$result = $dbi->select( |
889 |
table => 'table1', |
|
added experimental DBIx::Cus...
|
890 |
where => $where |
experimental extended select...
|
891 |
); |
892 |
$row = $result->fetch_hash_all; |
|
893 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
|
894 | ||
added experimental DBIx::Cus...
|
895 |
$where = $dbi->where |
added test
|
896 |
->clause(['and', '{= key1}', '{= key2}']) |
added experimental DBIx::Cus...
|
897 |
->param({key1 => 1, key2 => 2}); |
experimental extended select...
|
898 |
$result = $dbi->select( |
899 |
table => 'table1', |
|
added experimental DBIx::Cus...
|
900 |
where => $where |
experimental extended select...
|
901 |
); |
902 |
$row = $result->fetch_hash_all; |
|
903 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
|
904 | ||
added experimental DBIx::Cus...
|
905 |
$where = $dbi->where |
added test
|
906 |
->clause(['and', '{= key1}', '{= key2}']) |
added experimental DBIx::Cus...
|
907 |
->param({}); |
experimental extended select...
|
908 |
$result = $dbi->select( |
909 |
table => 'table1', |
|
added experimental DBIx::Cus...
|
910 |
where => $where, |
experimental extended select...
|
911 |
); |
912 |
$row = $result->fetch_hash_all; |
|
913 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]); |
|
914 | ||
added experimental DBIx::Cus...
|
915 |
$where = $dbi->where |
added test
|
916 |
->clause(['and', ['or', '{> key1}', '{< key1}'], '{= key2}']) |
added experimental DBIx::Cus...
|
917 |
->param({key1 => [0, 3], key2 => 2}); |
experimental extended select...
|
918 |
$result = $dbi->select( |
919 |
table => 'table1', |
|
added experimental DBIx::Cus...
|
920 |
where => $where, |
added experimental not_exist...
|
921 |
); |
experimental extended select...
|
922 |
$row = $result->fetch_hash_all; |
923 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
|
924 | ||
added experimental DBIx::Cus...
|
925 |
$where = $dbi->where; |
926 |
$result = $dbi->select( |
|
927 |
table => 'table1', |
|
928 |
where => $where |
|
929 |
); |
|
930 |
$row = $result->fetch_hash_all; |
|
931 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]); |
|
932 | ||
experimental extended select...
|
933 |
eval { |
added experimental DBIx::Cus...
|
934 |
$where = $dbi->where |
added test
|
935 |
->clause(['uuu']); |
experimental extended select...
|
936 |
$result = $dbi->select( |
937 |
table => 'table1', |
|
added experimental DBIx::Cus...
|
938 |
where => $where |
experimental extended select...
|
939 |
); |
940 |
}; |
|
941 |
ok($@); |
|
942 | ||
added experimental DBIx::Cus...
|
943 |
$where = $dbi->where; |
944 |
is("$where", ''); |
|
945 | ||
added test
|
946 |
$where = $dbi->where |
947 |
->clause(['or', ('{= key1}') x 2]) |
|
948 |
->param({key1 => [1, 3]}); |
|
949 |
$result = $dbi->select( |
|
950 |
table => 'table1', |
|
951 |
where => $where, |
|
952 |
); |
|
953 |
$row = $result->fetch_hash_all; |
|
954 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]); |
|
955 | ||
956 |
$where = $dbi->where |
|
957 |
->clause(['or', ('{= key1}') x 2]) |
|
958 |
->param({key1 => [1]}); |
|
959 |
$result = $dbi->select( |
|
960 |
table => 'table1', |
|
961 |
where => $where, |
|
962 |
); |
|
963 |
$row = $result->fetch_hash_all; |
|
964 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
|
965 | ||
966 |
$where = $dbi->where |
|
967 |
->clause(['or', ('{= key1}') x 2]) |
|
968 |
->param({key1 => 1}); |
|
969 |
$result = $dbi->select( |
|
970 |
table => 'table1', |
|
971 |
where => $where, |
|
972 |
); |
|
973 |
$row = $result->fetch_hash_all; |
|
974 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
|
added experimental DBIx::Cus...
|
975 | |
many changed
|
976 |
$where = $dbi->where |
977 |
->clause('{= key1}') |
|
978 |
->param({key1 => 1}); |
|
979 |
$result = $dbi->select( |
|
980 |
table => 'table1', |
|
981 |
where => $where, |
|
982 |
); |
|
983 |
$row = $result->fetch_hash_all; |
|
984 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
|
985 | ||
986 |
$where = $dbi->where |
|
987 |
->clause('{= key1} {= key2}') |
|
988 |
->param({key1 => 1}); |
|
989 |
eval{$where->to_string}; |
|
990 |
like($@, qr/one column/); |
|
991 | ||
added experimental not_exist...
|
992 |
$where = $dbi->where |
993 |
->clause('{= key1}') |
|
994 |
->param([]); |
|
995 |
eval{$where->to_string}; |
|
996 |
like($@, qr/Parameter/); |
|
997 | ||
998 |
$where = $dbi->where |
|
999 |
->clause(['or', ('{= key1}') x 3]) |
|
1000 |
->param({key1 => [$dbi->not_exists, 1, 3]}); |
|
1001 |
$result = $dbi->select( |
|
1002 |
table => 'table1', |
|
1003 |
where => $where, |
|
1004 |
); |
|
1005 |
$row = $result->fetch_hash_all; |
|
1006 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists'); |
|
1007 | ||
1008 |
$where = $dbi->where |
|
1009 |
->clause(['or', ('{= key1}') x 3]) |
|
1010 |
->param({key1 => [1, $dbi->not_exists, 3]}); |
|
1011 |
$result = $dbi->select( |
|
1012 |
table => 'table1', |
|
1013 |
where => $where, |
|
1014 |
); |
|
1015 |
$row = $result->fetch_hash_all; |
|
1016 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists'); |
|
1017 | ||
1018 |
$where = $dbi->where |
|
1019 |
->clause(['or', ('{= key1}') x 3]) |
|
1020 |
->param({key1 => [1, 3, $dbi->not_exists]}); |
|
1021 |
$result = $dbi->select( |
|
1022 |
table => 'table1', |
|
1023 |
where => $where, |
|
1024 |
); |
|
1025 |
$row = $result->fetch_hash_all; |
|
1026 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists'); |
|
1027 | ||
1028 |
$where = $dbi->where |
|
1029 |
->clause(['or', ('{= key1}') x 3]) |
|
1030 |
->param({key1 => [1, $dbi->not_exists, $dbi->not_exists]}); |
|
1031 |
$result = $dbi->select( |
|
1032 |
table => 'table1', |
|
1033 |
where => $where, |
|
1034 |
); |
|
1035 |
$row = $result->fetch_hash_all; |
|
1036 |
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists'); |
|
1037 | ||
1038 |
$where = $dbi->where |
|
1039 |
->clause(['or', ('{= key1}') x 3]) |
|
1040 |
->param({key1 => [$dbi->not_exists, 1, $dbi->not_exists]}); |
|
1041 |
$result = $dbi->select( |
|
1042 |
table => 'table1', |
|
1043 |
where => $where, |
|
1044 |
); |
|
1045 |
$row = $result->fetch_hash_all; |
|
1046 |
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists'); |
|
1047 | ||
1048 |
$where = $dbi->where |
|
1049 |
->clause(['or', ('{= key1}') x 3]) |
|
1050 |
->param({key1 => [$dbi->not_exists, $dbi->not_exists, 1]}); |
|
1051 |
$result = $dbi->select( |
|
1052 |
table => 'table1', |
|
1053 |
where => $where, |
|
1054 |
); |
|
1055 |
$row = $result->fetch_hash_all; |
|
1056 |
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists'); |
|
1057 | ||
1058 |
$where = $dbi->where |
|
1059 |
->clause(['or', ('{= key1}') x 3]) |
|
1060 |
->param({key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]}); |
|
1061 |
$result = $dbi->select( |
|
1062 |
table => 'table1', |
|
1063 |
where => $where, |
|
1064 |
); |
|
1065 |
$row = $result->fetch_hash_all; |
|
1066 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists'); |
|
1067 | ||
make delete() using where ob...
|
1068 |
$where = $dbi->where |
1069 |
->clause(['or', ('{= key1}') x 3]) |
|
1070 |
->param({key1 => []}); |
|
1071 |
$result = $dbi->select( |
|
1072 |
table => 'table1', |
|
1073 |
where => $where, |
|
1074 |
); |
|
1075 |
$row = $result->fetch_hash_all; |
|
1076 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists'); |
|
1077 | ||
1078 |
$where = $dbi->where |
|
1079 |
->clause(['and', '{> key1}', '{< key1}' ]) |
|
1080 |
->param({key1 => [2, $dbi->not_exists]}); |
|
1081 |
$result = $dbi->select( |
|
1082 |
table => 'table1', |
|
1083 |
where => $where, |
|
1084 |
); |
|
1085 |
$row = $result->fetch_hash_all; |
|
1086 |
is_deeply($row, [{key1 => 3, key2 => 4}], 'not_exists'); |
|
1087 | ||
1088 |
$where = $dbi->where |
|
1089 |
->clause(['and', '{> key1}', '{< key1}' ]) |
|
1090 |
->param({key1 => [$dbi->not_exists, 2]}); |
|
1091 |
$result = $dbi->select( |
|
1092 |
table => 'table1', |
|
1093 |
where => $where, |
|
1094 |
); |
|
1095 |
$row = $result->fetch_hash_all; |
|
1096 |
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists'); |
|
1097 | ||
1098 |
$where = $dbi->where |
|
1099 |
->clause(['and', '{> key1}', '{< key1}' ]) |
|
1100 |
->param({key1 => [$dbi->not_exists, $dbi->not_exists]}); |
|
1101 |
$result = $dbi->select( |
|
1102 |
table => 'table1', |
|
1103 |
where => $where, |
|
1104 |
); |
|
1105 |
$row = $result->fetch_hash_all; |
|
1106 |
is_deeply($row, [{key1 => 1, key2 => 2},{key1 => 3, key2 => 4}], 'not_exists'); |
|
1107 | ||
1108 |
$where = $dbi->where |
|
1109 |
->clause(['and', '{> key1}', '{< key1}' ]) |
|
1110 |
->param({key1 => [0, 2]}); |
|
1111 |
$result = $dbi->select( |
|
1112 |
table => 'table1', |
|
1113 |
where => $where, |
|
1114 |
); |
|
1115 |
$row = $result->fetch_hash_all; |
|
1116 |
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists'); |
|
1117 | ||
renamed dbi_options to dbi_o...
|
1118 |
test 'dbi_option default'; |
added experimental DBIx::Cus...
|
1119 |
$dbi = DBIx::Custom->new; |
renamed dbi_options to dbi_o...
|
1120 |
is_deeply($dbi->dbi_option, {}); |
added experimental DBIx::Cus...
|
1121 | |
added register_tag_processor
|
1122 |
test 'register_tag_processor'; |
1123 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1124 |
$dbi->register_tag_processor( |
|
1125 |
a => sub { 1 } |
|
1126 |
); |
|
1127 |
is($dbi->query_builder->tag_processors->{a}->(), 1); |
|
added experimental DBIx::Cus...
|
1128 | |
renamed DBIx::Custom::TagPro...
|
1129 |
test 'register_tag'; |
1130 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1131 |
$dbi->register_tag( |
|
1132 |
b => sub { 2 } |
|
1133 |
); |
|
1134 |
is($dbi->query_builder->tags->{b}->(), 2); |
|
1135 | ||
added table not specified ex...
|
1136 |
test 'table not specify exception'; |
1137 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1138 |
eval {$dbi->insert}; |
|
1139 |
like($@, qr/table/); |
|
1140 |
eval {$dbi->update}; |
|
1141 |
like($@, qr/table/); |
|
1142 |
eval {$dbi->delete}; |
|
1143 |
like($@, qr/table/); |
|
1144 |
eval {$dbi->select}; |
|
1145 |
like($@, qr/table/); |
|
many changed
|
1146 | |
1147 | ||
1148 |
test 'more tests'; |
|
1149 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1150 |
eval{$dbi->apply_filter('table', 'column', [])}; |
|
1151 |
like($@, qr/apply_filter/); |
|
1152 | ||
1153 |
eval{$dbi->apply_filter('table', 'column', {outer => 2})}; |
|
1154 |
like($@, qr/apply_filter/); |
|
1155 | ||
1156 |
$dbi->apply_filter( |
|
1157 | ||
1158 |
); |
|
1159 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1160 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1161 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1162 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
1163 |
$dbi->apply_filter('table1', 'key2', |
|
1164 |
{in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }}); |
|
1165 |
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->fetch_hash_all; |
|
1166 |
is_deeply($rows, [{key1 => 1, key2 => 6}]); |
|
1167 | ||
1168 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1169 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1170 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1171 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
1172 |
$dbi->apply_filter('table1', 'key2', {}); |
|
1173 |
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->fetch_hash_all; |
|
1174 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
|
1175 | ||
1176 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1177 |
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})}; |
|
1178 |
like($@, qr/not registered/); |
|
1179 |
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})}; |
|
1180 |
like($@, qr/not registered/); |
|
renamed helper to method.
|
1181 |
$dbi->method({one => sub { 1 }}); |
many changed
|
1182 |
is($dbi->one, 1); |
1183 | ||
1184 |
eval{DBIx::Custom->connect()}; |
|
1185 |
like($@, qr/connect/); |
|
1186 | ||
1187 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1188 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1189 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1190 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, |
|
1191 |
filter => {key1 => 'twice'}); |
|
1192 |
$row = $dbi->select(table => 'table1')->fetch_hash_first; |
|
1193 |
is_deeply($row, {key1 => 2, key2 => 2}); |
|
1194 |
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, |
|
1195 |
filter => {key1 => 'no'}) }; |
|
1196 |
like($@, qr//); |
|
1197 | ||
1198 |
$dbi->register_filter(one => sub { }); |
|
1199 |
$dbi->default_fetch_filter('one'); |
|
1200 |
ok($dbi->default_fetch_filter); |
|
1201 |
$dbi->default_bind_filter('one'); |
|
1202 |
ok($dbi->default_bind_filter); |
|
1203 |
eval{$dbi->default_fetch_filter('no')}; |
|
1204 |
like($@, qr/not registered/); |
|
1205 |
eval{$dbi->default_bind_filter('no')}; |
|
1206 |
like($@, qr/not registered/); |
|
1207 |
$dbi->default_bind_filter(undef); |
|
1208 |
ok(!defined $dbi->default_bind_filter); |
|
1209 |
$dbi->default_fetch_filter(undef); |
|
1210 |
ok(!defined $dbi->default_fetch_filter); |
|
1211 |
eval {$dbi->execute('select * from table1 {= author') }; |
|
1212 |
like($@, qr/Tag not finished/); |
|
1213 | ||
1214 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1215 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1216 |
$dbi->register_filter(one => sub { 1 }); |
|
1217 |
$result = $dbi->select(table => 'table1'); |
|
1218 |
eval {$result->filter(key1 => 'no')}; |
|
1219 |
like($@, qr/not registered/); |
|
1220 |
eval {$result->end_filter(key1 => 'no')}; |
|
1221 |
like($@, qr/not registered/); |
|
1222 |
$result->default_filter(undef); |
|
1223 |
ok(!defined $result->default_filter); |
|
1224 |
$result->default_filter('one'); |
|
1225 |
is($result->default_filter->(), 1); |
|
1226 | ||
1227 |
$dbi->table('book'); |
|
1228 |
eval{$dbi->table('book')->no_exists}; |
|
renamed dbi_options to dbi_o...
|
1229 |
like($@, qr/locate/); |
1230 | ||
1231 |
test 'dbi_option'; |
|
1232 |
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:', |
|
1233 |
dbi_option => {PrintError => 1}); |
|
1234 |
ok($dbi->dbh->{PrintError}); |
|
1235 |
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:', |
|
1236 |
dbi_options => {PrintError => 1}); |
|
1237 |
ok($dbi->dbh->{PrintError}); |
|
1238 | ||
added experimental DBIx::Cus...
|
1239 |
test 'DBIx::Custom::Result stash()'; |
1240 |
$result = DBIx::Custom::Result->new; |
|
1241 |
is_deeply($result->stash, {}, 'default'); |
|
1242 |
$result->stash->{foo} = 1; |
|
1243 |
is($result->stash->{foo}, 1, 'get and set'); |
|
table object call dbi object...
|
1244 | |
1245 |
test 'base_table'; |
|
1246 |
$dbi = DBIx::Custom->new; |
|
1247 |
$dbi->base_table->method( |
|
1248 |
one => sub { 1 } |
|
1249 |
); |
|
1250 |
$table = $dbi->table('book'); |
|
1251 |
$table->method( |
|
1252 |
two => sub { 2 } |
|
1253 |
); |
|
1254 |
is($dbi->base_table->one, 1, 'method'); |
|
1255 |
is($table->one, 1, 'inherit method'); |
|
1256 |
is($table->two, 2, 'child table method'); |
|
1257 |
eval {$dbi->base_table->two}; |
|
1258 |
ok($@); |
|
1259 | ||
1260 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1261 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1262 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1263 |
$result = $dbi->base_table->execute("select * from table1"); |
|
1264 |
is_deeply($result->fetch_hash_all, [{key1 => 1, key2 => 2}], 'dbi method from base_table'); |
|
1265 |
$result = $dbi->table('table1')->execute("select * from table1"); |
|
1266 |
is_deeply($result->fetch_hash_all, [{key1 => 1, key2 => 2}], 'dbi method from table'); |
|
table object call dbi object...
|
1267 | |
1268 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1269 |
$dbi->method( |
|
1270 |
one => sub { 1 } |
|
1271 |
); |
|
1272 |
is($dbi->base_table->one, 1, 'use dbi method'); |
|
1273 |
is($dbi->table('table1')->one, 1, 'use dbi method'); |
|
added experimental not_exist...
|
1274 |