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 = { |
|
data_source is DEPRECATED! I...
|
45 |
0 => {dsn => 'dbi:SQLite:dbname=:memory:'} |
removed register_format()
|
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'; |
|
data_source is DEPRECATED! I...
|
208 |
eval {DBIx::Custom->connect(dsn => '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()}; |
|
cleanup
|
1331 |
like($@, qr/_connect/); |
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'; |
data_source is DEPRECATED! I...
|
1374 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:', |
renamed dbi_options to dbi_o...
|
1375 |
dbi_option => {PrintError => 1}); |
1376 |
ok($dbi->dbh->{PrintError}); |
|
data_source is DEPRECATED! I...
|
1377 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:', |
renamed dbi_options to dbi_o...
|
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 assign_ta...
|
1795 |
test 'update_param_tag'; |
added experimental update_pa...
|
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 | ||
added EXPERIMENTAL assign_ta...
|
1856 |
test 'set_tag'; |
1857 |
test 'update_param_tag'; |
|
1858 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1859 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1860 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
1861 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
1862 | ||
1863 |
$param = {key2 => 11}; |
|
1864 |
$update_param = $dbi->assign_tag($param); |
|
1865 |
$sql = <<"EOS"; |
|
1866 |
update {table table1} set $update_param |
|
1867 |
where key1 = 1 |
|
1868 |
EOS |
|
1869 |
$dbi->execute($sql, param => $param); |
|
1870 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
1871 |
$rows = $result->fetch_hash_all; |
|
1872 |
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5}, |
|
1873 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
1874 |
"basic"); |
|
1875 | ||
1876 | ||
added experimental update_pa...
|
1877 |
test 'insert_param'; |
1878 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1879 |
$dbi->execute($CREATE_TABLE->{1}); |
|
added EXPERIMENTAL updat_par...
|
1880 |
$param = {key1 => 1, key2 => 2}; |
- renamed update_param to up...
|
1881 |
$insert_param = $dbi->insert_param_tag($param); |
added experimental update_pa...
|
1882 |
$sql = <<"EOS"; |
1883 |
insert into {table table1} $insert_param |
|
1884 |
EOS |
|
added EXPERIMENTAL updat_par...
|
1885 |
$dbi->execute($sql, param => $param); |
1886 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1); |
|
1887 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2); |
|
added experimental update_pa...
|
1888 | |
added EXPERIMENTAL updat_par...
|
1889 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
1890 |
$dbi->reserved_word_quote('"'); |
|
1891 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1892 |
$param = {key1 => 1, key2 => 2}; |
|
- renamed update_param to up...
|
1893 |
$insert_param = $dbi->insert_param_tag($param); |
added EXPERIMENTAL updat_par...
|
1894 |
$sql = <<"EOS"; |
1895 |
insert into {table table1} $insert_param |
|
1896 |
EOS |
|
added experimental update_pa...
|
1897 |
$dbi->execute($sql, param => $param); |
1898 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1); |
|
added EXPERIMENTAL updat_par...
|
1899 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2); |
add experimental DBIx::Custo...
|
1900 | |
- renamed update_param to up...
|
1901 |
eval { $dbi->insert_param_tag({";" => 1}) }; |
added experimental update_pa...
|
1902 |
like($@, qr/not safety/); |
cleanup
|
1903 | |
1904 | ||
- added experimental DBIx::C...
|
1905 |
test 'join'; |
cleanup
|
1906 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
1907 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1908 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1909 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
1910 |
$dbi->execute($CREATE_TABLE->{2}); |
|
1911 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5}); |
|
- added experimental DBIx::C...
|
1912 |
$dbi->execute($CREATE_TABLE->{4}); |
1913 |
$dbi->insert(table => 'table3', param => {key3 => 5, key4 => 4}); |
|
cleanup
|
1914 |
$rows = $dbi->select( |
1915 |
table => 'table1', |
|
1916 |
column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3', |
|
1917 |
where => {'table1.key2' => 2}, |
|
- added experimental DBIx::C...
|
1918 |
join => ['left outer join table2 on table1.key1 = table2.key1'] |
cleanup
|
1919 |
)->fetch_hash_all; |
1920 |
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}]); |
|
1921 | ||
- added experimental DBIx::C...
|
1922 |
$rows = $dbi->select( |
1923 |
table => 'table1', |
|
1924 |
where => {'key1' => 1}, |
|
1925 |
join => ['left outer join table2 on table1.key1 = table2.key1'] |
|
1926 |
)->fetch_hash_all; |
|
1927 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
|
1928 | ||
cleanup
|
1929 |
eval { |
1930 |
$rows = $dbi->select( |
|
1931 |
table => 'table1', |
|
1932 |
column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3', |
|
1933 |
where => {'table1.key2' => 2}, |
|
- added experimental DBIx::C...
|
1934 |
join => {'table1.key1' => 'table2.key1'} |
cleanup
|
1935 |
); |
1936 |
}; |
|
1937 |
like ($@, qr/array/); |
|
- added experimental DBIx::C...
|
1938 | |
1939 |
$rows = $dbi->select( |
|
1940 |
table => 'table1', |
|
1941 |
where => {'key1' => 1}, |
|
1942 |
join => ['left outer join table2 on table1.key1 = table2.key1', |
|
1943 |
'left outer join table3 on table2.key3 = table3.key3'] |
|
1944 |
)->fetch_hash_all; |
|
1945 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
|
1946 | ||
1947 |
$rows = $dbi->select( |
|
1948 |
column => 'table3.key4 as table3__key4', |
|
1949 |
table => 'table1', |
|
1950 |
where => {'table1.key1' => 1}, |
|
1951 |
join => ['left outer join table2 on table1.key1 = table2.key1', |
|
1952 |
'left outer join table3 on table2.key3 = table3.key3'] |
|
1953 |
)->fetch_hash_all; |
|
1954 |
is_deeply($rows, [{table3__key4 => 4}]); |
|
1955 | ||
1956 |
$rows = $dbi->select( |
|
1957 |
column => 'table1.key1 as table1__key1', |
|
1958 |
table => 'table1', |
|
1959 |
where => {'table3.key4' => 4}, |
|
1960 |
join => ['left outer join table2 on table1.key1 = table2.key1', |
|
1961 |
'left outer join table3 on table2.key3 = table3.key3'] |
|
1962 |
)->fetch_hash_all; |
|
1963 |
is_deeply($rows, [{table1__key1 => 1}]); |
|
- added experimental DBIx::C...
|
1964 | |
added EXPERIMENTAL reserved_...
|
1965 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
1966 |
$dbi->reserved_word_quote('"'); |
|
1967 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1968 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1969 |
$dbi->execute($CREATE_TABLE->{2}); |
|
1970 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5}); |
|
1971 |
$rows = $dbi->select( |
|
1972 |
table => 'table1', |
|
1973 |
column => '"table1"."key1" as "table1_key1", "table2"."key1" as "table2_key1", "key2", "key3"', |
|
1974 |
where => {'table1.key2' => 2}, |
|
1975 |
join => ['left outer join "table2" on "table1"."key1" = "table2"."key1"'], |
|
1976 |
)->fetch_hash_all; |
|
1977 |
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], |
|
1978 |
'reserved_word_quote'); |
|
- added experimental DBIx::C...
|
1979 | |
1980 |
{ |
|
1981 |
package MyDBI8; |
|
1982 |
|
|
1983 |
use base 'DBIx::Custom'; |
|
1984 |
|
|
1985 |
sub connect { |
|
1986 |
my $self = shift->SUPER::connect(@_); |
|
1987 |
|
|
1988 |
$self->include_model('MyModel7'); |
|
1989 |
|
|
1990 |
return $self; |
|
1991 |
} |
|
1992 |
} |
|
added select() all_column op...
|
1993 | |
data_source is DEPRECATED! I...
|
1994 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
1995 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1996 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1997 |
$sql = <<"EOS"; |
|
1998 |
left outer join ( |
|
1999 |
select * from table1 as t1 |
|
2000 |
where t1.key2 = ( |
|
2001 |
select max(t2.key2) from table1 as t2 |
|
2002 |
where t1.key1 = t2.key1 |
|
2003 |
) |
|
2004 |
) as latest_table1 on table1.key1 = latest_table1.key1 |
|
2005 |
EOS |
|
2006 |
$join = [$sql]; |
|
2007 |
$rows = $dbi->select( |
|
2008 |
table => 'table1', |
|
2009 |
column => 'latest_table1.key1 as latest_table1__key1', |
|
2010 |
join => $join |
|
2011 |
)->fetch_hash_all; |
|
2012 |
is_deeply($rows, [{latest_table1__key1 => 1}]); |
|
2013 | ||
- added EXPERIMENTAL DBIx::C...
|
2014 |
test 'mycolumn'; |
2015 |
$dbi = MyDBI8->connect($NEW_ARGS->{0}); |
|
- added EXPERIMENTAL DBIx::C...
|
2016 |
$dbi->execute($CREATE_TABLE->{0}); |
- added EXPERIMENTAL DBIx::C...
|
2017 |
$dbi->execute($CREATE_TABLE->{2}); |
2018 |
$dbi->setup_model; |
|
2019 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2020 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3}); |
|
2021 |
$model = $dbi->model('table1'); |
|
2022 |
$result = $model->select_at( |
|
2023 |
column => [ |
|
2024 |
$model->mycolumn, |
|
2025 |
$model->column('table2') |
|
2026 |
] |
|
- added EXPERIMENTAL DBIx::C...
|
2027 |
); |
- added EXPERIMENTAL DBIx::C...
|
2028 |
is_deeply($result->fetch_hash_first, |
2029 |
{key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3}); |
|
2030 |
$result = $model->select_at( |
|
2031 |
column => [ |
|
2032 |
$model->mycolumn(['key1']), |
|
2033 |
$model->column(table2 => ['key1']) |
|
2034 |
] |
|
2035 |
); |
|
2036 |
is_deeply($result->fetch_hash_first, |
|
2037 |
{key1 => 1, table2__key1 => 1}); |
|
- added EXPERIMENTAL DBIx::C...
|
2038 | |
- added EXPERIMENTAL DBIx::C...
|
2039 |
test 'dbi method from model'; |
- added EXPERIMENTAL DBIx::C...
|
2040 |
{ |
2041 |
package MyDBI9; |
|
2042 |
|
|
2043 |
use base 'DBIx::Custom'; |
|
2044 |
|
|
2045 |
sub connect { |
|
2046 |
my $self = shift->SUPER::connect(@_); |
|
2047 |
|
|
2048 |
$self->include_model('MyModel8')->setup_model; |
|
2049 |
|
|
2050 |
return $self; |
|
2051 |
} |
|
2052 |
} |
|
2053 |
$dbi = MyDBI9->connect($NEW_ARGS->{0}); |
|
2054 |
$dbi->execute($CREATE_TABLE->{0}); |
|
- added EXPERIMENTAL DBIx::C...
|
2055 |
$model = $dbi->model('table1'); |
2056 |
eval{$model->execute('select * from table1')}; |
|
2057 |
ok(!$@); |
|
2058 | ||
2059 |
test 'table_alias'; |
|
2060 |
$dbi = MyDBI9->connect($NEW_ARGS->{0}); |
|
2061 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2062 |
$dbi->execute($CREATE_TABLE->{2}); |
|
2063 |
$dbi->setup_model; |
|
2064 |
$dbi->execute('insert into table1 (key1, key2) values (1, 2);'); |
|
2065 |
$dbi->execute('insert into table2 (key1, key3) values (1, 4);'); |
|
2066 |
$model = $dbi->model('table1'); |
|
2067 |
$result = $model->select( |
|
2068 |
column => [ |
|
2069 |
$model->column('table2_alias') |
|
2070 |
], |
|
2071 |
where => {'table2_alias.key3' => 2} |
|
2072 |
); |
|
2073 |
is_deeply($result->fetch_hash_first, |
|
2074 |
{table2_alias__key1 => 1, table2_alias__key3 => 48}); |
|
2075 | ||
- added EXPERIMENTAL type() ...
|
2076 |
test 'type() option'; |
2077 |
$dbi = DBIx::Custom->connect( |
|
2078 |
data_source => 'dbi:SQLite:dbname=:memory:', |
|
2079 |
dbi_option => { |
|
2080 |
$DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1) |
|
2081 |
} |
|
2082 |
); |
|
2083 |
my $binary = pack("I3", 1, 2, 3); |
|
2084 |
$dbi->execute('create table table1(key1, key2)'); |
|
2085 |
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [key1 => DBI::SQL_BLOB]); |
|
2086 |
$result = $dbi->select(table => 'table1'); |
|
2087 |
$row = $result->fetch_hash_first; |
|
2088 |
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic"); |
|
2089 |
$result = $dbi->execute('select length(key1) as key1_length from table1'); |
|
2090 |
$row = $result->fetch_hash_first; |
|
2091 |
is($row->{key1_length}, length $binary); |
|
2092 | ||
2093 |
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [['key1'] => DBI::SQL_BLOB]); |
|
2094 |
$result = $dbi->select(table => 'table1'); |
|
2095 |
$row = $result->fetch_hash_first; |
|
2096 |
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic"); |
|
2097 |
$result = $dbi->execute('select length(key1) as key1_length from table1'); |
|
2098 |
$row = $result->fetch_hash_first; |
|
2099 |
is($row->{key1_length}, length $binary); |
|
2100 | ||
removed EXPERIMETNAL flag fr...
|
2101 |
test 'create_model'; |
2102 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2103 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2104 |
$dbi->execute($CREATE_TABLE->{2}); |
|
2105 | ||
2106 |
$dbi->create_model( |
|
2107 |
table => 'table1', |
|
2108 |
join => [ |
|
2109 |
'left outer join table2 on table1.key1 = table2.key1' |
|
2110 |
], |
|
2111 |
primary_key => ['key1'] |
|
2112 |
); |
|
create_model() return model
|
2113 |
$model2 = $dbi->create_model( |
removed EXPERIMETNAL flag fr...
|
2114 |
table => 'table2' |
2115 |
); |
|
2116 |
$dbi->create_model( |
|
2117 |
table => 'table3', |
|
2118 |
filter => [ |
|
2119 |
key1 => {in => sub { uc $_[0] }} |
|
2120 |
] |
|
2121 |
); |
|
2122 |
$dbi->setup_model; |
|
2123 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2124 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3}); |
|
2125 |
$model = $dbi->model('table1'); |
|
2126 |
$result = $model->select( |
|
2127 |
column => [$model->mycolumn, $model->column('table2')], |
|
2128 |
where => {'table1.key1' => 1} |
|
2129 |
); |
|
2130 |
is_deeply($result->fetch_hash_first, |
|
2131 |
{key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3}); |
|
create_model() return model
|
2132 |
is_deeply($model2->select->fetch_hash_first, {key1 => 1, key3 => 3}); |
removed EXPERIMETNAL flag fr...
|
2133 | |
adeed EXPERIMENTAL DBIx::Cus...
|
2134 |
test 'model method'; |
2135 |
test 'create_model'; |
|
2136 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2137 |
$dbi->execute($CREATE_TABLE->{2}); |
|
2138 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3}); |
|
2139 |
$model = $dbi->create_model( |
|
2140 |
table => 'table2' |
|
2141 |
); |
|
2142 |
$model->method(foo => sub { shift->select(@_) }); |
|
2143 |
is_deeply($model->foo->fetch_hash_first, {key1 => 1, key3 => 3}); |
|
added EXPERIMENTAL updat_par...
|
2144 | |
2145 |
test 'merge_param'; |
|
2146 |
{ |
|
2147 |
my $dbi = DBIx::Custom->new; |
|
2148 |
my $param1 = {key1 => 1, key2 => 2, key3 => 3}; |
|
2149 |
my $param2 = {key1 => 1, key2 => 2}; |
|
2150 |
my $param3 = {key1 => 1}; |
|
2151 |
my $param = $dbi->merge_param($param1, $param2, $param3); |
|
2152 |
is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3}); |
|
cleanup
|
2153 |
} |
2154 | ||
fixed merge_param bug
|
2155 |
{ |
2156 |
my $dbi = DBIx::Custom->new; |
|
2157 |
my $param1 = {key1 => [1, 2], key2 => 1, key3 => [1, 2]}; |
|
2158 |
my $param2 = {key1 => [3, 4], key2 => [2, 3], key3 => 3}; |
|
2159 |
my $param = $dbi->merge_param($param1, $param2); |
|
2160 |
is_deeply($param, {key1 => [1, 2, 3, 4], key2 => [1, 2, 3], key3 => [1, 2, 3]}); |
|
2161 |
} |
|
2162 | ||
cleanup
|
2163 |
test 'select() param option'; |
2164 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2165 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2166 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2167 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3}); |
|
2168 |
$dbi->execute($CREATE_TABLE->{2}); |
|
2169 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4}); |
|
2170 |
$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5}); |
|
2171 |
$rows = $dbi->select( |
|
2172 |
table => 'table1', |
|
2173 |
column => 'table1.key1 as table1_key1, key2, key3', |
|
2174 |
where => {'table1.key2' => 3}, |
|
2175 |
join => ['inner join (select * from table2 where {= table2.key3})' . |
|
2176 |
' as table2 on table1.key1 = table2.key1'], |
|
2177 |
param => {'table2.key3' => 5} |
|
2178 |
)->fetch_hash_all; |
|
2179 |
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]); |
|
2180 | ||
added EXPERIMENTAL select() ...
|
2181 | |
2182 |
test 'select() wrap option'; |
|
2183 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2184 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2185 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2186 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3}); |
|
2187 |
$rows = $dbi->select( |
|
2188 |
table => 'table1', |
|
2189 |
column => 'key1', |
|
2190 |
wrap => ['select * from (', ') as t where key1 = 1'] |
|
2191 |
)->fetch_hash_all; |
|
2192 |
is_deeply($rows, [{key1 => 1}]); |
|
2193 | ||
2194 |
eval { |
|
2195 |
$dbi->select( |
|
2196 |
table => 'table1', |
|
2197 |
column => 'key1', |
|
2198 |
wrap => 'select * from (' |
|
2199 |
) |
|
2200 |
}; |
|
cleanup
|
2201 |
like($@, qr/array/); |
2202 | ||
2203 |
test 'select() string where'; |
|
2204 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2205 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2206 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2207 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3}); |
|
2208 |
$rows = $dbi->select( |
|
2209 |
table => 'table1', |
|
select, update, and delete w...
|
2210 |
where => '{= key1} and {= key2}', |
DEPRECATED select() param op...
|
2211 |
where_param => {key1 => 1, key2 => 2} |
cleanup
|
2212 |
)->fetch_hash_all; |
2213 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
|
select, update, and delete w...
|
2214 | |
2215 |
test 'delete() string where'; |
|
2216 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2217 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2218 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2219 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3}); |
|
2220 |
$dbi->delete( |
|
2221 |
table => 'table1', |
|
2222 |
where => '{= key1} and {= key2}', |
|
DEPRECATED select() param op...
|
2223 |
where_param => {key1 => 1, key2 => 2} |
select, update, and delete w...
|
2224 |
); |
2225 |
$rows = $dbi->select(table => 'table1')->fetch_hash_all; |
|
2226 |
is_deeply($rows, [{key1 => 2, key2 => 3}]); |
|
2227 | ||
2228 | ||
2229 |
test 'update() string where'; |
|
2230 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2231 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2232 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2233 |
$dbi->update( |
|
2234 |
table => 'table1', |
|
DEPRECATED select() param op...
|
2235 |
param => {key1 => 5}, |
2236 |
where => '{= key1} and {= key2}', |
|
2237 |
where_param => {key1 => 1, key2 => 2} |
|
select, update, and delete w...
|
2238 |
); |
2239 |
$rows = $dbi->select(table => 'table1')->fetch_hash_all; |
|
2240 |
is_deeply($rows, [{key1 => 5, key2 => 2}]); |