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