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