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