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