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