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