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