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