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