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 | |
EXPERIMENTAL type_rule_off i...
|
9 |
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/}; |
removed EXPERIMETNAL select(...
|
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; |
added EXPERIMENTAL select pr...
|
107 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "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}); |
|
added EXPERIMENTAL select pr...
|
124 |
$rows = $result->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}); |
added EXPERIMENTAL select pr...
|
138 |
$rows = $result->filter({key2 => 'three_times'})->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]}); |
|
added EXPERIMENTAL select pr...
|
151 |
$rows = $result->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}); |
added EXPERIMENTAL select pr...
|
163 |
$rows = $result->all; |
cleanup
|
164 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag1"); |
removed register_format()
|
165 | |
execute method can second ar...
|
166 |
$source = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};"; |
167 |
$query = $dbi->create_query($source); |
|
168 |
$result = $dbi->execute($query, {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5}); |
|
added EXPERIMENTAL select pr...
|
169 |
$rows = $result->all; |
execute method can second ar...
|
170 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag1"); |
171 | ||
renamed build_query to creat...
|
172 |
$source = "select * from table1 where {<= key1} and {like key2};"; |
173 |
$query = $dbi->create_query($source); |
|
removed register_format()
|
174 |
$result = $dbi->execute($query, param => {key1 => 1, key2 => '%2%'}); |
added EXPERIMENTAL select pr...
|
175 |
$rows = $result->all; |
cleanup
|
176 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag2"); |
removed register_format()
|
177 | |
178 |
test 'DIB::Custom::SQLTemplate in tag'; |
|
179 |
$dbi->execute($DROP_TABLE->{0}); |
|
180 |
$dbi->execute($CREATE_TABLE->{1}); |
|
181 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
182 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
183 | ||
renamed build_query to creat...
|
184 |
$source = "select * from table1 where {in key1 2};"; |
185 |
$query = $dbi->create_query($source); |
|
removed register_format()
|
186 |
$result = $dbi->execute($query, param => {key1 => [9, 1]}); |
added EXPERIMENTAL select pr...
|
187 |
$rows = $result->all; |
cleanup
|
188 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic"); |
removed register_format()
|
189 | |
190 |
test 'DBIx::Custom::SQLTemplate insert tag'; |
|
191 |
$dbi->execute("delete from table1"); |
|
add tests
|
192 |
$insert_SOURCE = 'insert into table1 {insert_param key1 key2 key3 key4 key5}'; |
193 |
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
removed register_format()
|
194 | |
add tests
|
195 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
added EXPERIMENTAL select pr...
|
196 |
$rows = $result->all; |
cleanup
|
197 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic"); |
removed register_format()
|
198 | |
199 |
test 'DBIx::Custom::SQLTemplate update tag'; |
|
200 |
$dbi->execute("delete from table1"); |
|
add tests
|
201 |
$insert_SOURCE = "insert into table1 {insert_param key1 key2 key3 key4 key5}"; |
202 |
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
203 |
$dbi->execute($insert_SOURCE, param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
removed register_format()
|
204 | |
add tests
|
205 |
$update_SOURCE = 'update table1 {update_param key1 key2 key3 key4} where {= key5}'; |
206 |
$dbi->execute($update_SOURCE, param => {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5}); |
|
removed register_format()
|
207 | |
add tests
|
208 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
added EXPERIMENTAL select pr...
|
209 |
$rows = $result->all; |
removed register_format()
|
210 |
is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5}, |
cleanup
|
211 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "basic"); |
removed register_format()
|
212 | |
- update_param_tag is DEPREC...
|
213 | |
214 |
test 'parameter'; |
|
215 |
$dbi->execute($DROP_TABLE->{0}); |
|
216 |
$dbi->execute($CREATE_TABLE->{1}); |
|
217 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
218 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
219 | ||
220 |
$source = "select * from table1 where key1 = :key1 and key2 = :key2"; |
|
221 |
$result = $dbi->execute($source, param => {key1 => 1, key2 => 2}); |
|
added EXPERIMENTAL select pr...
|
222 |
$rows = $result->all; |
- update_param_tag is DEPREC...
|
223 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]); |
224 | ||
225 |
$source = "select * from table1 where key1 = \n:key1\n and key2 = :key2"; |
|
226 |
$result = $dbi->execute($source, param => {key1 => 1, key2 => 2}); |
|
added EXPERIMENTAL select pr...
|
227 |
$rows = $result->all; |
- update_param_tag is DEPREC...
|
228 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]); |
229 | ||
230 |
$source = "select * from table1 where key1 = :key1 or key1 = :key1"; |
|
231 |
$result = $dbi->execute($source, param => {key1 => [1, 2]}); |
|
added EXPERIMENTAL select pr...
|
232 |
$rows = $result->all; |
- update_param_tag is DEPREC...
|
233 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]); |
234 | ||
235 |
$source = "select * from table1 where key1 = :table1.key1 and key2 = :table1.key2"; |
|
236 |
$result = $dbi->execute( |
|
237 |
$source, |
|
238 |
param => {'table1.key1' => 1, 'table1.key2' => 1}, |
|
239 |
filter => {'table1.key2' => sub { $_[0] * 2 }} |
|
240 |
); |
|
added EXPERIMENTAL select pr...
|
241 |
$rows = $result->all; |
- update_param_tag is DEPREC...
|
242 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]); |
243 | ||
removed register_format()
|
244 |
test 'Error case'; |
data_source is DEPRECATED! I...
|
245 |
eval {DBIx::Custom->connect(dsn => 'dbi:SQLit')}; |
cleanup
|
246 |
ok($@, "connect error"); |
removed register_format()
|
247 | |
248 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
renamed build_query to creat...
|
249 |
eval{$dbi->create_query("{p }")}; |
cleanup
|
250 |
ok($@, "create_query invalid SQL template"); |
removed register_format()
|
251 | |
252 |
test 'insert'; |
|
253 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
254 |
$dbi->execute($CREATE_TABLE->{0}); |
|
255 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
256 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
add tests
|
257 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
added EXPERIMENTAL select pr...
|
258 |
$rows = $result->all; |
cleanup
|
259 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic"); |
removed register_format()
|
260 | |
261 |
$dbi->execute('delete from table1'); |
|
262 |
$dbi->register_filter( |
|
263 |
twice => sub { $_[0] * 2 }, |
|
264 |
three_times => sub { $_[0] * 3 } |
|
265 |
); |
|
renamed default_query_filter...
|
266 |
$dbi->default_bind_filter('twice'); |
removed register_format()
|
267 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => 'three_times'}); |
add tests
|
268 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
added EXPERIMENTAL select pr...
|
269 |
$rows = $result->all; |
cleanup
|
270 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter"); |
renamed default_query_filter...
|
271 |
$dbi->default_bind_filter(undef); |
removed register_format()
|
272 | |
273 |
$dbi->execute($DROP_TABLE->{0}); |
|
274 |
$dbi->execute($CREATE_TABLE->{0}); |
|
275 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, append => ' '); |
|
added EXPERIMENTAL select pr...
|
276 |
$rows = $dbi->select(table => 'table1')->all; |
removed register_format()
|
277 |
is_deeply($rows, [{key1 => 1, key2 => 2}], 'insert append'); |
278 | ||
changed argument of tag proc...
|
279 |
eval{$dbi->insert(table => 'table1', noexist => 1)}; |
cleanup
|
280 |
like($@, qr/noexist/, "invalid"); |
changed argument of tag proc...
|
281 | |
select() where can't receive...
|
282 |
eval{$dbi->insert(table => 'table', param => {';' => 1})}; |
283 |
like($@, qr/safety/); |
|
changed argument of tag proc...
|
284 | |
added EXPERIMENTAL reserved_...
|
285 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
286 |
$dbi->reserved_word_quote('"'); |
|
287 |
$dbi->execute('create table "table" ("select")'); |
|
288 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
|
289 |
$dbi->insert(table => 'table', param => {select => 1}); |
|
290 |
$result = $dbi->execute('select * from "table"'); |
|
added EXPERIMENTAL select pr...
|
291 |
$rows = $result->all; |
added EXPERIMENTAL reserved_...
|
292 |
is_deeply($rows, [{select => 2}], "reserved word"); |
293 | ||
- insert, insert_at, update,...
|
294 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
295 |
$dbi->execute($CREATE_TABLE->{0}); |
|
296 |
$dbi->insert({key1 => 1, key2 => 2}, table => 'table1'); |
|
297 |
$dbi->insert({key1 => 3, key2 => 4}, table => 'table1'); |
|
298 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
added EXPERIMENTAL select pr...
|
299 |
$rows = $result->all; |
- insert, insert_at, update,...
|
300 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic"); |
301 | ||
removed register_format()
|
302 |
test 'update'; |
303 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
304 |
$dbi->execute($CREATE_TABLE->{1}); |
|
305 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
306 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
307 |
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1}); |
|
add tests
|
308 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
added EXPERIMENTAL select pr...
|
309 |
$rows = $result->all; |
removed register_format()
|
310 |
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5}, |
311 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
cleanup
|
312 |
"basic"); |
removed register_format()
|
313 |
|
314 |
$dbi->execute("delete from table1"); |
|
315 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
316 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
317 |
$dbi->update(table => 'table1', param => {key2 => 12}, where => {key2 => 2, key3 => 3}); |
|
add tests
|
318 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
added EXPERIMENTAL select pr...
|
319 |
$rows = $result->all; |
removed register_format()
|
320 |
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5}, |
321 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
cleanup
|
322 |
"update key same as search key"); |
removed register_format()
|
323 | |
add tests
|
324 |
$dbi->update(table => 'table1', param => {key2 => [12]}, where => {key2 => 2, key3 => 3}); |
325 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
added EXPERIMENTAL select pr...
|
326 |
$rows = $result->all; |
add tests
|
327 |
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5}, |
328 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
cleanup
|
329 |
"update key same as search key : param is array ref"); |
add tests
|
330 | |
removed register_format()
|
331 |
$dbi->execute("delete from table1"); |
332 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
333 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
334 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
335 |
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1}, |
|
many changed
|
336 |
filter => {key2 => sub { $_[0] * 2 }}); |
add tests
|
337 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
added EXPERIMENTAL select pr...
|
338 |
$rows = $result->all; |
removed register_format()
|
339 |
is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5}, |
340 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
cleanup
|
341 |
"filter"); |
removed register_format()
|
342 | |
343 |
$result = $dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1}, append => ' '); |
|
344 | ||
changed argument of tag proc...
|
345 |
eval{$dbi->update(table => 'table1', noexist => 1)}; |
cleanup
|
346 |
like($@, qr/noexist/, "invalid"); |
changed argument of tag proc...
|
347 | |
348 |
eval{$dbi->update(table => 'table1')}; |
|
cleanup
|
349 |
like($@, qr/where/, "not contain where"); |
changed argument of tag proc...
|
350 | |
improved delete() and update...
|
351 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
352 |
$dbi->execute($CREATE_TABLE->{0}); |
|
353 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
354 |
$where = $dbi->where; |
|
- update_param_tag is DEPREC...
|
355 |
$where->clause(['and', 'key1 = :key1', 'key2 = :key2']); |
improved delete() and update...
|
356 |
$where->param({key1 => 1, key2 => 2}); |
357 |
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where); |
|
358 |
$result = $dbi->select(table => 'table1'); |
|
added EXPERIMENTAL select pr...
|
359 |
is_deeply($result->all, [{key1 => 3, key2 => 2}], 'update() where'); |
where can recieve array refr...
|
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 |
$dbi->update( |
|
365 |
table => 'table1', |
|
366 |
param => {key1 => 3}, |
|
367 |
where => [ |
|
368 |
['and', '{= key1}', '{= key2}'], |
|
369 |
{key1 => 1, key2 => 2} |
|
370 |
] |
|
371 |
); |
|
372 |
$result = $dbi->select(table => 'table1'); |
|
added EXPERIMENTAL select pr...
|
373 |
is_deeply($result->all, [{key1 => 3, key2 => 2}], 'update() where'); |
improved delete() and update...
|
374 | |
375 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
376 |
$dbi->execute($CREATE_TABLE->{0}); |
|
377 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
378 |
$where = $dbi->where; |
|
379 |
$where->clause(['and', '{= key2}']); |
|
380 |
$where->param({key2 => 2}); |
|
381 |
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where); |
|
382 |
$result = $dbi->select(table => 'table1'); |
|
added EXPERIMENTAL select pr...
|
383 |
is_deeply($result->all, [{key1 => 3, key2 => 2}], 'update() where'); |
changed argument of tag proc...
|
384 | |
select() where can't receive...
|
385 |
eval{$dbi->update(table => 'table1', param => {';' => 1})}; |
386 |
like($@, qr/safety/); |
|
387 | ||
388 |
eval{$dbi->update(table => 'table1', param => {'key1' => 1}, where => {';' => 1})}; |
|
389 |
like($@, qr/safety/); |
|
390 | ||
added EXPERIMENTAL reserved_...
|
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 => {select => 1}, param => {update => 2}); |
|
398 |
$result = $dbi->execute('select * from "table"'); |
|
added EXPERIMENTAL select pr...
|
399 |
$rows = $result->all; |
added EXPERIMENTAL reserved_...
|
400 |
is_deeply($rows, [{select => 2, update => 6}], "reserved word"); |
401 | ||
402 |
eval {$dbi->update_all(table => 'table', param => {';' => 2}) }; |
|
403 |
like($@, qr/safety/); |
|
404 | ||
405 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
406 |
$dbi->reserved_word_quote('"'); |
|
407 |
$dbi->execute('create table "table" ("select", "update")'); |
|
408 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
|
409 |
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}}); |
|
410 |
$dbi->insert(table => 'table', param => {select => 1}); |
|
411 |
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2}); |
|
412 |
$result = $dbi->execute('select * from "table"'); |
|
added EXPERIMENTAL select pr...
|
413 |
$rows = $result->all; |
added EXPERIMENTAL reserved_...
|
414 |
is_deeply($rows, [{select => 2, update => 6}], "reserved word"); |
415 | ||
- insert, insert_at, update,...
|
416 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
417 |
$dbi->execute($CREATE_TABLE->{1}); |
|
418 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
419 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
420 |
$dbi->update({key2 => 11}, table => 'table1', where => {key1 => 1}); |
|
421 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
added EXPERIMENTAL select pr...
|
422 |
$rows = $result->all; |
- insert, insert_at, update,...
|
423 |
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5}, |
424 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
425 |
"basic"); |
|
426 | ||
removed register_format()
|
427 |
test 'update_all'; |
428 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
429 |
$dbi->execute($CREATE_TABLE->{1}); |
|
430 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
431 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
432 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
433 |
$dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'}); |
|
add tests
|
434 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
added EXPERIMENTAL select pr...
|
435 |
$rows = $result->all; |
removed register_format()
|
436 |
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5}, |
437 |
{key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}], |
|
cleanup
|
438 |
"filter"); |
removed register_format()
|
439 | |
440 | ||
441 |
test 'delete'; |
|
442 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
443 |
$dbi->execute($CREATE_TABLE->{0}); |
|
444 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
445 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
446 |
$dbi->delete(table => 'table1', where => {key1 => 1}); |
|
add tests
|
447 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
added EXPERIMENTAL select pr...
|
448 |
$rows = $result->all; |
cleanup
|
449 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "basic"); |
removed register_format()
|
450 | |
451 |
$dbi->execute("delete from table1;"); |
|
452 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
453 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
454 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
455 |
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'}); |
|
add tests
|
456 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
added EXPERIMENTAL select pr...
|
457 |
$rows = $result->all; |
cleanup
|
458 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter"); |
removed register_format()
|
459 | |
460 |
$dbi->delete(table => 'table1', where => {key1 => 1}, append => ' '); |
|
461 | ||
462 |
$dbi->delete_all(table => 'table1'); |
|
463 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
464 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
465 |
$dbi->delete(table => 'table1', where => {key1 => 1, key2 => 2}); |
|
added EXPERIMENTAL select pr...
|
466 |
$rows = $dbi->select(table => 'table1')->all; |
cleanup
|
467 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "delete multi key"); |
removed register_format()
|
468 | |
changed argument of tag proc...
|
469 |
eval{$dbi->delete(table => 'table1', noexist => 1)}; |
cleanup
|
470 |
like($@, qr/noexist/, "invalid"); |
changed argument of tag proc...
|
471 | |
improved delete() and update...
|
472 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
473 |
$dbi->execute($CREATE_TABLE->{0}); |
|
474 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
475 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
476 |
$where = $dbi->where; |
|
477 |
$where->clause(['and', '{= key1}', '{= key2}']); |
|
478 |
$where->param({ke1 => 1, key2 => 2}); |
|
479 |
$dbi->delete(table => 'table1', where => $where); |
|
480 |
$result = $dbi->select(table => 'table1'); |
|
added EXPERIMENTAL select pr...
|
481 |
is_deeply($result->all, [{key1 => 3, key2 => 4}], 'delete() where'); |
changed argument of tag proc...
|
482 | |
where can recieve array refr...
|
483 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
484 |
$dbi->execute($CREATE_TABLE->{0}); |
|
485 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
486 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
487 |
$dbi->delete( |
|
488 |
table => 'table1', |
|
489 |
where => [ |
|
490 |
['and', '{= key1}', '{= key2}'], |
|
491 |
{ke1 => 1, key2 => 2} |
|
492 |
] |
|
493 |
); |
|
494 |
$result = $dbi->select(table => 'table1'); |
|
added EXPERIMENTAL select pr...
|
495 |
is_deeply($result->all, [{key1 => 3, key2 => 4}], 'delete() where'); |
where can recieve array refr...
|
496 | |
removed register_format()
|
497 |
test 'delete error'; |
498 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
499 |
$dbi->execute($CREATE_TABLE->{0}); |
|
500 |
eval{$dbi->delete(table => 'table1')}; |
|
make delete() using where ob...
|
501 |
like($@, qr/"where" must be specified/, |
cleanup
|
502 |
"where key-value pairs not specified"); |
removed register_format()
|
503 | |
select() where can't receive...
|
504 |
eval{$dbi->delete(table => 'table1', where => {';' => 1})}; |
505 |
like($@, qr/safety/); |
|
506 | ||
added EXPERIMENTAL reserved_...
|
507 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
508 |
$dbi->reserved_word_quote('"'); |
|
509 |
$dbi->execute('create table "table" ("select", "update")'); |
|
510 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
|
511 |
$dbi->insert(table => 'table', param => {select => 1}); |
|
512 |
$dbi->delete(table => 'table', where => {select => 1}); |
|
513 |
$result = $dbi->execute('select * from "table"'); |
|
added EXPERIMENTAL select pr...
|
514 |
$rows = $result->all; |
added EXPERIMENTAL reserved_...
|
515 |
is_deeply($rows, [], "reserved word"); |
516 | ||
removed register_format()
|
517 |
test 'delete_all'; |
518 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
519 |
$dbi->execute($CREATE_TABLE->{0}); |
|
520 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
521 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
522 |
$dbi->delete_all(table => 'table1'); |
|
add tests
|
523 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
added EXPERIMENTAL select pr...
|
524 |
$rows = $result->all; |
cleanup
|
525 |
is_deeply($rows, [], "basic"); |
removed register_format()
|
526 | |
527 | ||
528 |
test 'select'; |
|
529 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
530 |
$dbi->execute($CREATE_TABLE->{0}); |
|
531 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
532 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
added EXPERIMENTAL select pr...
|
533 |
$rows = $dbi->select(table => 'table1')->all; |
removed register_format()
|
534 |
is_deeply($rows, [{key1 => 1, key2 => 2}, |
cleanup
|
535 |
{key1 => 3, key2 => 4}], "table"); |
removed register_format()
|
536 | |
added EXPERIMENTAL select pr...
|
537 |
$rows = $dbi->select(table => 'table1', column => ['key1'])->all; |
cleanup
|
538 |
is_deeply($rows, [{key1 => 1}, {key1 => 3}], "table and columns and where key"); |
removed register_format()
|
539 | |
added EXPERIMENTAL select pr...
|
540 |
$rows = $dbi->select(table => 'table1', where => {key1 => 1})->all; |
cleanup
|
541 |
is_deeply($rows, [{key1 => 1, key2 => 2}], "table and columns and where key"); |
removed register_format()
|
542 | |
added EXPERIMENTAL select pr...
|
543 |
$rows = $dbi->select(table => 'table1', column => ['key1'], where => {key1 => 3})->all; |
cleanup
|
544 |
is_deeply($rows, [{key1 => 3}], "table and columns and where key"); |
removed register_format()
|
545 | |
added EXPERIMENTAL select pr...
|
546 |
$rows = $dbi->select(table => 'table1', append => "order by key1 desc limit 1")->all; |
cleanup
|
547 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "append statement"); |
removed register_format()
|
548 | |
549 |
$dbi->register_filter(decrement => sub { $_[0] - 1 }); |
|
update document
|
550 |
$rows = $dbi->select(table => 'table1', where => {key1 => 2}, filter => {key1 => 'decrement'}) |
added EXPERIMENTAL select pr...
|
551 |
->all; |
cleanup
|
552 |
is_deeply($rows, [{key1 => 1, key2 => 2}], "filter"); |
removed register_format()
|
553 | |
554 |
$dbi->execute($CREATE_TABLE->{2}); |
|
555 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5}); |
|
556 |
$rows = $dbi->select( |
|
557 |
table => [qw/table1 table2/], |
|
select method column option ...
|
558 |
column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3', |
removed register_format()
|
559 |
where => {'table1.key2' => 2}, |
added commit method
|
560 |
relation => {'table1.key1' => 'table2.key1'} |
added EXPERIMENTAL select pr...
|
561 |
)->all; |
cleanup
|
562 |
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "relation : exists where"); |
added commit method
|
563 | |
564 |
$rows = $dbi->select( |
|
565 |
table => [qw/table1 table2/], |
|
566 |
column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'], |
|
567 |
relation => {'table1.key1' => 'table2.key1'} |
|
added EXPERIMENTAL select pr...
|
568 |
)->all; |
cleanup
|
569 |
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "relation : no exists where"); |
removed register_format()
|
570 | |
changed argument of tag proc...
|
571 |
eval{$dbi->select(table => 'table1', noexist => 1)}; |
cleanup
|
572 |
like($@, qr/noexist/, "invalid"); |
changed argument of tag proc...
|
573 | |
added EXPERIMENTAL reserved_...
|
574 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
575 |
$dbi->reserved_word_quote('"'); |
|
576 |
$dbi->execute('create table "table" ("select", "update")'); |
|
577 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
|
578 |
$dbi->insert(table => 'table', param => {select => 1, update => 2}); |
|
579 |
$result = $dbi->select(table => 'table', where => {select => 1}); |
|
added EXPERIMENTAL select pr...
|
580 |
$rows = $result->all; |
added EXPERIMENTAL reserved_...
|
581 |
is_deeply($rows, [{select => 2, update => 2}], "reserved word"); |
changed argument of tag proc...
|
582 | |
removed register_format()
|
583 |
test 'fetch filter'; |
584 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
585 |
$dbi->register_filter( |
|
586 |
twice => sub { $_[0] * 2 }, |
|
587 |
three_times => sub { $_[0] * 3 } |
|
588 |
); |
|
589 |
$dbi->default_fetch_filter('twice'); |
|
590 |
$dbi->execute($CREATE_TABLE->{0}); |
|
591 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
592 |
$result = $dbi->select(table => 'table1'); |
|
593 |
$result->filter({key1 => 'three_times'}); |
|
- added DBIx::Custom::Result...
|
594 |
$row = $result->one; |
cleanup
|
595 |
is_deeply($row, {key1 => 3, key2 => 4}, "default_fetch_filter and filter"); |
removed register_format()
|
596 | |
597 |
test 'filters'; |
|
598 |
$dbi = DBIx::Custom->new; |
|
599 | ||
update document
|
600 |
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')), |
cleanup
|
601 |
'あ', "decode_utf8"); |
removed register_format()
|
602 | |
603 |
is($dbi->filters->{encode_utf8}->('あ'), |
|
cleanup
|
604 |
encode_utf8('あ'), "encode_utf8"); |
removed register_format()
|
605 | |
added commit method
|
606 |
test 'transaction'; |
607 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
608 |
$dbi->execute($CREATE_TABLE->{0}); |
|
removed DBIx::Custom commit ...
|
609 |
$dbi->dbh->begin_work; |
added commit method
|
610 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
611 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3}); |
|
removed DBIx::Custom commit ...
|
612 |
$dbi->dbh->commit; |
added commit method
|
613 |
$result = $dbi->select(table => 'table1'); |
- added DBIx::Custom::Result...
|
614 |
is_deeply(scalar $result->all, [{key1 => 1, key2 => 2}, {key1 => 2, key2 => 3}], |
cleanup
|
615 |
"commit"); |
added commit method
|
616 | |
617 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
618 |
$dbi->execute($CREATE_TABLE->{0}); |
|
removed DBIx::Custom commit ...
|
619 |
$dbi->dbh->begin_work(0); |
added commit method
|
620 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
removed DBIx::Custom commit ...
|
621 |
$dbi->dbh->rollback; |
added commit method
|
622 | |
623 |
$result = $dbi->select(table => 'table1'); |
|
cleanup
|
624 |
ok(! $result->fetch_first, "rollback"); |
add cache attribute
|
625 | |
626 |
test 'cache'; |
|
627 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
removed from cache() and cac...
|
628 |
$dbi->cache(1); |
add cache attribute
|
629 |
$dbi->execute($CREATE_TABLE->{0}); |
renamed build_query to creat...
|
630 |
$source = 'select * from table1 where {= key1} and {= key2};'; |
631 |
$dbi->create_query($source); |
|
632 |
is_deeply($dbi->{_cached}->{$source}, |
|
add table tag
|
633 |
{sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2'], tables => []}, "cache"); |
add cache attribute
|
634 | |
635 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
636 |
$dbi->execute($CREATE_TABLE->{0}); |
|
637 |
$dbi->{_cached} = {}; |
|
638 |
$dbi->cache(0); |
|
639 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
640 |
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache'); |
|
641 | ||
add tests
|
642 |
test 'execute'; |
643 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
644 |
$dbi->execute($CREATE_TABLE->{0}); |
|
removed experimental registe...
|
645 |
{ |
646 |
local $Carp::Verbose = 0; |
|
647 |
eval{$dbi->execute('select * frm table1')}; |
|
cleanup
|
648 |
like($@, qr/\Qselect * frm table1;/, "fail prepare"); |
649 |
like($@, qr/\.t /, "fail : not verbose"); |
|
removed experimental registe...
|
650 |
} |
651 |
{ |
|
652 |
local $Carp::Verbose = 1; |
|
653 |
eval{$dbi->execute('select * frm table1')}; |
|
cleanup
|
654 |
like($@, qr/Custom.*\.t /s, "fail : verbose"); |
removed experimental registe...
|
655 |
} |
add tests
|
656 | |
657 |
eval{$dbi->execute('select * from table1', no_exists => 1)}; |
|
improved error messages
|
658 |
like($@, qr/wrong/, "invald SQL"); |
add tests
|
659 | |
660 |
$query = $dbi->create_query('select * from table1 where {= key1}'); |
|
661 |
$dbi->dbh->disconnect; |
|
662 |
eval{$dbi->execute($query, param => {key1 => {a => 1}})}; |
|
cleanup
|
663 |
ok($@, "execute fail"); |
add tests
|
664 | |
removed experimental registe...
|
665 |
{ |
666 |
local $Carp::Verbose = 0; |
|
667 |
eval{$dbi->create_query('select * from table1 where {0 key1}')}; |
|
cleanup
|
668 |
like($@, qr/\Q.t /, "caller spec : not vebose"); |
removed experimental registe...
|
669 |
} |
670 |
{ |
|
671 |
local $Carp::Verbose = 1; |
|
672 |
eval{$dbi->create_query('select * from table1 where {0 key1}')}; |
|
cleanup
|
673 |
like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose"); |
removed experimental registe...
|
674 |
} |
cleanup
|
675 | |
676 | ||
677 |
test 'transaction'; |
|
678 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
679 |
$dbi->execute($CREATE_TABLE->{0}); |
|
680 | ||
681 |
$dbi->begin_work; |
|
682 | ||
683 |
eval { |
|
684 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
685 |
die "Error"; |
|
686 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
687 |
}; |
|
688 | ||
689 |
$dbi->rollback if $@; |
|
690 | ||
691 |
$result = $dbi->select(table => 'table1'); |
|
added EXPERIMENTAL select pr...
|
692 |
$rows = $result->all; |
cleanup
|
693 |
is_deeply($rows, [], "rollback"); |
cleanup
|
694 | |
695 |
$dbi->begin_work; |
|
696 | ||
697 |
eval { |
|
698 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
699 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
700 |
}; |
|
701 | ||
702 |
$dbi->commit unless $@; |
|
703 | ||
704 |
$result = $dbi->select(table => 'table1'); |
|
added EXPERIMENTAL select pr...
|
705 |
$rows = $result->all; |
cleanup
|
706 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "commit"); |
cleanup
|
707 | |
708 |
$dbi->dbh->{AutoCommit} = 0; |
|
709 |
eval{ $dbi->begin_work }; |
|
cleanup
|
710 |
ok($@, "exception"); |
cleanup
|
711 |
$dbi->dbh->{AutoCommit} = 1; |
712 | ||
added helper method
|
713 | |
renamed helper to method.
|
714 |
test 'method'; |
added helper method
|
715 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
renamed helper to method.
|
716 |
$dbi->method( |
added helper method
|
717 |
one => sub { 1 } |
718 |
); |
|
renamed helper to method.
|
719 |
$dbi->method( |
added helper method
|
720 |
two => sub { 2 } |
721 |
); |
|
renamed helper to method.
|
722 |
$dbi->method({ |
added helper method
|
723 |
twice => sub { |
724 |
my $self = shift; |
|
725 |
return $_[0] * 2; |
|
726 |
} |
|
727 |
}); |
|
728 | ||
cleanup
|
729 |
is($dbi->one, 1, "first"); |
730 |
is($dbi->two, 2, "second"); |
|
731 |
is($dbi->twice(5), 10 , "second"); |
|
added helper method
|
732 | |
733 |
eval {$dbi->XXXXXX}; |
|
autoload DBI method
|
734 |
ok($@, "not exists"); |
added helper method
|
735 | |
renamed auto_filter to apply...
|
736 |
test 'out filter'; |
added auto_filter method
|
737 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
738 |
$dbi->execute($CREATE_TABLE->{0}); |
|
739 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
740 |
$dbi->register_filter(three_times => sub { $_[0] * 3}); |
|
renamed auto_filter to apply...
|
741 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
742 |
'table1', 'key1' => {out => 'twice', in => 'three_times'}, |
743 |
'key2' => {out => 'three_times', in => 'twice'}); |
|
added auto_filter method
|
744 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
745 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
746 |
$row = $result->fetch_hash_first; |
|
cleanup
|
747 |
is_deeply($row, {key1 => 2, key2 => 6}, "insert"); |
renamed auto_filter to apply...
|
748 |
$result = $dbi->select(table => 'table1'); |
added tests
|
749 |
$row = $result->one; |
cleanup
|
750 |
is_deeply($row, {key1 => 6, key2 => 12}, "insert"); |
added auto_filter method
|
751 | |
fix bug : filter can't over...
|
752 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
753 |
$dbi->execute($CREATE_TABLE->{0}); |
|
754 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
755 |
$dbi->register_filter(three_times => sub { $_[0] * 3}); |
|
756 |
$dbi->apply_filter( |
|
757 |
'table1', 'key1' => {out => 'twice', in => 'three_times'}, |
|
758 |
'key2' => {out => 'three_times', in => 'twice'}); |
|
759 |
$dbi->apply_filter( |
|
760 |
'table1', 'key1' => {out => undef} |
|
761 |
); |
|
762 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
763 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
added tests
|
764 |
$row = $result->one; |
fix bug : filter can't over...
|
765 |
is_deeply($row, {key1 => 1, key2 => 6}, "insert"); |
766 | ||
added auto_filter method
|
767 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
768 |
$dbi->execute($CREATE_TABLE->{0}); |
|
769 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
renamed auto_filter to apply...
|
770 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
771 |
'table1', 'key1' => {out => 'twice', in => 'twice'} |
added auto_filter method
|
772 |
); |
renamed auto_filter to apply...
|
773 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => undef}); |
added auto_filter method
|
774 |
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2}); |
775 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
added tests
|
776 |
$row = $result->one; |
cleanup
|
777 |
is_deeply($row, {key1 => 4, key2 => 2}, "update"); |
added auto_filter method
|
778 | |
779 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
780 |
$dbi->execute($CREATE_TABLE->{0}); |
|
781 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
renamed auto_filter to apply...
|
782 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
783 |
'table1', 'key1' => {out => 'twice', in => 'twice'} |
added auto_filter method
|
784 |
); |
renamed auto_filter to apply...
|
785 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1=> undef}); |
added auto_filter method
|
786 |
$dbi->delete(table => 'table1', where => {key1 => 1}); |
787 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
|
added EXPERIMENTAL select pr...
|
788 |
$rows = $result->all; |
cleanup
|
789 |
is_deeply($rows, [], "delete"); |
added auto_filter method
|
790 | |
791 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
792 |
$dbi->execute($CREATE_TABLE->{0}); |
|
793 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
renamed auto_filter to apply...
|
794 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
795 |
'table1', 'key1' => {out => 'twice', in => 'twice'} |
added auto_filter method
|
796 |
); |
renamed auto_filter to apply...
|
797 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef}); |
added auto_filter method
|
798 |
$result = $dbi->select(table => 'table1', where => {key1 => 1}); |
799 |
$result->filter({'key2' => 'twice'}); |
|
added EXPERIMENTAL select pr...
|
800 |
$rows = $result->all; |
cleanup
|
801 |
is_deeply($rows, [{key1 => 4, key2 => 4}], "select"); |
added auto_filter method
|
802 | |
803 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
804 |
$dbi->execute($CREATE_TABLE->{0}); |
|
805 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
renamed auto_filter to apply...
|
806 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
807 |
'table1', 'key1' => {out => 'twice', in => 'twice'} |
added auto_filter method
|
808 |
); |
renamed auto_filter to apply...
|
809 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef}); |
added auto_filter method
|
810 |
$result = $dbi->execute("select * from table1 where {= key1} and {= key2};", |
811 |
param => {key1 => 1, key2 => 2}, |
|
renamed auto_filter to apply...
|
812 |
table => ['table1']); |
added EXPERIMENTAL select pr...
|
813 |
$rows = $result->all; |
cleanup
|
814 |
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute"); |
added auto_filter method
|
815 | |
add table tag
|
816 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
817 |
$dbi->execute($CREATE_TABLE->{0}); |
|
818 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
819 |
$dbi->apply_filter( |
|
820 |
'table1', 'key1' => {out => 'twice', in => 'twice'} |
|
821 |
); |
|
822 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef}); |
|
823 |
$result = $dbi->execute("select * from {table table1} where {= key1} and {= key2};", |
|
824 |
param => {key1 => 1, key2 => 2}); |
|
added EXPERIMENTAL select pr...
|
825 |
$rows = $result->all; |
add table tag
|
826 |
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute table tag"); |
827 | ||
added auto_filter method
|
828 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
829 |
$dbi->execute($CREATE_TABLE->{0}); |
|
830 |
$dbi->execute($CREATE_TABLE->{2}); |
|
831 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
832 |
$dbi->register_filter(three_times => sub { $_[0] * 3 }); |
|
renamed auto_filter to apply...
|
833 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
834 |
'table1', 'key2' => {out => 'twice', in => 'twice'} |
added auto_filter method
|
835 |
); |
renamed auto_filter to apply...
|
836 |
$dbi->apply_filter( |
renamed auto_filter to apply...
|
837 |
'table2', 'key3' => {out => 'three_times', in => 'three_times'} |
added auto_filter method
|
838 |
); |
renamed auto_filter to apply...
|
839 |
$dbi->insert(table => 'table1', param => {key1 => 5, key2 => 2}, filter => {key2 => undef}); |
840 |
$dbi->insert(table => 'table2', param => {key1 => 5, key3 => 6}, filter => {key3 => undef}); |
|
added auto_filter method
|
841 |
$result = $dbi->select( |
842 |
table => ['table1', 'table2'], |
|
843 |
column => ['key2', 'key3'], |
|
844 |
where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'}); |
|
845 | ||
846 |
$result->filter({'key2' => 'twice'}); |
|
added EXPERIMENTAL select pr...
|
847 |
$rows = $result->all; |
cleanup
|
848 |
is_deeply($rows, [{key2 => 4, key3 => 18}], "select : join"); |
added auto_filter method
|
849 | |
850 |
$result = $dbi->select( |
|
851 |
table => ['table1', 'table2'], |
|
852 |
column => ['key2', 'key3'], |
|
853 |
where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'}); |
|
854 | ||
855 |
$result->filter({'key2' => 'twice'}); |
|
added EXPERIMENTAL select pr...
|
856 |
$rows = $result->all; |
cleanup
|
857 |
is_deeply($rows, [{key2 => 4, key3 => 18}], "select : join : omit"); |
added auto_filter method
|
858 | |
pod fix
|
859 |
test 'each_column'; |
added experimental iterate_a...
|
860 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
861 |
$dbi->execute($CREATE_TABLE->{2}); |
|
862 |
$dbi->execute($CREATE_TABLE->{3}); |
|
863 | ||
864 |
$infos = []; |
|
pod fix
|
865 |
$dbi->each_column(sub { |
removed experimental txn_sco...
|
866 |
my ($self, $table, $column, $cinfo) = @_; |
added experimental iterate_a...
|
867 |
|
868 |
if ($table =~ /^table/) { |
|
869 |
my $info = [$table, $column, $cinfo->{COLUMN_NAME}]; |
|
870 |
push @$infos, $info; |
|
871 |
} |
|
872 |
}); |
|
873 |
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos]; |
|
874 |
is_deeply($infos, |
|
875 |
[ |
|
876 |
['table1', 'key1', 'key1'], |
|
877 |
['table1', 'key2', 'key2'], |
|
878 |
['table2', 'key1', 'key1'], |
|
879 |
['table2', 'key3', 'key3'] |
|
880 |
] |
|
cleanup
|
881 |
|
added experimental iterate_a...
|
882 |
); |
added auto_filter method
|
883 | |
add examples
|
884 |
test 'limit'; |
885 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
886 |
$dbi->execute($CREATE_TABLE->{0}); |
|
887 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
888 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4}); |
|
889 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6}); |
|
renamed DBIx::Custom::TagPro...
|
890 |
$dbi->register_tag( |
add examples
|
891 |
limit => sub { |
892 |
my ($count, $offset) = @_; |
|
893 |
|
|
894 |
my $s = ''; |
|
895 |
$s .= "limit $count"; |
|
896 |
$s .= " offset $offset" if defined $offset; |
|
897 |
|
|
898 |
return [$s, []]; |
|
899 |
} |
|
900 |
); |
|
901 |
$rows = $dbi->select( |
|
902 |
table => 'table1', |
|
903 |
where => {key1 => 1}, |
|
904 |
append => "order by key2 {limit 1 0}" |
|
added EXPERIMENTAL select pr...
|
905 |
)->all; |
cleanup
|
906 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
add examples
|
907 |
$rows = $dbi->select( |
908 |
table => 'table1', |
|
909 |
where => {key1 => 1}, |
|
910 |
append => "order by key2 {limit 2 1}" |
|
added EXPERIMENTAL select pr...
|
911 |
)->all; |
cleanup
|
912 |
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]); |
add examples
|
913 |
$rows = $dbi->select( |
914 |
table => 'table1', |
|
915 |
where => {key1 => 1}, |
|
916 |
append => "order by key2 {limit 1}" |
|
added EXPERIMENTAL select pr...
|
917 |
)->all; |
cleanup
|
918 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
added insert, update, update...
|
919 | |
remove DBIx::Custom::Model
|
920 |
test 'connect super'; |
921 |
{ |
|
922 |
package MyDBI; |
|
923 |
|
|
924 |
use base 'DBIx::Custom'; |
|
925 |
sub connect { |
|
926 |
my $self = shift->SUPER::connect(@_); |
|
927 |
|
|
928 |
return $self; |
|
929 |
} |
|
930 |
|
|
931 |
sub new { |
|
cleanup
|
932 |
my $self = shift->SUPER::new(@_); |
remove DBIx::Custom::Model
|
933 |
|
934 |
return $self; |
|
935 |
} |
|
936 |
} |
|
937 | ||
938 |
$dbi = MyDBI->connect($NEW_ARGS->{0}); |
|
939 |
$dbi->execute($CREATE_TABLE->{0}); |
|
940 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
added tests
|
941 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
remove DBIx::Custom::Model
|
942 | |
943 |
$dbi = MyDBI->new($NEW_ARGS->{0}); |
|
cleanup
|
944 |
$dbi->connect; |
remove DBIx::Custom::Model
|
945 |
$dbi->execute($CREATE_TABLE->{0}); |
946 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
added tests
|
947 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
added experimental DBIx::Cus...
|
948 | |
cleanup
|
949 |
{ |
950 |
package MyDBI2; |
|
951 |
|
|
952 |
use base 'DBIx::Custom'; |
|
953 |
sub connect { |
|
954 |
my $self = shift->SUPER::new(@_); |
|
955 |
$self->connect; |
|
956 |
|
|
957 |
return $self; |
|
958 |
} |
|
959 |
} |
|
960 | ||
961 |
$dbi = MyDBI->connect($NEW_ARGS->{0}); |
|
962 |
$dbi->execute($CREATE_TABLE->{0}); |
|
963 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
added tests
|
964 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
added experimental DBIx::Cus...
|
965 | |
966 |
test 'end_filter'; |
|
967 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
968 |
$dbi->execute($CREATE_TABLE->{0}); |
|
969 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
970 |
$result = $dbi->select(table => 'table1'); |
|
971 |
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 }); |
|
972 |
$result->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 }); |
|
973 |
$row = $result->fetch_first; |
|
974 |
is_deeply($row, [6, 40]); |
|
975 | ||
all filter can receive array...
|
976 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
977 |
$dbi->execute($CREATE_TABLE->{0}); |
|
978 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
979 |
$result = $dbi->select(table => 'table1'); |
|
980 |
$result->filter([qw/key1 key2/] => sub { $_[0] * 2 }); |
|
981 |
$result->end_filter([[qw/key1 key2/] => sub { $_[0] * 3 }]); |
|
982 |
$row = $result->fetch_first; |
|
983 |
is_deeply($row, [6, 12]); |
|
984 | ||
985 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
986 |
$dbi->execute($CREATE_TABLE->{0}); |
|
987 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
988 |
$result = $dbi->select(table => 'table1'); |
|
989 |
$result->filter([[qw/key1 key2/] => sub { $_[0] * 2 }]); |
|
990 |
$result->end_filter([qw/key1 key2/] => sub { $_[0] * 3 }); |
|
991 |
$row = $result->fetch_first; |
|
992 |
is_deeply($row, [6, 12]); |
|
993 | ||
many changed
|
994 |
$dbi->register_filter(five_times => sub { $_[0] * 5 }); |
added experimental DBIx::Cus...
|
995 |
$result = $dbi->select(table => 'table1'); |
996 |
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 }); |
|
many changed
|
997 |
$result->end_filter({key1 => sub { $_[0] * 3 }, key2 => 'five_times' }); |
added tests
|
998 |
$row = $result->one; |
added experimental DBIx::Cus...
|
999 |
is_deeply($row, {key1 => 6, key2 => 40}); |
fix select method empty wher...
|
1000 | |
fix bug : filter can't over...
|
1001 |
$dbi->register_filter(five_times => sub { $_[0] * 5 }); |
1002 |
$dbi->apply_filter('table1', |
|
1003 |
key1 => {end => sub { $_[0] * 3 } }, |
|
1004 |
key2 => {end => 'five_times'} |
|
1005 |
); |
|
1006 |
$result = $dbi->select(table => 'table1'); |
|
1007 |
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 }); |
|
added tests
|
1008 |
$row = $result->one; |
fix bug : filter can't over...
|
1009 |
is_deeply($row, {key1 => 6, key2 => 40}, 'apply_filter'); |
1010 | ||
1011 |
$dbi->register_filter(five_times => sub { $_[0] * 5 }); |
|
1012 |
$dbi->apply_filter('table1', |
|
1013 |
key1 => {end => sub { $_[0] * 3 } }, |
|
1014 |
key2 => {end => 'five_times'} |
|
1015 |
); |
|
1016 |
$result = $dbi->select(table => 'table1'); |
|
1017 |
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 }); |
|
1018 |
$result->filter(key1 => undef); |
|
1019 |
$result->end_filter(key1 => undef); |
|
added tests
|
1020 |
$row = $result->one; |
fix bug : filter can't over...
|
1021 |
is_deeply($row, {key1 => 1, key2 => 40}, 'apply_filter overwrite'); |
fix select method empty wher...
|
1022 | |
added experimental DBIx::Cus...
|
1023 |
test 'remove_end_filter and remove_filter'; |
added experimental DBIx::Cus...
|
1024 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
1025 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1026 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1027 |
$result = $dbi->select(table => 'table1'); |
|
added experimental DBIx::Cus...
|
1028 |
$row = $result |
1029 |
->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 }) |
|
1030 |
->remove_filter |
|
1031 |
->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 }) |
|
added experimental DBIx::Cus...
|
1032 |
->remove_end_filter |
1033 |
->fetch_first; |
|
added experimental DBIx::Cus...
|
1034 |
is_deeply($row, [1, 2]); |
added experimental DBIx::Cus...
|
1035 | |
fix select method empty wher...
|
1036 |
test 'empty where select'; |
1037 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1038 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1039 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1040 |
$result = $dbi->select(table => 'table1', where => {}); |
|
added tests
|
1041 |
$row = $result->one; |
fix select method empty wher...
|
1042 |
is_deeply($row, {key1 => 1, key2 => 2}); |
1043 | ||
added experimental sugar met...
|
1044 |
test 'select query option'; |
1045 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1046 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1047 |
$query = $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, query => 1); |
|
1048 |
is(ref $query, 'DBIx::Custom::Query'); |
|
1049 |
$query = $dbi->update(table => 'table1', where => {key1 => 1}, param => {key2 => 2}, query => 1); |
|
1050 |
is(ref $query, 'DBIx::Custom::Query'); |
|
1051 |
$query = $dbi->delete(table => 'table1', where => {key1 => 1}, query => 1); |
|
1052 |
is(ref $query, 'DBIx::Custom::Query'); |
|
1053 |
$query = $dbi->select(table => 'table1', where => {key1 => 1, key2 => 2}, query => 1); |
|
1054 |
is(ref $query, 'DBIx::Custom::Query'); |
|
1055 | ||
added experimental DBIx::Cus...
|
1056 |
test 'DBIx::Custom::Where'; |
experimental extended select...
|
1057 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
1058 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1059 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1060 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
renamed DBIx::Custom::TagPro...
|
1061 |
$where = $dbi->where->clause(['and', '{= key1}', '{= key2}']); |
1062 |
is("$where", "where ( {= key1} and {= key2} )", 'no param'); |
|
1063 | ||
added experimental DBIx::Cus...
|
1064 |
$where = $dbi->where |
added test
|
1065 |
->clause(['and', '{= key1}', '{= key2}']) |
added experimental DBIx::Cus...
|
1066 |
->param({key1 => 1}); |
added test
|
1067 | |
experimental extended select...
|
1068 |
$result = $dbi->select( |
1069 |
table => 'table1', |
|
added experimental DBIx::Cus...
|
1070 |
where => $where |
experimental extended select...
|
1071 |
); |
added EXPERIMENTAL select pr...
|
1072 |
$row = $result->all; |
experimental extended select...
|
1073 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
1074 | ||
where can recieve array refr...
|
1075 |
$result = $dbi->select( |
1076 |
table => 'table1', |
|
1077 |
where => [ |
|
1078 |
['and', '{= key1}', '{= key2}'], |
|
1079 |
{key1 => 1} |
|
1080 |
] |
|
1081 |
); |
|
added EXPERIMENTAL select pr...
|
1082 |
$row = $result->all; |
where can recieve array refr...
|
1083 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
1084 | ||
added experimental DBIx::Cus...
|
1085 |
$where = $dbi->where |
added test
|
1086 |
->clause(['and', '{= key1}', '{= key2}']) |
added experimental DBIx::Cus...
|
1087 |
->param({key1 => 1, key2 => 2}); |
experimental extended select...
|
1088 |
$result = $dbi->select( |
1089 |
table => 'table1', |
|
added experimental DBIx::Cus...
|
1090 |
where => $where |
experimental extended select...
|
1091 |
); |
added EXPERIMENTAL select pr...
|
1092 |
$row = $result->all; |
experimental extended select...
|
1093 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
1094 | ||
added experimental DBIx::Cus...
|
1095 |
$where = $dbi->where |
added test
|
1096 |
->clause(['and', '{= key1}', '{= key2}']) |
added experimental DBIx::Cus...
|
1097 |
->param({}); |
experimental extended select...
|
1098 |
$result = $dbi->select( |
1099 |
table => 'table1', |
|
added experimental DBIx::Cus...
|
1100 |
where => $where, |
experimental extended select...
|
1101 |
); |
added EXPERIMENTAL select pr...
|
1102 |
$row = $result->all; |
experimental extended select...
|
1103 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]); |
1104 | ||
added experimental DBIx::Cus...
|
1105 |
$where = $dbi->where |
updated pod
|
1106 |
->clause(['and', ['or', 'key1 > :key1', 'key1 < :key1'], 'key2 = :key2']) |
added experimental DBIx::Cus...
|
1107 |
->param({key1 => [0, 3], key2 => 2}); |
experimental extended select...
|
1108 |
$result = $dbi->select( |
1109 |
table => 'table1', |
|
added experimental DBIx::Cus...
|
1110 |
where => $where, |
added experimental not_exist...
|
1111 |
); |
added EXPERIMENTAL select pr...
|
1112 |
$row = $result->all; |
experimental extended select...
|
1113 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
1114 | ||
added experimental DBIx::Cus...
|
1115 |
$where = $dbi->where; |
1116 |
$result = $dbi->select( |
|
1117 |
table => 'table1', |
|
1118 |
where => $where |
|
1119 |
); |
|
added EXPERIMENTAL select pr...
|
1120 |
$row = $result->all; |
added experimental DBIx::Cus...
|
1121 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]); |
1122 | ||
experimental extended select...
|
1123 |
eval { |
added experimental DBIx::Cus...
|
1124 |
$where = $dbi->where |
added test
|
1125 |
->clause(['uuu']); |
experimental extended select...
|
1126 |
$result = $dbi->select( |
1127 |
table => 'table1', |
|
added experimental DBIx::Cus...
|
1128 |
where => $where |
experimental extended select...
|
1129 |
); |
1130 |
}; |
|
1131 |
ok($@); |
|
1132 | ||
added experimental DBIx::Cus...
|
1133 |
$where = $dbi->where; |
1134 |
is("$where", ''); |
|
1135 | ||
added test
|
1136 |
$where = $dbi->where |
1137 |
->clause(['or', ('{= key1}') x 2]) |
|
1138 |
->param({key1 => [1, 3]}); |
|
1139 |
$result = $dbi->select( |
|
1140 |
table => 'table1', |
|
1141 |
where => $where, |
|
1142 |
); |
|
added EXPERIMENTAL select pr...
|
1143 |
$row = $result->all; |
added test
|
1144 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]); |
1145 | ||
1146 |
$where = $dbi->where |
|
1147 |
->clause(['or', ('{= key1}') x 2]) |
|
1148 |
->param({key1 => [1]}); |
|
1149 |
$result = $dbi->select( |
|
1150 |
table => 'table1', |
|
1151 |
where => $where, |
|
1152 |
); |
|
added EXPERIMENTAL select pr...
|
1153 |
$row = $result->all; |
added test
|
1154 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
1155 | ||
1156 |
$where = $dbi->where |
|
1157 |
->clause(['or', ('{= key1}') x 2]) |
|
1158 |
->param({key1 => 1}); |
|
1159 |
$result = $dbi->select( |
|
1160 |
table => 'table1', |
|
1161 |
where => $where, |
|
1162 |
); |
|
added EXPERIMENTAL select pr...
|
1163 |
$row = $result->all; |
added test
|
1164 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
added experimental DBIx::Cus...
|
1165 | |
many changed
|
1166 |
$where = $dbi->where |
1167 |
->clause('{= key1}') |
|
1168 |
->param({key1 => 1}); |
|
1169 |
$result = $dbi->select( |
|
1170 |
table => 'table1', |
|
1171 |
where => $where, |
|
1172 |
); |
|
added EXPERIMENTAL select pr...
|
1173 |
$row = $result->all; |
many changed
|
1174 |
is_deeply($row, [{key1 => 1, key2 => 2}]); |
1175 | ||
1176 |
$where = $dbi->where |
|
1177 |
->clause('{= key1} {= key2}') |
|
1178 |
->param({key1 => 1}); |
|
1179 |
eval{$where->to_string}; |
|
1180 |
like($@, qr/one column/); |
|
1181 | ||
added experimental not_exist...
|
1182 |
$where = $dbi->where |
1183 |
->clause('{= key1}') |
|
1184 |
->param([]); |
|
1185 |
eval{$where->to_string}; |
|
1186 |
like($@, qr/Parameter/); |
|
1187 | ||
1188 |
$where = $dbi->where |
|
1189 |
->clause(['or', ('{= key1}') x 3]) |
|
1190 |
->param({key1 => [$dbi->not_exists, 1, 3]}); |
|
1191 |
$result = $dbi->select( |
|
1192 |
table => 'table1', |
|
1193 |
where => $where, |
|
1194 |
); |
|
added EXPERIMENTAL select pr...
|
1195 |
$row = $result->all; |
added experimental not_exist...
|
1196 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists'); |
1197 | ||
1198 |
$where = $dbi->where |
|
1199 |
->clause(['or', ('{= key1}') x 3]) |
|
1200 |
->param({key1 => [1, $dbi->not_exists, 3]}); |
|
1201 |
$result = $dbi->select( |
|
1202 |
table => 'table1', |
|
1203 |
where => $where, |
|
1204 |
); |
|
added EXPERIMENTAL select pr...
|
1205 |
$row = $result->all; |
added experimental not_exist...
|
1206 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists'); |
1207 | ||
1208 |
$where = $dbi->where |
|
1209 |
->clause(['or', ('{= key1}') x 3]) |
|
1210 |
->param({key1 => [1, 3, $dbi->not_exists]}); |
|
1211 |
$result = $dbi->select( |
|
1212 |
table => 'table1', |
|
1213 |
where => $where, |
|
1214 |
); |
|
added EXPERIMENTAL select pr...
|
1215 |
$row = $result->all; |
added experimental not_exist...
|
1216 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists'); |
1217 | ||
1218 |
$where = $dbi->where |
|
1219 |
->clause(['or', ('{= key1}') x 3]) |
|
1220 |
->param({key1 => [1, $dbi->not_exists, $dbi->not_exists]}); |
|
1221 |
$result = $dbi->select( |
|
1222 |
table => 'table1', |
|
1223 |
where => $where, |
|
1224 |
); |
|
added EXPERIMENTAL select pr...
|
1225 |
$row = $result->all; |
added experimental not_exist...
|
1226 |
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists'); |
1227 | ||
1228 |
$where = $dbi->where |
|
1229 |
->clause(['or', ('{= key1}') x 3]) |
|
1230 |
->param({key1 => [$dbi->not_exists, 1, $dbi->not_exists]}); |
|
1231 |
$result = $dbi->select( |
|
1232 |
table => 'table1', |
|
1233 |
where => $where, |
|
1234 |
); |
|
added EXPERIMENTAL select pr...
|
1235 |
$row = $result->all; |
added experimental not_exist...
|
1236 |
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists'); |
1237 | ||
1238 |
$where = $dbi->where |
|
1239 |
->clause(['or', ('{= key1}') x 3]) |
|
1240 |
->param({key1 => [$dbi->not_exists, $dbi->not_exists, 1]}); |
|
1241 |
$result = $dbi->select( |
|
1242 |
table => 'table1', |
|
1243 |
where => $where, |
|
1244 |
); |
|
added EXPERIMENTAL select pr...
|
1245 |
$row = $result->all; |
added experimental not_exist...
|
1246 |
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists'); |
1247 | ||
1248 |
$where = $dbi->where |
|
1249 |
->clause(['or', ('{= key1}') x 3]) |
|
1250 |
->param({key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]}); |
|
1251 |
$result = $dbi->select( |
|
1252 |
table => 'table1', |
|
1253 |
where => $where, |
|
1254 |
); |
|
added EXPERIMENTAL select pr...
|
1255 |
$row = $result->all; |
added experimental not_exist...
|
1256 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists'); |
1257 | ||
make delete() using where ob...
|
1258 |
$where = $dbi->where |
1259 |
->clause(['or', ('{= key1}') x 3]) |
|
1260 |
->param({key1 => []}); |
|
1261 |
$result = $dbi->select( |
|
1262 |
table => 'table1', |
|
1263 |
where => $where, |
|
1264 |
); |
|
added EXPERIMENTAL select pr...
|
1265 |
$row = $result->all; |
make delete() using where ob...
|
1266 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists'); |
1267 | ||
1268 |
$where = $dbi->where |
|
1269 |
->clause(['and', '{> key1}', '{< key1}' ]) |
|
1270 |
->param({key1 => [2, $dbi->not_exists]}); |
|
1271 |
$result = $dbi->select( |
|
1272 |
table => 'table1', |
|
1273 |
where => $where, |
|
1274 |
); |
|
added EXPERIMENTAL select pr...
|
1275 |
$row = $result->all; |
make delete() using where ob...
|
1276 |
is_deeply($row, [{key1 => 3, key2 => 4}], 'not_exists'); |
1277 | ||
1278 |
$where = $dbi->where |
|
1279 |
->clause(['and', '{> key1}', '{< key1}' ]) |
|
1280 |
->param({key1 => [$dbi->not_exists, 2]}); |
|
1281 |
$result = $dbi->select( |
|
1282 |
table => 'table1', |
|
1283 |
where => $where, |
|
1284 |
); |
|
added EXPERIMENTAL select pr...
|
1285 |
$row = $result->all; |
make delete() using where ob...
|
1286 |
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists'); |
1287 | ||
1288 |
$where = $dbi->where |
|
1289 |
->clause(['and', '{> key1}', '{< key1}' ]) |
|
1290 |
->param({key1 => [$dbi->not_exists, $dbi->not_exists]}); |
|
1291 |
$result = $dbi->select( |
|
1292 |
table => 'table1', |
|
1293 |
where => $where, |
|
1294 |
); |
|
added EXPERIMENTAL select pr...
|
1295 |
$row = $result->all; |
make delete() using where ob...
|
1296 |
is_deeply($row, [{key1 => 1, key2 => 2},{key1 => 3, key2 => 4}], 'not_exists'); |
1297 | ||
1298 |
$where = $dbi->where |
|
1299 |
->clause(['and', '{> key1}', '{< key1}' ]) |
|
1300 |
->param({key1 => [0, 2]}); |
|
1301 |
$result = $dbi->select( |
|
1302 |
table => 'table1', |
|
1303 |
where => $where, |
|
1304 |
); |
|
added EXPERIMENTAL select pr...
|
1305 |
$row = $result->all; |
make delete() using where ob...
|
1306 |
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists'); |
1307 | ||
DBIx::Custom::Where clause a...
|
1308 |
$where = $dbi->where |
1309 |
->clause(['and', 'key1 is not null', 'key2 is not null' ]); |
|
1310 |
$result = $dbi->select( |
|
1311 |
table => 'table1', |
|
1312 |
where => $where, |
|
1313 |
); |
|
added EXPERIMENTAL select pr...
|
1314 |
$row = $result->all; |
DBIx::Custom::Where clause a...
|
1315 |
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists'); |
1316 | ||
improved error messages
|
1317 |
eval {$dbi->where(ppp => 1) }; |
1318 |
like($@, qr/invalid/); |
|
1319 | ||
renamed dbi_options to dbi_o...
|
1320 |
test 'dbi_option default'; |
added experimental DBIx::Cus...
|
1321 |
$dbi = DBIx::Custom->new; |
renamed dbi_options to dbi_o...
|
1322 |
is_deeply($dbi->dbi_option, {}); |
added experimental DBIx::Cus...
|
1323 | |
added register_tag_processor
|
1324 |
test 'register_tag_processor'; |
1325 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1326 |
$dbi->register_tag_processor( |
|
1327 |
a => sub { 1 } |
|
1328 |
); |
|
1329 |
is($dbi->query_builder->tag_processors->{a}->(), 1); |
|
added experimental DBIx::Cus...
|
1330 | |
renamed DBIx::Custom::TagPro...
|
1331 |
test 'register_tag'; |
1332 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1333 |
$dbi->register_tag( |
|
1334 |
b => sub { 2 } |
|
1335 |
); |
|
1336 |
is($dbi->query_builder->tags->{b}->(), 2); |
|
1337 | ||
added table not specified ex...
|
1338 |
test 'table not specify exception'; |
1339 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1340 |
eval {$dbi->insert}; |
|
1341 |
like($@, qr/table/); |
|
1342 |
eval {$dbi->update}; |
|
1343 |
like($@, qr/table/); |
|
1344 |
eval {$dbi->delete}; |
|
1345 |
like($@, qr/table/); |
|
1346 |
eval {$dbi->select}; |
|
1347 |
like($@, qr/table/); |
|
many changed
|
1348 | |
1349 | ||
1350 |
test 'more tests'; |
|
1351 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1352 |
eval{$dbi->apply_filter('table', 'column', [])}; |
|
1353 |
like($@, qr/apply_filter/); |
|
1354 | ||
1355 |
eval{$dbi->apply_filter('table', 'column', {outer => 2})}; |
|
1356 |
like($@, qr/apply_filter/); |
|
1357 | ||
1358 |
$dbi->apply_filter( |
|
1359 | ||
1360 |
); |
|
1361 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1362 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1363 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1364 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
1365 |
$dbi->apply_filter('table1', 'key2', |
|
1366 |
{in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }}); |
|
added EXPERIMENTAL select pr...
|
1367 |
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->all; |
many changed
|
1368 |
is_deeply($rows, [{key1 => 1, key2 => 6}]); |
1369 | ||
1370 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1371 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1372 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1373 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
1374 |
$dbi->apply_filter('table1', 'key2', {}); |
|
added EXPERIMENTAL select pr...
|
1375 |
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->all; |
many changed
|
1376 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
1377 | ||
1378 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1379 |
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})}; |
|
1380 |
like($@, qr/not registered/); |
|
1381 |
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})}; |
|
1382 |
like($@, qr/not registered/); |
|
renamed helper to method.
|
1383 |
$dbi->method({one => sub { 1 }}); |
many changed
|
1384 |
is($dbi->one, 1); |
1385 | ||
1386 |
eval{DBIx::Custom->connect()}; |
|
cleanup
|
1387 |
like($@, qr/_connect/); |
many changed
|
1388 | |
1389 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1390 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1391 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
|
1392 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, |
|
1393 |
filter => {key1 => 'twice'}); |
|
added tests
|
1394 |
$row = $dbi->select(table => 'table1')->one; |
many changed
|
1395 |
is_deeply($row, {key1 => 2, key2 => 2}); |
1396 |
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, |
|
1397 |
filter => {key1 => 'no'}) }; |
|
1398 |
like($@, qr//); |
|
1399 | ||
1400 |
$dbi->register_filter(one => sub { }); |
|
1401 |
$dbi->default_fetch_filter('one'); |
|
1402 |
ok($dbi->default_fetch_filter); |
|
1403 |
$dbi->default_bind_filter('one'); |
|
1404 |
ok($dbi->default_bind_filter); |
|
1405 |
eval{$dbi->default_fetch_filter('no')}; |
|
1406 |
like($@, qr/not registered/); |
|
1407 |
eval{$dbi->default_bind_filter('no')}; |
|
1408 |
like($@, qr/not registered/); |
|
1409 |
$dbi->default_bind_filter(undef); |
|
1410 |
ok(!defined $dbi->default_bind_filter); |
|
1411 |
$dbi->default_fetch_filter(undef); |
|
1412 |
ok(!defined $dbi->default_fetch_filter); |
|
- update_param_tag is DEPREC...
|
1413 |
eval {$dbi->execute('select * from table1 {} {= author') }; |
many changed
|
1414 |
like($@, qr/Tag not finished/); |
1415 | ||
1416 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1417 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1418 |
$dbi->register_filter(one => sub { 1 }); |
|
1419 |
$result = $dbi->select(table => 'table1'); |
|
1420 |
eval {$result->filter(key1 => 'no')}; |
|
1421 |
like($@, qr/not registered/); |
|
1422 |
eval {$result->end_filter(key1 => 'no')}; |
|
1423 |
like($@, qr/not registered/); |
|
1424 |
$result->default_filter(undef); |
|
1425 |
ok(!defined $result->default_filter); |
|
1426 |
$result->default_filter('one'); |
|
1427 |
is($result->default_filter->(), 1); |
|
1428 | ||
renamed dbi_options to dbi_o...
|
1429 |
test 'dbi_option'; |
data_source is DEPRECATED! I...
|
1430 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:', |
renamed dbi_options to dbi_o...
|
1431 |
dbi_option => {PrintError => 1}); |
1432 |
ok($dbi->dbh->{PrintError}); |
|
data_source is DEPRECATED! I...
|
1433 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:', |
renamed dbi_options to dbi_o...
|
1434 |
dbi_options => {PrintError => 1}); |
1435 |
ok($dbi->dbh->{PrintError}); |
|
1436 | ||
added experimental DBIx::Cus...
|
1437 |
test 'DBIx::Custom::Result stash()'; |
1438 |
$result = DBIx::Custom::Result->new; |
|
1439 |
is_deeply($result->stash, {}, 'default'); |
|
1440 |
$result->stash->{foo} = 1; |
|
1441 |
is($result->stash->{foo}, 1, 'get and set'); |
|
table object call dbi object...
|
1442 | |
fix bug : filter can't over...
|
1443 |
test 'filter __ expression'; |
1444 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1445 |
$dbi->execute('create table company (id, name, location_id)'); |
|
1446 |
$dbi->execute('create table location (id, name)'); |
|
1447 |
$dbi->apply_filter('location', |
|
1448 |
name => {in => sub { uc $_[0] } } |
|
1449 |
); |
|
1450 | ||
1451 |
$dbi->insert(table => 'company', param => {id => 1, name => 'a', location_id => 2}); |
|
1452 |
$dbi->insert(table => 'location', param => {id => 2, name => 'b'}); |
|
1453 | ||
1454 |
$result = $dbi->select( |
|
1455 |
table => ['company', 'location'], relation => {'company.location_id' => 'location.id'}, |
|
1456 |
column => ['location.name as location__name'] |
|
1457 |
); |
|
1458 |
is($result->fetch_first->[0], 'B'); |
|
1459 | ||
add experimental DBIx::Custo...
|
1460 |
$result = $dbi->select( |
1461 |
table => 'company', relation => {'company.location_id' => 'location.id'}, |
|
1462 |
column => ['location.name as location__name'] |
|
1463 |
); |
|
1464 |
is($result->fetch_first->[0], 'B'); |
|
1465 | ||
added EXPERIMENTAL col metho...
|
1466 |
$result = $dbi->select( |
1467 |
table => 'company', relation => {'company.location_id' => 'location.id'}, |
|
1468 |
column => ['location.name as "location.name"'] |
|
1469 |
); |
|
1470 |
is($result->fetch_first->[0], 'B'); |
|
1471 | ||
add feture. all model class ...
|
1472 |
test 'Model class'; |
removed experimental base_ta...
|
1473 |
use MyDBI1; |
1474 |
$dbi = MyDBI1->connect($NEW_ARGS->{0}); |
|
1475 |
$dbi->execute("create table book (title, author)"); |
|
add feture. all model class ...
|
1476 |
$model = $dbi->model('book'); |
1477 |
$model->insert({title => 'a', author => 'b'}); |
|
added EXPERIMENTAL select pr...
|
1478 |
is_deeply($model->list->all, [{title => 'a', author => 'b'}], 'basic'); |
removed experimental base_ta...
|
1479 |
$dbi->execute("create table company (name)"); |
add feture. all model class ...
|
1480 |
$model = $dbi->model('company'); |
1481 |
$model->insert({name => 'a'}); |
|
added EXPERIMENTAL select pr...
|
1482 |
is_deeply($model->list->all, [{name => 'a'}], 'basic'); |
add models() attribute
|
1483 |
is($dbi->models->{'book'}, $dbi->model('book')); |
1484 |
is($dbi->models->{'company'}, $dbi->model('company')); |
|
removed experimental base_ta...
|
1485 | |
1486 |
{ |
|
1487 |
package MyDBI4; |
|
1488 | ||
1489 |
use strict; |
|
1490 |
use warnings; |
|
1491 | ||
1492 |
use base 'DBIx::Custom'; |
|
1493 | ||
1494 |
sub connect { |
|
1495 |
my $self = shift->SUPER::connect(@_); |
|
1496 |
|
|
add feture. all model class ...
|
1497 |
$self->include_model( |
1498 |
MyModel2 => [ |
|
removed experimental base_ta...
|
1499 |
'book', |
add experimental DBIx::Custo...
|
1500 |
{class => 'Company', name => 'company'} |
removed experimental base_ta...
|
1501 |
] |
1502 |
); |
|
1503 |
} |
|
1504 | ||
add feture. all model class ...
|
1505 |
package MyModel2::Base1; |
removed experimental base_ta...
|
1506 | |
1507 |
use strict; |
|
1508 |
use warnings; |
|
1509 | ||
add feture. all model class ...
|
1510 |
use base 'DBIx::Custom::Model'; |
removed experimental base_ta...
|
1511 | |
add feture. all model class ...
|
1512 |
package MyModel2::book; |
removed experimental base_ta...
|
1513 | |
1514 |
use strict; |
|
1515 |
use warnings; |
|
1516 | ||
add feture. all model class ...
|
1517 |
use base 'MyModel2::Base1'; |
removed experimental base_ta...
|
1518 | |
1519 |
sub insert { |
|
1520 |
my ($self, $param) = @_; |
|
1521 |
|
|
1522 |
return $self->SUPER::insert(param => $param); |
|
1523 |
} |
|
1524 | ||
1525 |
sub list { shift->select; } |
|
1526 | ||
add feture. all model class ...
|
1527 |
package MyModel2::Company; |
removed experimental base_ta...
|
1528 | |
1529 |
use strict; |
|
1530 |
use warnings; |
|
1531 | ||
add feture. all model class ...
|
1532 |
use base 'MyModel2::Base1'; |
removed experimental base_ta...
|
1533 | |
1534 |
sub insert { |
|
1535 |
my ($self, $param) = @_; |
|
1536 |
|
|
1537 |
return $self->SUPER::insert(param => $param); |
|
1538 |
} |
|
1539 | ||
1540 |
sub list { shift->select; } |
|
1541 |
} |
|
1542 |
$dbi = MyDBI4->connect($NEW_ARGS->{0}); |
|
1543 |
$dbi->execute("create table book (title, author)"); |
|
add feture. all model class ...
|
1544 |
$model = $dbi->model('book'); |
1545 |
$model->insert({title => 'a', author => 'b'}); |
|
added EXPERIMENTAL select pr...
|
1546 |
is_deeply($model->list->all, [{title => 'a', author => 'b'}], 'basic'); |
removed experimental base_ta...
|
1547 |
$dbi->execute("create table company (name)"); |
add feture. all model class ...
|
1548 |
$model = $dbi->model('company'); |
1549 |
$model->insert({name => 'a'}); |
|
added EXPERIMENTAL select pr...
|
1550 |
is_deeply($model->list->all, [{name => 'a'}], 'basic'); |
add feture. all model class ...
|
1551 | |
1552 |
{ |
|
1553 |
package MyDBI5; |
|
1554 | ||
1555 |
use strict; |
|
1556 |
use warnings; |
|
1557 | ||
1558 |
use base 'DBIx::Custom'; |
|
1559 | ||
1560 |
sub connect { |
|
1561 |
my $self = shift->SUPER::connect(@_); |
|
1562 |
|
|
1563 |
$self->include_model('MyModel4'); |
|
1564 |
} |
|
1565 |
} |
|
1566 |
$dbi = MyDBI5->connect($NEW_ARGS->{0}); |
|
1567 |
$dbi->execute("create table company (name)"); |
|
- added EXPERIMENTAL type() ...
|
1568 |
$dbi->execute("create table table1 (key1)"); |
add feture. all model class ...
|
1569 |
$model = $dbi->model('company'); |
1570 |
$model->insert({name => 'a'}); |
|
added EXPERIMENTAL select pr...
|
1571 |
is_deeply($model->list->all, [{name => 'a'}], 'include all model'); |
- added EXPERIMENTAL type() ...
|
1572 |
$dbi->insert(table => 'table1', param => {key1 => 1}); |
add feture. all model class ...
|
1573 |
$model = $dbi->model('book'); |
added EXPERIMENTAL select pr...
|
1574 |
is_deeply($model->list->all, [{key1 => 1}], 'include all model'); |
add feture. all model class ...
|
1575 | |
add DBIx::Custom::Model fore...
|
1576 |
test 'primary_key'; |
1577 |
use MyDBI1; |
|
1578 |
$dbi = MyDBI1->connect($NEW_ARGS->{0}); |
|
1579 |
$model = $dbi->model('book'); |
|
1580 |
$model->primary_key(['id', 'number']); |
|
1581 |
is_deeply($model->primary_key, ['id', 'number']); |
|
1582 | ||
add DBIx::Custom::Model colu...
|
1583 |
test 'columns'; |
1584 |
use MyDBI1; |
|
1585 |
$dbi = MyDBI1->connect($NEW_ARGS->{0}); |
|
1586 |
$model = $dbi->model('book'); |
|
1587 |
$model->columns(['id', 'number']); |
|
1588 |
is_deeply($model->columns, ['id', 'number']); |
|
add feture. all model class ...
|
1589 | |
add experimental setup_model...
|
1590 |
test 'setup_model'; |
1591 |
use MyDBI1; |
|
1592 |
$dbi = MyDBI1->connect($NEW_ARGS->{0}); |
|
1593 |
$dbi->execute('create table book (id)'); |
|
1594 |
$dbi->execute('create table company (id, name);'); |
|
1595 |
$dbi->execute('create table test (id, name, primary key (id, name));'); |
|
1596 |
$dbi->setup_model; |
|
1597 |
is_deeply($dbi->model('book')->columns, ['id']); |
|
1598 |
is_deeply($dbi->model('company')->columns, ['id', 'name']); |
|
add experimental update_at()...
|
1599 | |
1600 |
test 'delete_at'; |
|
1601 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1602 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1603 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1604 |
$dbi->delete_at( |
|
1605 |
table => 'table1', |
|
1606 |
primary_key => ['key1', 'key2'], |
|
1607 |
where => [1, 2], |
|
1608 |
); |
|
added EXPERIMENTAL select pr...
|
1609 |
is_deeply($dbi->select(table => 'table1')->all, []); |
add experimental update_at()...
|
1610 | |
1611 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1612 |
$dbi->delete_at( |
|
1613 |
table => 'table1', |
|
1614 |
primary_key => 'key1', |
|
1615 |
where => 1, |
|
1616 |
); |
|
added EXPERIMENTAL select pr...
|
1617 |
is_deeply($dbi->select(table => 'table1')->all, []); |
add experimental update_at()...
|
1618 | |
- added experimental DBIx::C...
|
1619 |
test 'insert_at'; |
1620 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1621 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1622 |
$dbi->insert_at( |
|
1623 |
primary_key => ['key1', 'key2'], |
|
1624 |
table => 'table1', |
|
1625 |
where => [1, 2], |
|
1626 |
param => {key3 => 3} |
|
1627 |
); |
|
added tests
|
1628 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
1629 |
is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
1630 |
is($dbi->select(table => 'table1')->one->{key3}, 3); |
|
- added experimental DBIx::C...
|
1631 | |
1632 |
$dbi->delete_all(table => 'table1'); |
|
add experimental update_at()...
|
1633 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
- added experimental DBIx::C...
|
1634 |
$dbi->insert_at( |
1635 |
primary_key => 'key1', |
|
add experimental update_at()...
|
1636 |
table => 'table1', |
- added experimental DBIx::C...
|
1637 |
where => 1, |
1638 |
param => {key2 => 2, key3 => 3} |
|
add experimental update_at()...
|
1639 |
); |
1640 | ||
added tests
|
1641 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
1642 |
is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
1643 |
is($dbi->select(table => 'table1')->one->{key3}, 3); |
|
- added experimental DBIx::C...
|
1644 | |
1645 |
eval { |
|
1646 |
$dbi->insert_at( |
|
1647 |
table => 'table1', |
|
1648 |
primary_key => ['key1', 'key2'], |
|
1649 |
where => {}, |
|
1650 |
param => {key1 => 1, key2 => 2, key3 => 3}, |
|
1651 |
); |
|
1652 |
}; |
|
1653 |
like($@, qr/must be/); |
|
add experimental update_at()...
|
1654 | |
- insert, insert_at, update,...
|
1655 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
1656 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1657 |
$dbi->insert_at( |
|
1658 |
{key3 => 3}, |
|
1659 |
primary_key => ['key1', 'key2'], |
|
1660 |
table => 'table1', |
|
1661 |
where => [1, 2], |
|
1662 |
); |
|
added tests
|
1663 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
1664 |
is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
1665 |
is($dbi->select(table => 'table1')->one->{key3}, 3); |
|
- insert, insert_at, update,...
|
1666 | |
add experimental update_at()...
|
1667 |
test 'update_at'; |
1668 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1669 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1670 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1671 |
$dbi->update_at( |
|
1672 |
table => 'table1', |
|
1673 |
primary_key => ['key1', 'key2'], |
|
1674 |
where => [1, 2], |
|
1675 |
param => {key3 => 4} |
|
1676 |
); |
|
added tests
|
1677 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
1678 |
is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
1679 |
is($dbi->select(table => 'table1')->one->{key3}, 4); |
|
add experimental update_at()...
|
1680 | |
1681 |
$dbi->delete_all(table => 'table1'); |
|
1682 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1683 |
$dbi->update_at( |
|
1684 |
table => 'table1', |
|
1685 |
primary_key => 'key1', |
|
1686 |
where => 1, |
|
1687 |
param => {key3 => 4} |
|
1688 |
); |
|
added tests
|
1689 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
1690 |
is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
1691 |
is($dbi->select(table => 'table1')->one->{key3}, 4); |
|
add experimental update_at()...
|
1692 | |
- insert, insert_at, update,...
|
1693 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
1694 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1695 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1696 |
$dbi->update_at( |
|
1697 |
{key3 => 4}, |
|
1698 |
table => 'table1', |
|
1699 |
primary_key => ['key1', 'key2'], |
|
1700 |
where => [1, 2] |
|
1701 |
); |
|
added tests
|
1702 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
1703 |
is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
1704 |
is($dbi->select(table => 'table1')->one->{key3}, 4); |
|
- insert, insert_at, update,...
|
1705 | |
add experimental update_at()...
|
1706 |
test 'select_at'; |
1707 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1708 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1709 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1710 |
$result = $dbi->select_at( |
|
1711 |
table => 'table1', |
|
1712 |
primary_key => ['key1', 'key2'], |
|
1713 |
where => [1, 2] |
|
1714 |
); |
|
added tests
|
1715 |
$row = $result->one; |
add experimental update_at()...
|
1716 |
is($row->{key1}, 1); |
1717 |
is($row->{key2}, 2); |
|
1718 |
is($row->{key3}, 3); |
|
1719 | ||
1720 |
$dbi->delete_all(table => 'table1'); |
|
1721 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1722 |
$result = $dbi->select_at( |
|
1723 |
table => 'table1', |
|
1724 |
primary_key => 'key1', |
|
1725 |
where => 1, |
|
1726 |
); |
|
added tests
|
1727 |
$row = $result->one; |
add experimental update_at()...
|
1728 |
is($row->{key1}, 1); |
1729 |
is($row->{key2}, 2); |
|
1730 |
is($row->{key3}, 3); |
|
1731 | ||
1732 |
$dbi->delete_all(table => 'table1'); |
|
1733 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1734 |
$result = $dbi->select_at( |
|
1735 |
table => 'table1', |
|
1736 |
primary_key => ['key1', 'key2'], |
|
cleanup
|
1737 |
where => [1, 2] |
add experimental update_at()...
|
1738 |
); |
added tests
|
1739 |
$row = $result->one; |
add experimental update_at()...
|
1740 |
is($row->{key1}, 1); |
1741 |
is($row->{key2}, 2); |
|
1742 |
is($row->{key3}, 3); |
|
1743 | ||
- added experimental DBIx::C...
|
1744 |
eval { |
1745 |
$result = $dbi->select_at( |
|
1746 |
table => 'table1', |
|
1747 |
primary_key => ['key1', 'key2'], |
|
1748 |
where => {}, |
|
1749 |
); |
|
1750 |
}; |
|
1751 |
like($@, qr/must be/); |
|
1752 | ||
improved error messages
|
1753 |
eval { |
1754 |
$result = $dbi->select_at( |
|
1755 |
table => 'table1', |
|
1756 |
primary_key => ['key1', 'key2'], |
|
1757 |
where => [1], |
|
1758 |
); |
|
1759 |
}; |
|
1760 |
like($@, qr/same/); |
|
1761 | ||
- added experimental DBIx::C...
|
1762 |
eval { |
1763 |
$result = $dbi->update_at( |
|
1764 |
table => 'table1', |
|
1765 |
primary_key => ['key1', 'key2'], |
|
1766 |
where => {}, |
|
1767 |
param => {key1 => 1, key2 => 2}, |
|
1768 |
); |
|
1769 |
}; |
|
1770 |
like($@, qr/must be/); |
|
1771 | ||
1772 |
eval { |
|
1773 |
$result = $dbi->delete_at( |
|
1774 |
table => 'table1', |
|
1775 |
primary_key => ['key1', 'key2'], |
|
1776 |
where => {}, |
|
1777 |
); |
|
1778 |
}; |
|
1779 |
like($@, qr/must be/); |
|
add experimental update_at()...
|
1780 | |
add experimental DBIx::Custo...
|
1781 |
test 'columns'; |
1782 |
use MyDBI1; |
|
1783 |
$dbi = MyDBI1->connect($NEW_ARGS->{0}); |
|
1784 |
$model = $dbi->model('book'); |
|
add experimental DBIx::Custo...
|
1785 | |
1786 | ||
1787 |
test 'model delete_at'; |
|
1788 |
{ |
|
1789 |
package MyDBI6; |
|
1790 |
|
|
1791 |
use base 'DBIx::Custom'; |
|
1792 |
|
|
1793 |
sub connect { |
|
1794 |
my $self = shift->SUPER::connect(@_); |
|
1795 |
|
|
1796 |
$self->include_model('MyModel5'); |
|
1797 |
|
|
1798 |
return $self; |
|
1799 |
} |
|
1800 |
} |
|
1801 |
$dbi = MyDBI6->connect($NEW_ARGS->{0}); |
|
1802 |
$dbi->execute($CREATE_TABLE->{1}); |
|
- added EXPERIMENTAL type() ...
|
1803 |
$dbi->execute("create table table2 (key1, key2, key3)"); |
1804 |
$dbi->execute("create table table3 (key1, key2, key3)"); |
|
add experimental DBIx::Custo...
|
1805 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
1806 |
$dbi->model('table1')->delete_at(where => [1, 2]); |
|
added EXPERIMENTAL select pr...
|
1807 |
is_deeply($dbi->select(table => 'table1')->all, []); |
- added EXPERIMENTAL type() ...
|
1808 |
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3}); |
add experimental DBIx::Custo...
|
1809 |
$dbi->model('table1_1')->delete_at(where => [1, 2]); |
added EXPERIMENTAL select pr...
|
1810 |
is_deeply($dbi->select(table => 'table1')->all, []); |
- added EXPERIMENTAL type() ...
|
1811 |
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3}); |
add experimental DBIx::Custo...
|
1812 |
$dbi->model('table1_3')->delete_at(where => [1, 2]); |
added EXPERIMENTAL select pr...
|
1813 |
is_deeply($dbi->select(table => 'table1')->all, []); |
add experimental DBIx::Custo...
|
1814 | |
- added experimental DBIx::C...
|
1815 |
test 'model insert_at'; |
1816 |
$dbi = MyDBI6->connect($NEW_ARGS->{0}); |
|
1817 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1818 |
$dbi->model('table1')->insert_at( |
|
1819 |
where => [1, 2], |
|
1820 |
param => {key3 => 3} |
|
1821 |
); |
|
1822 |
$result = $dbi->model('table1')->select; |
|
added tests
|
1823 |
$row = $result->one; |
- added experimental DBIx::C...
|
1824 |
is($row->{key1}, 1); |
1825 |
is($row->{key2}, 2); |
|
1826 |
is($row->{key3}, 3); |
|
add experimental DBIx::Custo...
|
1827 | |
- added experimental DBIx::C...
|
1828 |
test 'model update_at'; |
add experimental DBIx::Custo...
|
1829 |
$dbi = MyDBI6->connect($NEW_ARGS->{0}); |
1830 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1831 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1832 |
$dbi->model('table1')->update_at( |
|
1833 |
where => [1, 2], |
|
1834 |
param => {key3 => 4} |
|
1835 |
); |
|
1836 |
$result = $dbi->model('table1')->select; |
|
added tests
|
1837 |
$row = $result->one; |
add experimental DBIx::Custo...
|
1838 |
is($row->{key1}, 1); |
1839 |
is($row->{key2}, 2); |
|
1840 |
is($row->{key3}, 4); |
|
1841 | ||
- added experimental DBIx::C...
|
1842 |
test 'model select_at'; |
add experimental DBIx::Custo...
|
1843 |
$dbi = MyDBI6->connect($NEW_ARGS->{0}); |
1844 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1845 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
1846 |
$result = $dbi->model('table1')->select_at(where => [1, 2]); |
|
added tests
|
1847 |
$row = $result->one; |
add experimental DBIx::Custo...
|
1848 |
is($row->{key1}, 1); |
1849 |
is($row->{key2}, 2); |
|
1850 |
is($row->{key3}, 3); |
|
DBIx::Custom::Model select()...
|
1851 | |
1852 | ||
cleanup
|
1853 |
test 'mycolumn and column'; |
DBIx::Custom::Model select()...
|
1854 |
{ |
1855 |
package MyDBI7; |
|
1856 |
|
|
1857 |
use base 'DBIx::Custom'; |
|
1858 |
|
|
1859 |
sub connect { |
|
1860 |
my $self = shift->SUPER::connect(@_); |
|
1861 |
|
|
1862 |
$self->include_model('MyModel6'); |
|
1863 |
|
|
add experimental DBIx::Custo...
|
1864 |
|
DBIx::Custom::Model select()...
|
1865 |
return $self; |
1866 |
} |
|
1867 |
} |
|
1868 |
$dbi = MyDBI7->connect($NEW_ARGS->{0}); |
|
1869 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1870 |
$dbi->execute($CREATE_TABLE->{2}); |
|
EXPERIMTANL column method th...
|
1871 |
$dbi->separator('__'); |
add experimental DBIx::Custo...
|
1872 |
$dbi->setup_model; |
1873 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1874 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3}); |
|
1875 |
$model = $dbi->model('table1'); |
|
cleanup
|
1876 |
$result = $model->select( |
1877 |
column => [$model->mycolumn, $model->column('table2')], |
|
1878 |
where => {'table1.key1' => 1} |
|
1879 |
); |
|
added tests
|
1880 |
is_deeply($result->one, |
cleanup
|
1881 |
{key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3}); |
add experimental DBIx::Custo...
|
1882 | |
- update_param_tag is DEPREC...
|
1883 |
test 'update_param'; |
added experimental update_pa...
|
1884 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
1885 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1886 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
1887 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
1888 | ||
1889 |
$param = {key2 => 11}; |
|
- update_param_tag is DEPREC...
|
1890 |
$update_param = $dbi->update_param($param); |
added experimental update_pa...
|
1891 |
$sql = <<"EOS"; |
- update_param_tag is DEPREC...
|
1892 |
update table1 $update_param |
added experimental update_pa...
|
1893 |
where key1 = 1 |
1894 |
EOS |
|
1895 |
$dbi->execute($sql, param => $param); |
|
- update_param_tag is DEPREC...
|
1896 |
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1'); |
added EXPERIMENTAL select pr...
|
1897 |
$rows = $result->all; |
added experimental update_pa...
|
1898 |
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5}, |
1899 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
1900 |
"basic"); |
|
1901 | ||
1902 | ||
added EXPERIMENTAL updat_par...
|
1903 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
1904 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1905 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
1906 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
1907 | ||
1908 |
$param = {key2 => 11, key3 => 33}; |
|
- update_param_tag is DEPREC...
|
1909 |
$update_param = $dbi->update_param($param); |
added EXPERIMENTAL updat_par...
|
1910 |
$sql = <<"EOS"; |
- update_param_tag is DEPREC...
|
1911 |
update table1 $update_param |
added EXPERIMENTAL updat_par...
|
1912 |
where key1 = 1 |
1913 |
EOS |
|
1914 |
$dbi->execute($sql, param => $param); |
|
- update_param_tag is DEPREC...
|
1915 |
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1'); |
added EXPERIMENTAL select pr...
|
1916 |
$rows = $result->all; |
added EXPERIMENTAL updat_par...
|
1917 |
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5}, |
1918 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
1919 |
"basic"); |
|
1920 | ||
1921 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1922 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1923 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
1924 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
1925 | ||
1926 |
$param = {key2 => 11, key3 => 33}; |
|
- update_param_tag is DEPREC...
|
1927 |
$update_param = $dbi->update_param($param, {no_set => 1}); |
added EXPERIMENTAL updat_par...
|
1928 |
$sql = <<"EOS"; |
- update_param_tag is DEPREC...
|
1929 |
update table1 set $update_param |
added EXPERIMENTAL updat_par...
|
1930 |
where key1 = 1 |
1931 |
EOS |
|
1932 |
$dbi->execute($sql, param => $param); |
|
- update_param_tag is DEPREC...
|
1933 |
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1'); |
added EXPERIMENTAL select pr...
|
1934 |
$rows = $result->all; |
added EXPERIMENTAL updat_par...
|
1935 |
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5}, |
1936 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
1937 |
"update param no_set"); |
|
1938 | ||
1939 |
|
|
- update_param_tag is DEPREC...
|
1940 |
eval { $dbi->update_param({";" => 1}) }; |
added experimental update_pa...
|
1941 |
like($@, qr/not safety/); |
1942 | ||
1943 | ||
- update_param_tag is DEPREC...
|
1944 |
test 'update_param'; |
added EXPERIMENTAL assign_ta...
|
1945 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
1946 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1947 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
1948 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
1949 | ||
1950 |
$param = {key2 => 11}; |
|
- update_param_tag is DEPREC...
|
1951 |
$update_param = $dbi->assign_param($param); |
added EXPERIMENTAL assign_ta...
|
1952 |
$sql = <<"EOS"; |
- update_param_tag is DEPREC...
|
1953 |
update table1 set $update_param |
added EXPERIMENTAL assign_ta...
|
1954 |
where key1 = 1 |
1955 |
EOS |
|
- update_param_tag is DEPREC...
|
1956 |
$dbi->execute($sql, param => $param, table => 'table1'); |
added EXPERIMENTAL assign_ta...
|
1957 |
$result = $dbi->execute($SELECT_SOURCES->{0}); |
added EXPERIMENTAL select pr...
|
1958 |
$rows = $result->all; |
added EXPERIMENTAL assign_ta...
|
1959 |
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5}, |
1960 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
|
1961 |
"basic"); |
|
1962 | ||
1963 | ||
added experimental update_pa...
|
1964 |
test 'insert_param'; |
1965 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
1966 |
$dbi->execute($CREATE_TABLE->{1}); |
|
added EXPERIMENTAL updat_par...
|
1967 |
$param = {key1 => 1, key2 => 2}; |
- update_param_tag is DEPREC...
|
1968 |
$insert_param = $dbi->insert_param($param); |
added experimental update_pa...
|
1969 |
$sql = <<"EOS"; |
- update_param_tag is DEPREC...
|
1970 |
insert into table1 $insert_param |
added experimental update_pa...
|
1971 |
EOS |
- update_param_tag is DEPREC...
|
1972 |
$dbi->execute($sql, param => $param, table => 'table1'); |
added tests
|
1973 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
1974 |
is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
added experimental update_pa...
|
1975 | |
added EXPERIMENTAL updat_par...
|
1976 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
1977 |
$dbi->reserved_word_quote('"'); |
|
1978 |
$dbi->execute($CREATE_TABLE->{1}); |
|
1979 |
$param = {key1 => 1, key2 => 2}; |
|
- update_param_tag is DEPREC...
|
1980 |
$insert_param = $dbi->insert_param($param); |
added EXPERIMENTAL updat_par...
|
1981 |
$sql = <<"EOS"; |
- update_param_tag is DEPREC...
|
1982 |
insert into table1 $insert_param |
added EXPERIMENTAL updat_par...
|
1983 |
EOS |
- update_param_tag is DEPREC...
|
1984 |
$dbi->execute($sql, param => $param, table => 'table1'); |
added tests
|
1985 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
1986 |
is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
add experimental DBIx::Custo...
|
1987 | |
- update_param_tag is DEPREC...
|
1988 |
eval { $dbi->insert_param({";" => 1}) }; |
added experimental update_pa...
|
1989 |
like($@, qr/not safety/); |
cleanup
|
1990 | |
1991 | ||
- added experimental DBIx::C...
|
1992 |
test 'join'; |
cleanup
|
1993 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
1994 |
$dbi->execute($CREATE_TABLE->{0}); |
|
1995 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1996 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4}); |
|
1997 |
$dbi->execute($CREATE_TABLE->{2}); |
|
1998 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5}); |
|
- added experimental DBIx::C...
|
1999 |
$dbi->execute($CREATE_TABLE->{4}); |
2000 |
$dbi->insert(table => 'table3', param => {key3 => 5, key4 => 4}); |
|
cleanup
|
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}, |
|
- added experimental DBIx::C...
|
2005 |
join => ['left outer join table2 on table1.key1 = table2.key1'] |
added EXPERIMENTAL select pr...
|
2006 |
)->all; |
cleanup
|
2007 |
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}]); |
2008 | ||
- added experimental DBIx::C...
|
2009 |
$rows = $dbi->select( |
2010 |
table => 'table1', |
|
2011 |
where => {'key1' => 1}, |
|
2012 |
join => ['left outer join table2 on table1.key1 = table2.key1'] |
|
added EXPERIMENTAL select pr...
|
2013 |
)->all; |
- added experimental DBIx::C...
|
2014 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
2015 | ||
cleanup
|
2016 |
eval { |
2017 |
$rows = $dbi->select( |
|
2018 |
table => 'table1', |
|
2019 |
column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3', |
|
2020 |
where => {'table1.key2' => 2}, |
|
- added experimental DBIx::C...
|
2021 |
join => {'table1.key1' => 'table2.key1'} |
cleanup
|
2022 |
); |
2023 |
}; |
|
2024 |
like ($@, qr/array/); |
|
- added experimental DBIx::C...
|
2025 | |
2026 |
$rows = $dbi->select( |
|
2027 |
table => 'table1', |
|
2028 |
where => {'key1' => 1}, |
|
2029 |
join => ['left outer join table2 on table1.key1 = table2.key1', |
|
2030 |
'left outer join table3 on table2.key3 = table3.key3'] |
|
added EXPERIMENTAL select pr...
|
2031 |
)->all; |
- added experimental DBIx::C...
|
2032 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
2033 | ||
2034 |
$rows = $dbi->select( |
|
2035 |
column => 'table3.key4 as table3__key4', |
|
2036 |
table => 'table1', |
|
2037 |
where => {'table1.key1' => 1}, |
|
2038 |
join => ['left outer join table2 on table1.key1 = table2.key1', |
|
2039 |
'left outer join table3 on table2.key3 = table3.key3'] |
|
added EXPERIMENTAL select pr...
|
2040 |
)->all; |
- added experimental DBIx::C...
|
2041 |
is_deeply($rows, [{table3__key4 => 4}]); |
2042 | ||
2043 |
$rows = $dbi->select( |
|
2044 |
column => 'table1.key1 as table1__key1', |
|
2045 |
table => 'table1', |
|
2046 |
where => {'table3.key4' => 4}, |
|
2047 |
join => ['left outer join table2 on table1.key1 = table2.key1', |
|
2048 |
'left outer join table3 on table2.key3 = table3.key3'] |
|
added EXPERIMENTAL select pr...
|
2049 |
)->all; |
- added experimental DBIx::C...
|
2050 |
is_deeply($rows, [{table1__key1 => 1}]); |
- added experimental DBIx::C...
|
2051 | |
added EXPERIMENTAL reserved_...
|
2052 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
2053 |
$dbi->reserved_word_quote('"'); |
|
2054 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2055 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2056 |
$dbi->execute($CREATE_TABLE->{2}); |
|
2057 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5}); |
|
2058 |
$rows = $dbi->select( |
|
2059 |
table => 'table1', |
|
2060 |
column => '"table1"."key1" as "table1_key1", "table2"."key1" as "table2_key1", "key2", "key3"', |
|
2061 |
where => {'table1.key2' => 2}, |
|
2062 |
join => ['left outer join "table2" on "table1"."key1" = "table2"."key1"'], |
|
added EXPERIMENTAL select pr...
|
2063 |
)->all; |
added EXPERIMENTAL reserved_...
|
2064 |
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], |
2065 |
'reserved_word_quote'); |
|
- added experimental DBIx::C...
|
2066 | |
2067 |
{ |
|
2068 |
package MyDBI8; |
|
2069 |
|
|
2070 |
use base 'DBIx::Custom'; |
|
2071 |
|
|
2072 |
sub connect { |
|
2073 |
my $self = shift->SUPER::connect(@_); |
|
2074 |
|
|
2075 |
$self->include_model('MyModel7'); |
|
2076 |
|
|
2077 |
return $self; |
|
2078 |
} |
|
2079 |
} |
|
added select() all_column op...
|
2080 | |
data_source is DEPRECATED! I...
|
2081 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
2082 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2083 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2084 |
$sql = <<"EOS"; |
|
2085 |
left outer join ( |
|
2086 |
select * from table1 as t1 |
|
2087 |
where t1.key2 = ( |
|
2088 |
select max(t2.key2) from table1 as t2 |
|
2089 |
where t1.key1 = t2.key1 |
|
2090 |
) |
|
2091 |
) as latest_table1 on table1.key1 = latest_table1.key1 |
|
2092 |
EOS |
|
2093 |
$join = [$sql]; |
|
2094 |
$rows = $dbi->select( |
|
2095 |
table => 'table1', |
|
2096 |
column => 'latest_table1.key1 as latest_table1__key1', |
|
2097 |
join => $join |
|
added EXPERIMENTAL select pr...
|
2098 |
)->all; |
data_source is DEPRECATED! I...
|
2099 |
is_deeply($rows, [{latest_table1__key1 => 1}]); |
2100 | ||
- added EXPERIMENTAL DBIx::C...
|
2101 |
test 'mycolumn'; |
2102 |
$dbi = MyDBI8->connect($NEW_ARGS->{0}); |
|
- added EXPERIMENTAL DBIx::C...
|
2103 |
$dbi->execute($CREATE_TABLE->{0}); |
- added EXPERIMENTAL DBIx::C...
|
2104 |
$dbi->execute($CREATE_TABLE->{2}); |
2105 |
$dbi->setup_model; |
|
2106 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2107 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3}); |
|
2108 |
$model = $dbi->model('table1'); |
|
2109 |
$result = $model->select_at( |
|
2110 |
column => [ |
|
2111 |
$model->mycolumn, |
|
2112 |
$model->column('table2') |
|
2113 |
] |
|
- added EXPERIMENTAL DBIx::C...
|
2114 |
); |
added tests
|
2115 |
is_deeply($result->one, |
EXPERIMTANL column method th...
|
2116 |
{key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3}); |
- select() column option can...
|
2117 | |
- added EXPERIMENTAL DBIx::C...
|
2118 |
$result = $model->select_at( |
2119 |
column => [ |
|
2120 |
$model->mycolumn(['key1']), |
|
2121 |
$model->column(table2 => ['key1']) |
|
2122 |
] |
|
2123 |
); |
|
added tests
|
2124 |
is_deeply($result->one, |
EXPERIMTANL column method th...
|
2125 |
{key1 => 1, 'table2.key1' => 1}); |
- select() column option can...
|
2126 |
$result = $model->select_at( |
2127 |
column => [ |
|
2128 |
$model->mycolumn(['key1']), |
|
2129 |
{table2 => ['key1']} |
|
2130 |
] |
|
2131 |
); |
|
added tests
|
2132 |
is_deeply($result->one, |
- select() EXPERIMETNAL colu...
|
2133 |
{key1 => 1, 'table2.key1' => 1}); |
- select() column option can...
|
2134 | |
- select() column option can...
|
2135 |
$result = $model->select_at( |
2136 |
column => [ |
|
2137 |
$model->mycolumn(['key1']), |
|
2138 |
['table2.key1', as => 'table2.key1'] |
|
2139 |
] |
|
2140 |
); |
|
2141 |
is_deeply($result->one, |
|
2142 |
{key1 => 1, 'table2.key1' => 1}); |
|
2143 | ||
2144 |
eval{ |
|
2145 |
$result = $model->select_at( |
|
2146 |
column => [ |
|
2147 |
['table2.key1', asaaaa => 'table2.key1'] |
|
2148 |
] |
|
2149 |
); |
|
2150 |
}; |
|
2151 |
like($@, qr/COLUMN/); |
|
2152 | ||
- added EXPERIMENTAL DBIx::C...
|
2153 |
test 'dbi method from model'; |
- added EXPERIMENTAL DBIx::C...
|
2154 |
{ |
2155 |
package MyDBI9; |
|
2156 |
|
|
2157 |
use base 'DBIx::Custom'; |
|
2158 |
|
|
2159 |
sub connect { |
|
2160 |
my $self = shift->SUPER::connect(@_); |
|
2161 |
|
|
2162 |
$self->include_model('MyModel8')->setup_model; |
|
2163 |
|
|
2164 |
return $self; |
|
2165 |
} |
|
2166 |
} |
|
2167 |
$dbi = MyDBI9->connect($NEW_ARGS->{0}); |
|
2168 |
$dbi->execute($CREATE_TABLE->{0}); |
|
- added EXPERIMENTAL DBIx::C...
|
2169 |
$model = $dbi->model('table1'); |
2170 |
eval{$model->execute('select * from table1')}; |
|
2171 |
ok(!$@); |
|
2172 | ||
2173 |
test 'table_alias'; |
|
2174 |
$dbi = MyDBI9->connect($NEW_ARGS->{0}); |
|
2175 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2176 |
$dbi->execute($CREATE_TABLE->{2}); |
|
2177 |
$dbi->setup_model; |
|
2178 |
$dbi->execute('insert into table1 (key1, key2) values (1, 2);'); |
|
2179 |
$dbi->execute('insert into table2 (key1, key3) values (1, 4);'); |
|
2180 |
$model = $dbi->model('table1'); |
|
2181 |
$result = $model->select( |
|
2182 |
column => [ |
|
2183 |
$model->column('table2_alias') |
|
2184 |
], |
|
2185 |
where => {'table2_alias.key3' => 2} |
|
2186 |
); |
|
added tests
|
2187 |
is_deeply($result->one, |
EXPERIMTANL column method th...
|
2188 |
{'table2_alias.key1' => 1, 'table2_alias.key3' => 48}); |
- added EXPERIMENTAL DBIx::C...
|
2189 | |
cleanup
|
2190 |
$dbi->separator('__'); |
2191 |
$result = $model->select( |
|
2192 |
column => [ |
|
2193 |
$model->column('table2_alias') |
|
2194 |
], |
|
2195 |
where => {'table2_alias.key3' => 2} |
|
2196 |
); |
|
2197 |
is_deeply($result->one, |
|
2198 |
{'table2_alias__key1' => 1, 'table2_alias__key3' => 48}); |
|
2199 | ||
2200 |
$dbi->separator('-'); |
|
2201 |
$result = $model->select( |
|
2202 |
column => [ |
|
2203 |
$model->column('table2_alias') |
|
2204 |
], |
|
2205 |
where => {'table2_alias.key3' => 2} |
|
2206 |
); |
|
2207 |
is_deeply($result->one, |
|
2208 |
{'table2_alias-key1' => 1, 'table2_alias-key3' => 48}); |
|
2209 | ||
- added EXPERIMENTAL type() ...
|
2210 |
test 'type() option'; |
2211 |
$dbi = DBIx::Custom->connect( |
|
2212 |
data_source => 'dbi:SQLite:dbname=:memory:', |
|
2213 |
dbi_option => { |
|
2214 |
$DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1) |
|
2215 |
} |
|
2216 |
); |
|
2217 |
my $binary = pack("I3", 1, 2, 3); |
|
2218 |
$dbi->execute('create table table1(key1, key2)'); |
|
2219 |
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [key1 => DBI::SQL_BLOB]); |
|
2220 |
$result = $dbi->select(table => 'table1'); |
|
added tests
|
2221 |
$row = $result->one; |
- added EXPERIMENTAL type() ...
|
2222 |
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic"); |
2223 |
$result = $dbi->execute('select length(key1) as key1_length from table1'); |
|
added tests
|
2224 |
$row = $result->one; |
- added EXPERIMENTAL type() ...
|
2225 |
is($row->{key1_length}, length $binary); |
2226 | ||
2227 |
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [['key1'] => DBI::SQL_BLOB]); |
|
2228 |
$result = $dbi->select(table => 'table1'); |
|
added tests
|
2229 |
$row = $result->one; |
- added EXPERIMENTAL type() ...
|
2230 |
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic"); |
2231 |
$result = $dbi->execute('select length(key1) as key1_length from table1'); |
|
added tests
|
2232 |
$row = $result->one; |
- added EXPERIMENTAL type() ...
|
2233 |
is($row->{key1_length}, length $binary); |
2234 | ||
removed EXPERIMETNAL flag fr...
|
2235 |
test 'create_model'; |
2236 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2237 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2238 |
$dbi->execute($CREATE_TABLE->{2}); |
|
2239 | ||
2240 |
$dbi->create_model( |
|
2241 |
table => 'table1', |
|
2242 |
join => [ |
|
2243 |
'left outer join table2 on table1.key1 = table2.key1' |
|
2244 |
], |
|
2245 |
primary_key => ['key1'] |
|
2246 |
); |
|
create_model() return model
|
2247 |
$model2 = $dbi->create_model( |
removed EXPERIMETNAL flag fr...
|
2248 |
table => 'table2' |
2249 |
); |
|
2250 |
$dbi->create_model( |
|
2251 |
table => 'table3', |
|
2252 |
filter => [ |
|
2253 |
key1 => {in => sub { uc $_[0] }} |
|
2254 |
] |
|
2255 |
); |
|
2256 |
$dbi->setup_model; |
|
2257 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2258 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3}); |
|
2259 |
$model = $dbi->model('table1'); |
|
2260 |
$result = $model->select( |
|
2261 |
column => [$model->mycolumn, $model->column('table2')], |
|
2262 |
where => {'table1.key1' => 1} |
|
2263 |
); |
|
added tests
|
2264 |
is_deeply($result->one, |
EXPERIMTANL column method th...
|
2265 |
{key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3}); |
added tests
|
2266 |
is_deeply($model2->select->one, {key1 => 1, key3 => 3}); |
removed EXPERIMETNAL flag fr...
|
2267 | |
adeed EXPERIMENTAL DBIx::Cus...
|
2268 |
test 'model method'; |
2269 |
test 'create_model'; |
|
2270 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2271 |
$dbi->execute($CREATE_TABLE->{2}); |
|
2272 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3}); |
|
2273 |
$model = $dbi->create_model( |
|
2274 |
table => 'table2' |
|
2275 |
); |
|
2276 |
$model->method(foo => sub { shift->select(@_) }); |
|
added tests
|
2277 |
is_deeply($model->foo->one, {key1 => 1, key3 => 3}); |
added EXPERIMENTAL updat_par...
|
2278 | |
2279 |
test 'merge_param'; |
|
2280 |
{ |
|
2281 |
my $dbi = DBIx::Custom->new; |
|
2282 |
my $param1 = {key1 => 1, key2 => 2, key3 => 3}; |
|
2283 |
my $param2 = {key1 => 1, key2 => 2}; |
|
2284 |
my $param3 = {key1 => 1}; |
|
2285 |
my $param = $dbi->merge_param($param1, $param2, $param3); |
|
2286 |
is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3}); |
|
cleanup
|
2287 |
} |
2288 | ||
fixed merge_param bug
|
2289 |
{ |
2290 |
my $dbi = DBIx::Custom->new; |
|
2291 |
my $param1 = {key1 => [1, 2], key2 => 1, key3 => [1, 2]}; |
|
2292 |
my $param2 = {key1 => [3, 4], key2 => [2, 3], key3 => 3}; |
|
2293 |
my $param = $dbi->merge_param($param1, $param2); |
|
2294 |
is_deeply($param, {key1 => [1, 2, 3, 4], key2 => [1, 2, 3], key3 => [1, 2, 3]}); |
|
2295 |
} |
|
2296 | ||
cleanup
|
2297 |
test 'select() param option'; |
2298 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2299 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2300 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2301 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3}); |
|
2302 |
$dbi->execute($CREATE_TABLE->{2}); |
|
2303 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4}); |
|
2304 |
$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5}); |
|
2305 |
$rows = $dbi->select( |
|
2306 |
table => 'table1', |
|
2307 |
column => 'table1.key1 as table1_key1, key2, key3', |
|
2308 |
where => {'table1.key2' => 3}, |
|
2309 |
join => ['inner join (select * from table2 where {= table2.key3})' . |
|
2310 |
' as table2 on table1.key1 = table2.key1'], |
|
2311 |
param => {'table2.key3' => 5} |
|
added EXPERIMENTAL select pr...
|
2312 |
)->all; |
cleanup
|
2313 |
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]); |
2314 | ||
added EXPERIMENTAL select() ...
|
2315 | |
2316 |
test 'select() wrap option'; |
|
2317 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2318 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2319 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2320 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3}); |
|
2321 |
$rows = $dbi->select( |
|
2322 |
table => 'table1', |
|
2323 |
column => 'key1', |
|
2324 |
wrap => ['select * from (', ') as t where key1 = 1'] |
|
added EXPERIMENTAL select pr...
|
2325 |
)->all; |
added EXPERIMENTAL select() ...
|
2326 |
is_deeply($rows, [{key1 => 1}]); |
2327 | ||
2328 |
eval { |
|
2329 |
$dbi->select( |
|
2330 |
table => 'table1', |
|
2331 |
column => 'key1', |
|
2332 |
wrap => 'select * from (' |
|
2333 |
) |
|
2334 |
}; |
|
cleanup
|
2335 |
like($@, qr/array/); |
2336 | ||
2337 |
test 'select() string where'; |
|
2338 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2339 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2340 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2341 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3}); |
|
2342 |
$rows = $dbi->select( |
|
2343 |
table => 'table1', |
|
select, update, and delete w...
|
2344 |
where => '{= key1} and {= key2}', |
DEPRECATED select() param op...
|
2345 |
where_param => {key1 => 1, key2 => 2} |
added EXPERIMENTAL select pr...
|
2346 |
)->all; |
cleanup
|
2347 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
select, update, and delete w...
|
2348 | |
2349 |
test 'delete() string where'; |
|
2350 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2351 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2352 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2353 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3}); |
|
2354 |
$dbi->delete( |
|
2355 |
table => 'table1', |
|
2356 |
where => '{= key1} and {= key2}', |
|
DEPRECATED select() param op...
|
2357 |
where_param => {key1 => 1, key2 => 2} |
select, update, and delete w...
|
2358 |
); |
added EXPERIMENTAL select pr...
|
2359 |
$rows = $dbi->select(table => 'table1')->all; |
select, update, and delete w...
|
2360 |
is_deeply($rows, [{key1 => 2, key2 => 3}]); |
2361 | ||
2362 | ||
2363 |
test 'update() string where'; |
|
2364 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2365 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2366 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2367 |
$dbi->update( |
|
2368 |
table => 'table1', |
|
DEPRECATED select() param op...
|
2369 |
param => {key1 => 5}, |
2370 |
where => '{= key1} and {= key2}', |
|
2371 |
where_param => {key1 => 1, key2 => 2} |
|
select, update, and delete w...
|
2372 |
); |
added EXPERIMENTAL select pr...
|
2373 |
$rows = $dbi->select(table => 'table1')->all; |
select, update, and delete w...
|
2374 |
is_deeply($rows, [{key1 => 5, key2 => 2}]); |
- update_param_tag is DEPREC...
|
2375 | |
cleanup
|
2376 | |
insert_at is DEPRECATED! add...
|
2377 |
test 'insert id and primary_key option'; |
2378 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2379 |
$dbi->execute($CREATE_TABLE->{1}); |
|
2380 |
$dbi->insert( |
|
2381 |
primary_key => ['key1', 'key2'], |
|
2382 |
table => 'table1', |
|
2383 |
id => [1, 2], |
|
2384 |
param => {key3 => 3} |
|
2385 |
); |
|
2386 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
|
2387 |
is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
2388 |
is($dbi->select(table => 'table1')->one->{key3}, 3); |
|
2389 | ||
2390 |
$dbi->delete_all(table => 'table1'); |
|
2391 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
2392 |
$dbi->insert( |
|
2393 |
primary_key => 'key1', |
|
2394 |
table => 'table1', |
|
2395 |
id => 1, |
|
2396 |
param => {key2 => 2, key3 => 3} |
|
2397 |
); |
|
2398 | ||
2399 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
|
2400 |
is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
2401 |
is($dbi->select(table => 'table1')->one->{key3}, 3); |
|
2402 | ||
2403 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2404 |
$dbi->execute($CREATE_TABLE->{1}); |
|
2405 |
$dbi->insert( |
|
2406 |
{key3 => 3}, |
|
2407 |
primary_key => ['key1', 'key2'], |
|
2408 |
table => 'table1', |
|
2409 |
id => [1, 2], |
|
2410 |
); |
|
2411 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
|
2412 |
is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
2413 |
is($dbi->select(table => 'table1')->one->{key3}, 3); |
|
2414 | ||
cleanup
|
2415 | |
added tests
|
2416 |
test 'model insert id and primary_key option'; |
2417 |
$dbi = MyDBI6->connect($NEW_ARGS->{0}); |
|
2418 |
$dbi->execute($CREATE_TABLE->{1}); |
|
2419 |
$dbi->model('table1')->insert( |
|
2420 |
id => [1, 2], |
|
2421 |
param => {key3 => 3} |
|
2422 |
); |
|
2423 |
$result = $dbi->model('table1')->select; |
|
2424 |
$row = $result->one; |
|
2425 |
is($row->{key1}, 1); |
|
2426 |
is($row->{key2}, 2); |
|
2427 |
is($row->{key3}, 3); |
|
2428 | ||
- fixed bug that model inser...
|
2429 |
$dbi = MyDBI6->connect($NEW_ARGS->{0}); |
2430 |
$dbi->execute($CREATE_TABLE->{1}); |
|
2431 |
$dbi->model('table1')->insert( |
|
2432 |
{key3 => 3}, |
|
2433 |
id => [1, 2] |
|
2434 |
); |
|
2435 |
$result = $dbi->model('table1')->select; |
|
2436 |
$row = $result->one; |
|
2437 |
is($row->{key1}, 1); |
|
2438 |
is($row->{key2}, 2); |
|
2439 |
is($row->{key3}, 3); |
|
2440 | ||
update_at is DEPRECATED! use...
|
2441 |
test 'update and id option'; |
2442 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2443 |
$dbi->execute($CREATE_TABLE->{1}); |
|
2444 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
2445 |
$dbi->update( |
|
2446 |
table => 'table1', |
|
2447 |
primary_key => ['key1', 'key2'], |
|
2448 |
id => [1, 2], |
|
2449 |
param => {key3 => 4} |
|
2450 |
); |
|
2451 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
|
2452 |
is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
2453 |
is($dbi->select(table => 'table1')->one->{key3}, 4); |
|
2454 | ||
2455 |
$dbi->delete_all(table => 'table1'); |
|
2456 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
2457 |
$dbi->update( |
|
2458 |
table => 'table1', |
|
2459 |
primary_key => 'key1', |
|
2460 |
id => 1, |
|
2461 |
param => {key3 => 4} |
|
2462 |
); |
|
2463 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
|
2464 |
is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
2465 |
is($dbi->select(table => 'table1')->one->{key3}, 4); |
|
2466 | ||
2467 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2468 |
$dbi->execute($CREATE_TABLE->{1}); |
|
2469 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
2470 |
$dbi->update( |
|
2471 |
{key3 => 4}, |
|
2472 |
table => 'table1', |
|
2473 |
primary_key => ['key1', 'key2'], |
|
2474 |
id => [1, 2] |
|
2475 |
); |
|
2476 |
is($dbi->select(table => 'table1')->one->{key1}, 1); |
|
2477 |
is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
2478 |
is($dbi->select(table => 'table1')->one->{key3}, 4); |
|
2479 | ||
2480 | ||
delete_at is DEPRECATED! use...
|
2481 |
test 'model update and id option'; |
update_at is DEPRECATED! use...
|
2482 |
$dbi = MyDBI6->connect($NEW_ARGS->{0}); |
2483 |
$dbi->execute($CREATE_TABLE->{1}); |
|
2484 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
2485 |
$dbi->model('table1')->update( |
|
2486 |
id => [1, 2], |
|
2487 |
param => {key3 => 4} |
|
2488 |
); |
|
2489 |
$result = $dbi->model('table1')->select; |
|
2490 |
$row = $result->one; |
|
2491 |
is($row->{key1}, 1); |
|
2492 |
is($row->{key2}, 2); |
|
2493 |
is($row->{key3}, 4); |
|
added tests
|
2494 | |
delete_at is DEPRECATED! use...
|
2495 | |
2496 |
test 'delete and id option'; |
|
2497 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2498 |
$dbi->execute($CREATE_TABLE->{1}); |
|
2499 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
2500 |
$dbi->delete( |
|
2501 |
table => 'table1', |
|
2502 |
primary_key => ['key1', 'key2'], |
|
2503 |
id => [1, 2], |
|
2504 |
); |
|
added EXPERIMENTAL select pr...
|
2505 |
is_deeply($dbi->select(table => 'table1')->all, []); |
delete_at is DEPRECATED! use...
|
2506 | |
2507 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
2508 |
$dbi->delete( |
|
2509 |
table => 'table1', |
|
2510 |
primary_key => 'key1', |
|
2511 |
id => 1, |
|
2512 |
); |
|
added EXPERIMENTAL select pr...
|
2513 |
is_deeply($dbi->select(table => 'table1')->all, []); |
delete_at is DEPRECATED! use...
|
2514 | |
2515 | ||
2516 |
test 'model delete and id option'; |
|
2517 |
$dbi = MyDBI6->connect($NEW_ARGS->{0}); |
|
2518 |
$dbi->execute($CREATE_TABLE->{1}); |
|
2519 |
$dbi->execute("create table table2 (key1, key2, key3)"); |
|
2520 |
$dbi->execute("create table table3 (key1, key2, key3)"); |
|
2521 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
2522 |
$dbi->model('table1')->delete(id => [1, 2]); |
|
added EXPERIMENTAL select pr...
|
2523 |
is_deeply($dbi->select(table => 'table1')->all, []); |
delete_at is DEPRECATED! use...
|
2524 |
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3}); |
2525 |
$dbi->model('table1_1')->delete(id => [1, 2]); |
|
added EXPERIMENTAL select pr...
|
2526 |
is_deeply($dbi->select(table => 'table1')->all, []); |
delete_at is DEPRECATED! use...
|
2527 |
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3}); |
2528 |
$dbi->model('table1_3')->delete(id => [1, 2]); |
|
added EXPERIMENTAL select pr...
|
2529 |
is_deeply($dbi->select(table => 'table1')->all, []); |
delete_at is DEPRECATED! use...
|
2530 | |
select_at is DEPRECATED! use...
|
2531 | |
2532 |
test 'select and id option'; |
|
2533 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2534 |
$dbi->execute($CREATE_TABLE->{1}); |
|
2535 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
2536 |
$result = $dbi->select( |
|
2537 |
table => 'table1', |
|
2538 |
primary_key => ['key1', 'key2'], |
|
2539 |
id => [1, 2] |
|
2540 |
); |
|
2541 |
$row = $result->one; |
|
2542 |
is($row->{key1}, 1); |
|
2543 |
is($row->{key2}, 2); |
|
2544 |
is($row->{key3}, 3); |
|
2545 | ||
2546 |
$dbi->delete_all(table => 'table1'); |
|
2547 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
2548 |
$result = $dbi->select( |
|
2549 |
table => 'table1', |
|
2550 |
primary_key => 'key1', |
|
2551 |
id => 1, |
|
2552 |
); |
|
2553 |
$row = $result->one; |
|
2554 |
is($row->{key1}, 1); |
|
2555 |
is($row->{key2}, 2); |
|
2556 |
is($row->{key3}, 3); |
|
2557 | ||
2558 |
$dbi->delete_all(table => 'table1'); |
|
2559 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
2560 |
$result = $dbi->select( |
|
2561 |
table => 'table1', |
|
2562 |
primary_key => ['key1', 'key2'], |
|
2563 |
id => [1, 2] |
|
2564 |
); |
|
2565 |
$row = $result->one; |
|
2566 |
is($row->{key1}, 1); |
|
2567 |
is($row->{key2}, 2); |
|
2568 |
is($row->{key3}, 3); |
|
2569 | ||
2570 | ||
2571 |
test 'model select_at'; |
|
2572 |
$dbi = MyDBI6->connect($NEW_ARGS->{0}); |
|
2573 |
$dbi->execute($CREATE_TABLE->{1}); |
|
2574 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
2575 |
$result = $dbi->model('table1')->select(id => [1, 2]); |
|
2576 |
$row = $result->one; |
|
2577 |
is($row->{key1}, 1); |
|
2578 |
is($row->{key2}, 2); |
|
2579 |
is($row->{key3}, 3); |
|
2580 | ||
EXPERIMTANL column method th...
|
2581 |
test 'column separator is default .'; |
added EXPERIMENTAL col metho...
|
2582 |
$dbi = MyDBI7->connect($NEW_ARGS->{0}); |
2583 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2584 |
$dbi->execute($CREATE_TABLE->{2}); |
|
2585 |
$dbi->setup_model; |
|
2586 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2587 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3}); |
|
2588 |
$model = $dbi->model('table1'); |
|
2589 |
$result = $model->select( |
|
EXPERIMTANL column method th...
|
2590 |
column => [$model->column('table2')], |
added EXPERIMENTAL col metho...
|
2591 |
where => {'table1.key1' => 1} |
2592 |
); |
|
2593 |
is_deeply($result->one, |
|
2594 |
{'table2.key1' => 1, 'table2.key3' => 3}); |
|
2595 | ||
2596 |
$result = $model->select( |
|
EXPERIMTANL column method th...
|
2597 |
column => [$model->column('table2' => [qw/key1 key3/])], |
added EXPERIMENTAL col metho...
|
2598 |
where => {'table1.key1' => 1} |
2599 |
); |
|
2600 |
is_deeply($result->one, |
|
2601 |
{'table2.key1' => 1, 'table2.key3' => 3}); |
|
2602 | ||
added type_rule method and f...
|
2603 | |
2604 |
test 'type_rule from'; |
|
2605 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
|
2606 |
$dbi->type_rule( |
|
changed type_rule arguments ...
|
2607 |
from => { |
added EXPERIMENTAL DBIx::Cus...
|
2608 |
date => sub { uc $_[0] } |
added type_rule method and f...
|
2609 |
} |
2610 |
); |
|
2611 |
$dbi->execute("create table table1 (key1 Date, key2 datetime)"); |
|
2612 |
$dbi->insert({key1 => 'a'}, table => 'table1'); |
|
2613 |
$result = $dbi->select(table => 'table1'); |
|
2614 |
is($result->fetch_first->[0], 'A'); |
|
2615 | ||
2616 |
$result = $dbi->select(table => 'table1'); |
|
2617 |
is($result->one->{key1}, 'A'); |
|
2618 | ||
added type_rule into logic
|
2619 | |
2620 |
test 'type_rule into'; |
|
2621 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
|
2622 |
$dbi->execute("create table table1 (key1 Date, key2 datetime)"); |
|
2623 |
$dbi->type_rule( |
|
changed type_rule arguments ...
|
2624 |
into => { |
added EXPERIMENTAL DBIx::Cus...
|
2625 |
date => sub { uc $_[0] } |
added type_rule into logic
|
2626 |
} |
2627 |
); |
|
2628 |
$dbi->insert({key1 => 'a'}, table => 'table1'); |
|
2629 |
$result = $dbi->select(table => 'table1'); |
|
2630 |
is($result->one->{key1}, 'A'); |
|
2631 | ||
2632 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
|
added EXPERIMENTAL DBIx::Cus...
|
2633 |
$dbi->execute("create table table1 (key1 date, key2 datetime)"); |
added type_rule into logic
|
2634 |
$dbi->type_rule( |
changed type_rule arguments ...
|
2635 |
into => [ |
added EXPERIMENTAL DBIx::Cus...
|
2636 |
[qw/date datetime/] => sub { uc $_[0] } |
changed type_rule arguments ...
|
2637 |
] |
added type_rule into logic
|
2638 |
); |
2639 |
$dbi->insert({key1 => 'a', key2 => 'b'}, table => 'table1'); |
|
2640 |
$result = $dbi->select(table => 'table1'); |
|
2641 |
$row = $result->one; |
|
2642 |
is($row->{key1}, 'A'); |
|
2643 |
is($row->{key2}, 'B'); |
|
2644 | ||
2645 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
|
2646 |
$dbi->execute("create table table1 (key1 Date, key2 datetime)"); |
|
2647 |
$dbi->insert({key1 => 'a', key2 => 'B'}, table => 'table1'); |
|
2648 |
$dbi->type_rule( |
|
changed type_rule arguments ...
|
2649 |
into => [ |
added EXPERIMENTAL DBIx::Cus...
|
2650 |
[qw/date datetime/] => sub { uc $_[0] } |
changed type_rule arguments ...
|
2651 |
] |
added type_rule into logic
|
2652 |
); |
2653 |
$result = $dbi->execute( |
|
2654 |
"select * from table1 where key1 = :key1 and key2 = :table1.key2;", |
|
2655 |
param => {key1 => 'a', 'table1.key2' => 'b'} |
|
2656 |
); |
|
2657 |
$row = $result->one; |
|
2658 |
is($row->{key1}, 'a'); |
|
2659 |
is($row->{key2}, 'B'); |
|
2660 | ||
2661 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
|
2662 |
$dbi->execute("create table table1 (key1 Date, key2 datetime)"); |
|
2663 |
$dbi->insert({key1 => 'A', key2 => 'B'}, table => 'table1'); |
|
2664 |
$dbi->type_rule( |
|
changed type_rule arguments ...
|
2665 |
into => [ |
added EXPERIMENTAL DBIx::Cus...
|
2666 |
[qw/date datetime/] => sub { uc $_[0] } |
changed type_rule arguments ...
|
2667 |
] |
added type_rule into logic
|
2668 |
); |
2669 |
$result = $dbi->execute( |
|
2670 |
"select * from table1 where key1 = :key1 and key2 = :table1.key2;", |
|
2671 |
param => {key1 => 'a', 'table1.key2' => 'b'}, |
|
2672 |
table => 'table1' |
|
2673 |
); |
|
2674 |
$row = $result->one; |
|
2675 |
is($row->{key1}, 'A'); |
|
2676 |
is($row->{key2}, 'B'); |
|
2677 | ||
fixed bug that type_rule fro...
|
2678 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
added EXPERIMENTAL DBIx::Cus...
|
2679 |
$dbi->execute("create table table1 (key1 date, key2 datetime)"); |
fixed bug that type_rule fro...
|
2680 |
$dbi->register_filter(twice => sub { $_[0] * 2 }); |
2681 |
$dbi->type_rule( |
|
2682 |
from => { |
|
added EXPERIMENTAL DBIx::Cus...
|
2683 |
date => 'twice', |
fixed bug that type_rule fro...
|
2684 |
}, |
2685 |
into => { |
|
added EXPERIMENTAL DBIx::Cus...
|
2686 |
date => 'twice', |
fixed bug that type_rule fro...
|
2687 |
} |
2688 |
); |
|
2689 |
$dbi->insert({key1 => 2}, table => 'table1'); |
|
2690 |
$result = $dbi->select(table => 'table1'); |
|
2691 |
is($result->fetch->[0], 8); |
|
2692 | ||
added EXPERIMENTAL execute()...
|
2693 | |
2694 |
test 'type_rule_off'; |
|
2695 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
|
2696 |
$dbi->execute("create table table1 (key1 Date, key2 datetime)"); |
|
2697 |
$dbi->type_rule( |
|
changed type_rule arguments ...
|
2698 |
from => { |
added EXPERIMENTAL DBIx::Cus...
|
2699 |
date => sub { $_[0] * 2 }, |
changed type_rule arguments ...
|
2700 |
}, |
2701 |
into => { |
|
added EXPERIMENTAL DBIx::Cus...
|
2702 |
date => sub { $_[0] * 2 }, |
added EXPERIMENTAL execute()...
|
2703 |
} |
2704 |
); |
|
2705 |
$dbi->insert({key1 => 2}, table => 'table1', type_rule_off => 1); |
|
2706 |
$result = $dbi->select(table => 'table1', type_rule_off => 1); |
|
added test
|
2707 |
$result->type_rule_off(1); |
2708 |
is($result->fetch->[0], 2); |
|
added EXPERIMENTAL execute()...
|
2709 | |
2710 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
|
2711 |
$dbi->execute("create table table1 (key1 Date, key2 datetime)"); |
|
2712 |
$dbi->type_rule( |
|
changed type_rule arguments ...
|
2713 |
from => { |
added EXPERIMENTAL DBIx::Cus...
|
2714 |
date => sub { $_[0] * 2 }, |
changed type_rule arguments ...
|
2715 |
}, |
2716 |
into => { |
|
added EXPERIMENTAL DBIx::Cus...
|
2717 |
date => sub { $_[0] * 3 }, |
added EXPERIMENTAL execute()...
|
2718 |
} |
2719 |
); |
|
2720 |
$dbi->insert({key1 => 2}, table => 'table1', type_rule_off => 1); |
|
2721 |
$result = $dbi->select(table => 'table1', type_rule_off => 1); |
|
added EXPERIMENTAL DBIx::Cus...
|
2722 |
is($result->one->{key1}, 4); |
2723 | ||
2724 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
|
2725 |
$dbi->execute("create table table1 (key1 Date, key2 datetime)"); |
|
2726 |
$dbi->type_rule( |
|
2727 |
from => { |
|
2728 |
date => sub { $_[0] * 2 }, |
|
2729 |
}, |
|
2730 |
into => { |
|
2731 |
date => sub { $_[0] * 3 }, |
|
2732 |
} |
|
2733 |
); |
|
2734 |
$dbi->insert({key1 => 2}, table => 'table1'); |
|
2735 |
$result = $dbi->select(table => 'table1'); |
|
2736 |
is($result->one->{key1}, 12); |
|
2737 | ||
2738 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
|
2739 |
$dbi->execute("create table table1 (key1 Date, key2 datetime)"); |
|
2740 |
$dbi->type_rule( |
|
2741 |
from => { |
|
2742 |
date => sub { $_[0] * 2 }, |
|
2743 |
}, |
|
2744 |
into => { |
|
2745 |
date => sub { $_[0] * 3 }, |
|
2746 |
} |
|
2747 |
); |
|
2748 |
$dbi->insert({key1 => 2}, table => 'table1'); |
|
2749 |
$result = $dbi->select(table => 'table1'); |
|
2750 |
is($result->fetch->[0], 12); |
|
added EXPERIMENTAL execute()...
|
2751 | |
type_rule can receive filter...
|
2752 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
2753 |
$dbi->execute("create table table1 (key1 Date, key2 datetime)"); |
|
2754 |
$dbi->register_filter(ppp => sub { uc $_[0] }); |
|
2755 |
$dbi->type_rule( |
|
2756 |
into => { |
|
added EXPERIMENTAL DBIx::Cus...
|
2757 |
date => 'ppp' |
type_rule can receive filter...
|
2758 |
} |
2759 |
); |
|
2760 |
$dbi->insert({key1 => 'a'}, table => 'table1'); |
|
2761 |
$result = $dbi->select(table => 'table1'); |
|
2762 |
is($result->one->{key1}, 'A'); |
|
2763 | ||
2764 |
eval{$dbi->type_rule( |
|
2765 |
into => { |
|
added EXPERIMENTAL DBIx::Cus...
|
2766 |
date => 'pp' |
type_rule can receive filter...
|
2767 |
} |
2768 |
)}; |
|
2769 |
like($@, qr/not registered/); |
|
added DBIx::Custom result_fi...
|
2770 | |
added EXPERIMENTAL DBIx::Cus...
|
2771 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
2772 |
$dbi->execute("create table table1 (key1 Date, key2 datetime)"); |
|
2773 |
$dbi->type_rule( |
|
2774 |
from => { |
|
2775 |
date => sub { $_[0] * 2 }, |
|
2776 |
}, |
|
2777 |
into => { |
|
2778 |
date => sub { $_[0] * 3 }, |
|
2779 |
} |
|
2780 |
); |
|
2781 |
$dbi->insert({key1 => 2}, table => 'table1'); |
|
2782 |
$result = $dbi->select(table => 'table1'); |
|
2783 |
delete $result->type_rule->{date}; |
|
2784 |
is($result->one->{key1}, 6); |
|
2785 | ||
2786 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
|
2787 |
$dbi->execute("create table table1 (key1 Date, key2 datetime)"); |
|
2788 |
eval { |
|
2789 |
$dbi->type_rule( |
|
2790 |
from => { |
|
2791 |
Date => sub { $_[0] * 2 }, |
|
2792 |
} |
|
2793 |
); |
|
2794 |
}; |
|
2795 |
like($@, qr/lower/); |
|
2796 | ||
2797 |
eval { |
|
2798 |
$dbi->type_rule( |
|
2799 |
into => { |
|
2800 |
Date => sub { $_[0] * 2 }, |
|
2801 |
} |
|
2802 |
); |
|
2803 |
}; |
|
2804 |
like($@, qr/lower/); |
|
2805 | ||
2806 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
|
2807 |
$dbi->execute("create table table1 (key1 Date, key2 datetime)"); |
|
2808 |
$dbi->type_rule( |
|
2809 |
from => { |
|
2810 |
date => sub { $_[0] * 2 }, |
|
2811 |
}, |
|
2812 |
into => { |
|
2813 |
date => sub { $_[0] * 3 }, |
|
2814 |
} |
|
2815 |
); |
|
2816 |
$dbi->insert({key1 => 2}, table => 'table1'); |
|
2817 |
$result = $dbi->select(table => 'table1'); |
|
2818 |
$result->type_rule_off(1); |
|
2819 |
is($result->one->{key1}, 6); |
|
2820 | ||
2821 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
|
2822 |
$dbi->execute("create table table1 (key1 Date, key2 datetime)"); |
|
2823 |
$dbi->type_rule( |
|
2824 |
from => { |
|
2825 |
date => sub { $_[0] * 2 }, |
|
2826 |
datetime => sub { $_[0] * 4 }, |
|
2827 |
}, |
|
2828 |
); |
|
2829 |
$dbi->insert({key1 => 2, key2 => 2}, table => 'table1'); |
|
2830 |
$result = $dbi->select(table => 'table1'); |
|
2831 |
$result->type_rule(date => sub { $_[0] * 3 }); |
|
2832 |
$row = $result->one; |
|
2833 |
is($row->{key1}, 6); |
|
2834 |
is($row->{key2}, 8); |
|
2835 |
$result = $dbi->select(table => 'table1'); |
|
2836 |
$result->type_rule({date => sub { $_[0] * 3 }}); |
|
2837 |
$row = $result->one; |
|
2838 |
is($row->{key1}, 6); |
|
2839 |
is($row->{key2}, 8); |
|
2840 |
$result = $dbi->select(table => 'table1'); |
|
2841 |
$result->type_rule([date => sub { $_[0] * 3 }]); |
|
2842 |
$row = $result->one; |
|
2843 |
is($row->{key1}, 6); |
|
2844 |
is($row->{key2}, 8); |
|
2845 |
$dbi->register_filter(fivetimes => sub { $_[0] * 5}); |
|
2846 |
$result = $dbi->select(table => 'table1'); |
|
2847 |
$result->type_rule(date => 'fivetimes'); |
|
2848 |
$row = $result->one; |
|
2849 |
is($row->{key1}, 10); |
|
2850 |
is($row->{key2}, 8); |
|
2851 |
$result = $dbi->select(table => 'table1'); |
|
2852 |
$result->type_rule(date => undef); |
|
2853 |
$row = $result->one; |
|
2854 |
is($row->{key1}, 2); |
|
2855 |
is($row->{key2}, 8); |
|
2856 | ||
DBIx::Custom::Result filter ...
|
2857 |
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
2858 |
$dbi->execute("create table table1 (key1 Date, key2 datetime)"); |
|
2859 |
$dbi->type_rule( |
|
2860 |
from => { |
|
2861 |
date => sub { $_[0] * 2 }, |
|
2862 |
}, |
|
2863 |
); |
|
2864 |
$dbi->insert({key1 => 2}, table => 'table1'); |
|
2865 |
$result = $dbi->select(table => 'table1'); |
|
removed EXPERIMENTAL DBIx::M...
|
2866 |
$result->filter(key1 => sub { $_[0] * 3 }); |
DBIx::Custom::Result filter ...
|
2867 |
is($result->one->{key1}, 6); |
added EXPERIMENTAL DBIx::Cus...
|
2868 | |
removed EXPERIMENTAL DBIx::M...
|
2869 |
test 'separator'; |
added DBIx::Custom result_fi...
|
2870 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
2871 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2872 |
$dbi->execute($CREATE_TABLE->{2}); |
|
2873 | ||
2874 |
$dbi->create_model( |
|
2875 |
table => 'table1', |
|
2876 |
join => [ |
|
2877 |
'left outer join table2 on table1.key1 = table2.key1' |
|
2878 |
], |
|
2879 |
primary_key => ['key1'], |
|
2880 |
); |
|
2881 |
$model2 = $dbi->create_model( |
|
2882 |
table => 'table2', |
|
2883 |
); |
|
2884 |
$dbi->setup_model; |
|
2885 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2886 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3}); |
|
2887 |
$model = $dbi->model('table1'); |
|
2888 |
$result = $model->select( |
|
2889 |
column => [ |
|
2890 |
$model->mycolumn, |
|
2891 |
{table2 => [qw/key1 key3/]} |
|
2892 |
], |
|
2893 |
where => {'table1.key1' => 1} |
|
2894 |
); |
|
2895 |
is_deeply($result->one, |
|
removed EXPERIMENTAL DBIx::M...
|
2896 |
{key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3}); |
2897 |
is_deeply($model2->select->one, {key1 => 1, key3 => 3}); |
|
added DBIx::Custom result_fi...
|
2898 | |
EXPERIMTANL column method th...
|
2899 |
$dbi->separator('__'); |
2900 |
$model = $dbi->model('table1'); |
|
2901 |
$result = $model->select( |
|
2902 |
column => [ |
|
2903 |
$model->mycolumn, |
|
2904 |
{table2 => [qw/key1 key3/]} |
|
2905 |
], |
|
2906 |
where => {'table1.key1' => 1} |
|
2907 |
); |
|
2908 |
is_deeply($result->one, |
|
removed EXPERIMENTAL DBIx::M...
|
2909 |
{key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3}); |
2910 |
is_deeply($model2->select->one, {key1 => 1, key3 => 3}); |
|
EXPERIMTANL column method th...
|
2911 | |
cleanup
|
2912 |
$dbi->separator('-'); |
2913 |
$model = $dbi->model('table1'); |
|
2914 |
$result = $model->select( |
|
2915 |
column => [ |
|
2916 |
$model->mycolumn, |
|
2917 |
{table2 => [qw/key1 key3/]} |
|
2918 |
], |
|
2919 |
where => {'table1.key1' => 1} |
|
2920 |
); |
|
2921 |
is_deeply($result->one, |
|
removed EXPERIMENTAL DBIx::M...
|
2922 |
{key1 => 1, key2 => 2, 'table2-key1' => 1, 'table2-key3' => 3}); |
2923 |
is_deeply($model2->select->one, {key1 => 1, key3 => 3}); |
|
cleanup
|
2924 | |
EXPERIMTANL column method th...
|
2925 | |
type_rule can receive filter...
|
2926 |
test 'filter_off'; |
2927 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2928 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2929 |
$dbi->execute($CREATE_TABLE->{2}); |
|
2930 | ||
2931 |
$dbi->create_model( |
|
2932 |
table => 'table1', |
|
2933 |
join => [ |
|
2934 |
'left outer join table2 on table1.key1 = table2.key1' |
|
2935 |
], |
|
2936 |
primary_key => ['key1'], |
|
2937 |
); |
|
2938 |
$dbi->setup_model; |
|
2939 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2940 |
$model = $dbi->model('table1'); |
|
removed EXPERIMENTAL DBIx::M...
|
2941 |
$result = $model->select(column => 'key1'); |
2942 |
$result->filter(key1 => sub { $_[0] * 2 }); |
|
2943 |
is_deeply($result->one, {key1 => 2}); |
|
fixed bug that type_rule fro...
|
2944 | |
2945 |
test 'available_date_type'; |
|
2946 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2947 |
ok($dbi->can('available_data_type')); |
|
2948 | ||
added EXPERIMENTAL select pr...
|
2949 | |
2950 |
test 'select prefix option'; |
|
2951 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2952 |
$dbi->execute($CREATE_TABLE->{0}); |
|
2953 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2954 |
$rows = $dbi->select(prefix => 'key1,', column => 'key2', table => 'table1')->all; |
|
2955 |
is_deeply($rows, [{key1 => 1, key2 => 2}], "table"); |
|
2956 | ||
added EXPERIMETNAL separator...
|
2957 | |
2958 |
test 'separator'; |
|
2959 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2960 |
is($dbi->separator, '.'); |
|
2961 |
$dbi->separator('-'); |
|
2962 |
is($dbi->separator, '-'); |
|
2963 |
$dbi->separator('__'); |
|
2964 |
is($dbi->separator, '__'); |
|
2965 |
eval { $dbi->separator('?') }; |
|
2966 |
like($@, qr/Separator/); |
|
2967 | ||
- update_param_tag is DEPREC...
|
2968 |
=cut |