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