DBIx-Custom / t / dbix-custom-core-sqlite.t /
Newer Older
1274 lines | 43.737kb
removed register_format()
yuki-kimoto authored on 2010-05-26
1
use Test::More;
2
use strict;
3
use warnings;
4

            
5
use utf8;
6
use Encode qw/encode_utf8 decode_utf8/;
7

            
8
BEGIN {
9
    eval { require DBD::SQLite; 1 }
10
        or plan skip_all => 'DBD::SQLite required';
11
    eval { DBD::SQLite->VERSION >= 1.25 }
12
        or plan skip_all => 'DBD::SQLite >= 1.25 required';
13

            
14
    plan 'no_plan';
15
    use_ok('DBIx::Custom');
16
}
17

            
18
# Function for test name
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
19
sub test { print "# $_[0]\n" }
removed register_format()
yuki-kimoto authored on 2010-05-26
20

            
21
# Constant varialbes for test
22
my $CREATE_TABLE = {
23
    0 => 'create table table1 (key1 char(255), key2 char(255));',
24
    1 => 'create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));',
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
25
    2 => 'create table table2 (key1 char(255), key3 char(255));',
26
    3 => 'create table table1 (key1 Date, key2 datetime);'
removed register_format()
yuki-kimoto authored on 2010-05-26
27
};
28

            
add tests
yuki-kimoto authored on 2010-08-10
29
my $SELECT_SOURCES = {
removed register_format()
yuki-kimoto authored on 2010-05-26
30
    0 => 'select * from table1;'
31
};
32

            
33
my $DROP_TABLE = {
34
    0 => 'drop table table1'
35
};
36

            
37
my $NEW_ARGS = {
38
    0 => {data_source => 'dbi:SQLite:dbname=:memory:'}
39
};
40

            
41
# Variables
42
my $dbi;
43
my $sth;
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
44
my $source;
45
my @sources;
add tests
yuki-kimoto authored on 2010-08-10
46
my $select_SOURCE;
47
my $insert_SOURCE;
48
my $update_SOURCE;
removed register_format()
yuki-kimoto authored on 2010-05-26
49
my $params;
50
my $sql;
51
my $result;
52
my $row;
53
my @rows;
54
my $rows;
55
my $query;
56
my @queries;
57
my $select_query;
58
my $insert_query;
59
my $update_query;
60
my $ret_val;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
61
my $infos;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
62
my $table;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
63
my $where;
removed register_format()
yuki-kimoto authored on 2010-05-26
64

            
65
# Prepare table
66
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
67
$dbi->execute($CREATE_TABLE->{0});
68
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
69
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
70

            
71
test 'DBIx::Custom::Result test';
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
72
$source = "select key1, key2 from table1";
73
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
74
$result = $dbi->execute($query);
75

            
76
@rows = ();
77
while (my $row = $result->fetch) {
78
    push @rows, [@$row];
79
}
cleanup
Yuki Kimoto authored on 2011-01-23
80
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
removed register_format()
yuki-kimoto authored on 2010-05-26
81

            
82
$result = $dbi->execute($query);
83
@rows = ();
84
while (my $row = $result->fetch_hash) {
85
    push @rows, {%$row};
86
}
cleanup
Yuki Kimoto authored on 2011-01-23
87
is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "fetch_hash");
removed register_format()
yuki-kimoto authored on 2010-05-26
88

            
89
$result = $dbi->execute($query);
90
$rows = $result->fetch_all;
cleanup
Yuki Kimoto authored on 2011-01-23
91
is_deeply($rows, [[1, 2], [3, 4]], "fetch_all");
removed register_format()
yuki-kimoto authored on 2010-05-26
92

            
93
$result = $dbi->execute($query);
removed reconnect method
yuki-kimoto authored on 2010-05-28
94
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
95
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "fetch_hash_all");
removed register_format()
yuki-kimoto authored on 2010-05-26
96

            
97
test 'Insert query return value';
98
$dbi->execute($DROP_TABLE->{0});
99
$dbi->execute($CREATE_TABLE->{0});
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
100
$source = "insert into table1 {insert_param key1 key2}";
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
101
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
102
$ret_val = $dbi->execute($query, param => {key1 => 1, key2 => 2});
cleanup
Yuki Kimoto authored on 2011-01-23
103
ok($ret_val);
removed register_format()
yuki-kimoto authored on 2010-05-26
104

            
105

            
106
test 'Direct query';
107
$dbi->execute($DROP_TABLE->{0});
108
$dbi->execute($CREATE_TABLE->{0});
add tests
yuki-kimoto authored on 2010-08-10
109
$insert_SOURCE = "insert into table1 {insert_param key1 key2}";
110
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2});
111
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
112
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
113
is_deeply($rows, [{key1 => 1, key2 => 2}]);
removed register_format()
yuki-kimoto authored on 2010-05-26
114

            
115
test 'Filter basic';
116
$dbi->execute($DROP_TABLE->{0});
117
$dbi->execute($CREATE_TABLE->{0});
118
$dbi->register_filter(twice       => sub { $_[0] * 2}, 
119
                    three_times => sub { $_[0] * 3});
120

            
add tests
yuki-kimoto authored on 2010-08-10
121
$insert_SOURCE  = "insert into table1 {insert_param key1 key2};";
122
$insert_query = $dbi->create_query($insert_SOURCE);
removed register_format()
yuki-kimoto authored on 2010-05-26
123
$insert_query->filter({key1 => 'twice'});
124
$dbi->execute($insert_query, param => {key1 => 1, key2 => 2});
add tests
yuki-kimoto authored on 2010-08-10
125
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
126
$rows = $result->filter({key2 => 'three_times'})->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
127
is_deeply($rows, [{key1 => 2, key2 => 6}], "filter fetch_filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
128
$dbi->execute($DROP_TABLE->{0});
129

            
130
test 'Filter in';
131
$dbi->execute($CREATE_TABLE->{0});
add tests
yuki-kimoto authored on 2010-08-10
132
$insert_SOURCE  = "insert into table1 {insert_param key1 key2};";
133
$insert_query = $dbi->create_query($insert_SOURCE);
removed register_format()
yuki-kimoto authored on 2010-05-26
134
$dbi->execute($insert_query, param => {key1 => 2, key2 => 4});
add tests
yuki-kimoto authored on 2010-08-10
135
$select_SOURCE = "select * from table1 where {in table1.key1 2} and {in table1.key2 2}";
136
$select_query = $dbi->create_query($select_SOURCE);
removed register_format()
yuki-kimoto authored on 2010-05-26
137
$select_query->filter({'table1.key1' => 'twice'});
138
$result = $dbi->execute($select_query, param => {'table1.key1' => [1,5], 'table1.key2' => [2,4]});
139
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
140
is_deeply($rows, [{key1 => 2, key2 => 4}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
141

            
142
test 'DBIx::Custom::SQLTemplate basic tag';
143
$dbi->execute($DROP_TABLE->{0});
144
$dbi->execute($CREATE_TABLE->{1});
145
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
146
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
147

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
148
$source = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};";
149
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
150
$result = $dbi->execute($query, param => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
151
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
152
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag1");
removed register_format()
yuki-kimoto authored on 2010-05-26
153

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
154
$source = "select * from table1 where {<= key1} and {like key2};";
155
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
156
$result = $dbi->execute($query, param => {key1 => 1, key2 => '%2%'});
157
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
158
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag2");
removed register_format()
yuki-kimoto authored on 2010-05-26
159

            
160
test 'DIB::Custom::SQLTemplate in tag';
161
$dbi->execute($DROP_TABLE->{0});
162
$dbi->execute($CREATE_TABLE->{1});
163
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
164
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
165

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
166
$source = "select * from table1 where {in key1 2};";
167
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
168
$result = $dbi->execute($query, param => {key1 => [9, 1]});
169
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
170
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
171

            
172
test 'DBIx::Custom::SQLTemplate insert tag';
173
$dbi->execute("delete from table1");
add tests
yuki-kimoto authored on 2010-08-10
174
$insert_SOURCE = 'insert into table1 {insert_param key1 key2 key3 key4 key5}';
175
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
removed register_format()
yuki-kimoto authored on 2010-05-26
176

            
add tests
yuki-kimoto authored on 2010-08-10
177
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
178
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
179
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
180

            
181
test 'DBIx::Custom::SQLTemplate update tag';
182
$dbi->execute("delete from table1");
add tests
yuki-kimoto authored on 2010-08-10
183
$insert_SOURCE = "insert into table1 {insert_param key1 key2 key3 key4 key5}";
184
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
185
$dbi->execute($insert_SOURCE, param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
removed register_format()
yuki-kimoto authored on 2010-05-26
186

            
add tests
yuki-kimoto authored on 2010-08-10
187
$update_SOURCE = 'update table1 {update_param key1 key2 key3 key4} where {= key5}';
188
$dbi->execute($update_SOURCE, param => {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5});
removed register_format()
yuki-kimoto authored on 2010-05-26
189

            
add tests
yuki-kimoto authored on 2010-08-10
190
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
191
$rows = $result->fetch_hash_all;
192
is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5},
cleanup
Yuki Kimoto authored on 2011-01-23
193
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
194

            
195
test 'Error case';
196
eval {DBIx::Custom->connect(data_source => 'dbi:SQLit')};
cleanup
Yuki Kimoto authored on 2011-01-23
197
ok($@, "connect error");
removed register_format()
yuki-kimoto authored on 2010-05-26
198

            
199
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
200
eval{$dbi->create_query("{p }")};
cleanup
Yuki Kimoto authored on 2011-01-23
201
ok($@, "create_query invalid SQL template");
removed register_format()
yuki-kimoto authored on 2010-05-26
202

            
203
test 'insert';
204
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
205
$dbi->execute($CREATE_TABLE->{0});
206
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
207
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
add tests
yuki-kimoto authored on 2010-08-10
208
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
209
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
210
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
211

            
212
$dbi->execute('delete from table1');
213
$dbi->register_filter(
214
    twice       => sub { $_[0] * 2 },
215
    three_times => sub { $_[0] * 3 }
216
);
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
217
$dbi->default_bind_filter('twice');
removed register_format()
yuki-kimoto authored on 2010-05-26
218
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => 'three_times'});
add tests
yuki-kimoto authored on 2010-08-10
219
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
220
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
221
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
222
$dbi->default_bind_filter(undef);
removed register_format()
yuki-kimoto authored on 2010-05-26
223

            
224
$dbi->execute($DROP_TABLE->{0});
225
$dbi->execute($CREATE_TABLE->{0});
226
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, append => '   ');
227
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
228
is_deeply($rows, [{key1 => 1, key2 => 2}], 'insert append');
229

            
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
230
eval{$dbi->insert(table => 'table1', noexist => 1)};
cleanup
Yuki Kimoto authored on 2011-01-23
231
like($@, qr/noexist/, "invalid argument");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
232

            
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
233
eval{$dbi->insert(table => 'table', param => {';' => 1})};
234
like($@, qr/safety/);
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
235

            
removed register_format()
yuki-kimoto authored on 2010-05-26
236
test 'update';
237
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
238
$dbi->execute($CREATE_TABLE->{1});
239
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
240
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
241
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
242
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
243
$rows   = $result->fetch_hash_all;
244
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
245
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
246
                  "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
247
                  
248
$dbi->execute("delete from table1");
249
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
250
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
251
$dbi->update(table => 'table1', param => {key2 => 12}, where => {key2 => 2, key3 => 3});
add tests
yuki-kimoto authored on 2010-08-10
252
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
253
$rows   = $result->fetch_hash_all;
254
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
255
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
256
                  "update key same as search key");
removed register_format()
yuki-kimoto authored on 2010-05-26
257

            
add tests
yuki-kimoto authored on 2010-08-10
258
$dbi->update(table => 'table1', param => {key2 => [12]}, where => {key2 => 2, key3 => 3});
259
$result = $dbi->execute($SELECT_SOURCES->{0});
260
$rows   = $result->fetch_hash_all;
261
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
262
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
263
                  "update key same as search key : param is array ref");
add tests
yuki-kimoto authored on 2010-08-10
264

            
removed register_format()
yuki-kimoto authored on 2010-05-26
265
$dbi->execute("delete from table1");
266
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
267
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
268
$dbi->register_filter(twice => sub { $_[0] * 2 });
269
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1},
many changed
Yuki Kimoto authored on 2011-01-23
270
              filter => {key2 => sub { $_[0] * 2 }});
add tests
yuki-kimoto authored on 2010-08-10
271
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
272
$rows   = $result->fetch_hash_all;
273
is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5},
274
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
275
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
276

            
277
$result = $dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1}, append => '   ');
278

            
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
279
eval{$dbi->update(table => 'table1', noexist => 1)};
cleanup
Yuki Kimoto authored on 2011-01-23
280
like($@, qr/noexist/, "invalid argument");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
281

            
282
eval{$dbi->update(table => 'table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
283
like($@, qr/where/, "not contain where");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
284

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
285
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
286
$dbi->execute($CREATE_TABLE->{0});
287
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
288
$where = $dbi->where;
289
$where->clause(['and', '{= key1}', '{= key2}']);
290
$where->param({key1 => 1, key2 => 2});
291
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
292
$result = $dbi->select(table => 'table1');
293
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'delete() where');
294

            
295
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
296
$dbi->execute($CREATE_TABLE->{0});
297
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
298
$where = $dbi->where;
299
$where->clause(['and', '{= key2}']);
300
$where->param({key2 => 2});
301
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
302
$result = $dbi->select(table => 'table1');
303
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'delete() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
304

            
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
305
eval{$dbi->update(table => 'table1', param => {';' => 1})};
306
like($@, qr/safety/);
307

            
308
eval{$dbi->update(table => 'table1', param => {'key1' => 1}, where => {';' => 1})};
309
like($@, qr/safety/);
310

            
removed register_format()
yuki-kimoto authored on 2010-05-26
311
test 'update_all';
312
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
313
$dbi->execute($CREATE_TABLE->{1});
314
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
315
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
316
$dbi->register_filter(twice => sub { $_[0] * 2 });
317
$dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
318
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
319
$rows   = $result->fetch_hash_all;
320
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
321
                  {key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
322
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
323

            
324

            
325
test 'delete';
326
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
327
$dbi->execute($CREATE_TABLE->{0});
328
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
329
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
330
$dbi->delete(table => 'table1', where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
331
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
332
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
333
is_deeply($rows, [{key1 => 3, key2 => 4}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
334

            
335
$dbi->execute("delete from table1;");
336
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
337
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
338
$dbi->register_filter(twice => sub { $_[0] * 2 });
339
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
340
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
341
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
342
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
343

            
344
$dbi->delete(table => 'table1', where => {key1 => 1}, append => '   ');
345

            
346
$dbi->delete_all(table => 'table1');
347
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
348
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
349
$dbi->delete(table => 'table1', where => {key1 => 1, key2 => 2});
350
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
351
is_deeply($rows, [{key1 => 3, key2 => 4}], "delete multi key");
removed register_format()
yuki-kimoto authored on 2010-05-26
352

            
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
353
eval{$dbi->delete(table => 'table1', noexist => 1)};
cleanup
Yuki Kimoto authored on 2011-01-23
354
like($@, qr/noexist/, "invalid argument");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
355

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
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->insert(table => 'table1', param => {key1 => 3, key2 => 4});
360
$where = $dbi->where;
361
$where->clause(['and', '{= key1}', '{= key2}']);
362
$where->param({ke1 => 1, key2 => 2});
363
$dbi->delete(table => 'table1', where => $where);
364
$result = $dbi->select(table => 'table1');
365
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 4}], 'delete() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
366

            
removed register_format()
yuki-kimoto authored on 2010-05-26
367
test 'delete error';
368
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
369
$dbi->execute($CREATE_TABLE->{0});
370
eval{$dbi->delete(table => 'table1')};
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
371
like($@, qr/"where" must be specified/,
cleanup
Yuki Kimoto authored on 2011-01-23
372
         "where key-value pairs not specified");
removed register_format()
yuki-kimoto authored on 2010-05-26
373

            
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
374
eval{$dbi->delete(table => 'table1', where => {';' => 1})};
375
like($@, qr/safety/);
376

            
removed register_format()
yuki-kimoto authored on 2010-05-26
377
test 'delete_all';
378
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
379
$dbi->execute($CREATE_TABLE->{0});
380
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
381
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
382
$dbi->delete_all(table => 'table1');
add tests
yuki-kimoto authored on 2010-08-10
383
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
384
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
385
is_deeply($rows, [], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
386

            
387

            
388
test 'select';
389
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
390
$dbi->execute($CREATE_TABLE->{0});
391
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
392
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
393
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
394
is_deeply($rows, [{key1 => 1, key2 => 2},
cleanup
Yuki Kimoto authored on 2011-01-23
395
                  {key1 => 3, key2 => 4}], "table");
removed register_format()
yuki-kimoto authored on 2010-05-26
396

            
update document
yuki-kimoto authored on 2010-05-27
397
$rows = $dbi->select(table => 'table1', column => ['key1'])->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
398
is_deeply($rows, [{key1 => 1}, {key1 => 3}], "table and columns and where key");
removed register_format()
yuki-kimoto authored on 2010-05-26
399

            
400
$rows = $dbi->select(table => 'table1', where => {key1 => 1})->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
401
is_deeply($rows, [{key1 => 1, key2 => 2}], "table and columns and where key");
removed register_format()
yuki-kimoto authored on 2010-05-26
402

            
update document
yuki-kimoto authored on 2010-05-27
403
$rows = $dbi->select(table => 'table1', column => ['key1'], where => {key1 => 3})->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
404
is_deeply($rows, [{key1 => 3}], "table and columns and where key");
removed register_format()
yuki-kimoto authored on 2010-05-26
405

            
406
$rows = $dbi->select(table => 'table1', append => "order by key1 desc limit 1")->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
407
is_deeply($rows, [{key1 => 3, key2 => 4}], "append statement");
removed register_format()
yuki-kimoto authored on 2010-05-26
408

            
409
$dbi->register_filter(decrement => sub { $_[0] - 1 });
update document
yuki-kimoto authored on 2010-05-27
410
$rows = $dbi->select(table => 'table1', where => {key1 => 2}, filter => {key1 => 'decrement'})
removed register_format()
yuki-kimoto authored on 2010-05-26
411
            ->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
412
is_deeply($rows, [{key1 => 1, key2 => 2}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
413

            
414
$dbi->execute($CREATE_TABLE->{2});
415
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
416
$rows = $dbi->select(
417
    table => [qw/table1 table2/],
update document
yuki-kimoto authored on 2010-05-27
418
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
removed register_format()
yuki-kimoto authored on 2010-05-26
419
    where   => {'table1.key2' => 2},
added commit method
yuki-kimoto authored on 2010-05-27
420
    relation  => {'table1.key1' => 'table2.key1'}
removed register_format()
yuki-kimoto authored on 2010-05-26
421
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
422
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "relation : exists where");
added commit method
yuki-kimoto authored on 2010-05-27
423

            
424
$rows = $dbi->select(
425
    table => [qw/table1 table2/],
426
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
427
    relation  => {'table1.key1' => 'table2.key1'}
428
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
429
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "relation : no exists where");
removed register_format()
yuki-kimoto authored on 2010-05-26
430

            
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
431
eval{$dbi->select(table => 'table1', noexist => 1)};
cleanup
Yuki Kimoto authored on 2011-01-23
432
like($@, qr/noexist/, "invalid argument");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
433

            
434

            
removed register_format()
yuki-kimoto authored on 2010-05-26
435
test 'fetch filter';
436
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
437
$dbi->register_filter(
438
    twice       => sub { $_[0] * 2 },
439
    three_times => sub { $_[0] * 3 }
440
);
441
$dbi->default_fetch_filter('twice');
442
$dbi->execute($CREATE_TABLE->{0});
443
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
444
$result = $dbi->select(table => 'table1');
445
$result->filter({key1 => 'three_times'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
446
$row = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
447
is_deeply($row, {key1 => 3, key2 => 4}, "default_fetch_filter and filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
448

            
449
test 'filters';
450
$dbi = DBIx::Custom->new;
451

            
update document
yuki-kimoto authored on 2010-05-27
452
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
cleanup
Yuki Kimoto authored on 2011-01-23
453
   'あ', "decode_utf8");
removed register_format()
yuki-kimoto authored on 2010-05-26
454

            
455
is($dbi->filters->{encode_utf8}->('あ'),
cleanup
Yuki Kimoto authored on 2011-01-23
456
   encode_utf8('あ'), "encode_utf8");
removed register_format()
yuki-kimoto authored on 2010-05-26
457

            
added commit method
yuki-kimoto authored on 2010-05-27
458
test 'transaction';
459
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
460
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
461
$dbi->dbh->begin_work;
added commit method
yuki-kimoto authored on 2010-05-27
462
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
463
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
464
$dbi->dbh->commit;
added commit method
yuki-kimoto authored on 2010-05-27
465
$result = $dbi->select(table => 'table1');
466
is_deeply(scalar $result->fetch_hash_all, [{key1 => 1, key2 => 2}, {key1 => 2, key2 => 3}],
cleanup
Yuki Kimoto authored on 2011-01-23
467
          "commit");
added commit method
yuki-kimoto authored on 2010-05-27
468

            
469
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
470
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
471
$dbi->dbh->begin_work(0);
added commit method
yuki-kimoto authored on 2010-05-27
472
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
473
$dbi->dbh->rollback;
added commit method
yuki-kimoto authored on 2010-05-27
474

            
475
$result = $dbi->select(table => 'table1');
cleanup
Yuki Kimoto authored on 2011-01-23
476
ok(! $result->fetch_first, "rollback");
add cache attribute
yuki-kimoto authored on 2010-06-14
477

            
478
test 'cache';
479
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
480
$dbi->execute($CREATE_TABLE->{0});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
481
$source = 'select * from table1 where {= key1} and {= key2};';
482
$dbi->create_query($source);
483
is_deeply($dbi->{_cached}->{$source}, 
cleanup
Yuki Kimoto authored on 2011-01-23
484
          {sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2']}, "cache");
add cache attribute
yuki-kimoto authored on 2010-06-14
485

            
486
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
487
$dbi->execute($CREATE_TABLE->{0});
488
$dbi->{_cached} = {};
489
$dbi->cache(0);
490
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
491
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
492

            
add tests
yuki-kimoto authored on 2010-08-10
493
test 'execute';
494
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
495
$dbi->execute($CREATE_TABLE->{0});
removed experimental registe...
yuki-kimoto authored on 2010-08-24
496
{
497
    local $Carp::Verbose = 0;
498
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
499
    like($@, qr/\Qselect * frm table1;/, "fail prepare");
500
    like($@, qr/\.t /, "fail : not verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
501
}
502
{
503
    local $Carp::Verbose = 1;
504
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
505
    like($@, qr/Custom.*\.t /s, "fail : verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
506
}
add tests
yuki-kimoto authored on 2010-08-10
507

            
508
eval{$dbi->execute('select * from table1', no_exists => 1)};
cleanup
Yuki Kimoto authored on 2011-01-23
509
like($@, qr/\Q"no_exists" is invalid argument/, "invald SQL");
add tests
yuki-kimoto authored on 2010-08-10
510

            
511
$query = $dbi->create_query('select * from table1 where {= key1}');
512
$dbi->dbh->disconnect;
513
eval{$dbi->execute($query, param => {key1 => {a => 1}})};
cleanup
Yuki Kimoto authored on 2011-01-23
514
ok($@, "execute fail");
add tests
yuki-kimoto authored on 2010-08-10
515

            
removed experimental registe...
yuki-kimoto authored on 2010-08-24
516
{
517
    local $Carp::Verbose = 0;
518
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
cleanup
Yuki Kimoto authored on 2011-01-23
519
    like($@, qr/\Q.t /, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
520
}
521
{
522
    local $Carp::Verbose = 1;
523
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
cleanup
Yuki Kimoto authored on 2011-01-23
524
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
525
}
cleanup
yuki-kimoto authored on 2010-10-17
526

            
527

            
528
test 'transaction';
529
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
530
$dbi->execute($CREATE_TABLE->{0});
531

            
532
$dbi->begin_work;
533

            
534
eval {
535
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
536
    die "Error";
537
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
538
};
539

            
540
$dbi->rollback if $@;
541

            
542
$result = $dbi->select(table => 'table1');
543
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
544
is_deeply($rows, [], "rollback");
cleanup
yuki-kimoto authored on 2010-10-17
545

            
546
$dbi->begin_work;
547

            
548
eval {
549
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
550
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
551
};
552

            
553
$dbi->commit unless $@;
554

            
555
$result = $dbi->select(table => 'table1');
556
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
557
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "commit");
cleanup
yuki-kimoto authored on 2010-10-17
558

            
559
$dbi->dbh->{AutoCommit} = 0;
560
eval{ $dbi->begin_work };
cleanup
Yuki Kimoto authored on 2011-01-23
561
ok($@, "exception");
cleanup
yuki-kimoto authored on 2010-10-17
562
$dbi->dbh->{AutoCommit} = 1;
563

            
added helper method
yuki-kimoto authored on 2010-10-17
564

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
565
test 'method';
added helper method
yuki-kimoto authored on 2010-10-17
566
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
567
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
568
    one => sub { 1 }
569
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
570
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
571
    two => sub { 2 }
572
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
573
$dbi->method({
added helper method
yuki-kimoto authored on 2010-10-17
574
    twice => sub {
575
        my $self = shift;
576
        return $_[0] * 2;
577
    }
578
});
579

            
cleanup
Yuki Kimoto authored on 2011-01-23
580
is($dbi->one, 1, "first");
581
is($dbi->two, 2, "second");
582
is($dbi->twice(5), 10 , "second");
added helper method
yuki-kimoto authored on 2010-10-17
583

            
584
eval {$dbi->XXXXXX};
autoload DBI method
Yuki Kimoto authored on 2011-01-26
585
ok($@, "not exists");
added helper method
yuki-kimoto authored on 2010-10-17
586

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
587
test 'out filter';
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
588
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
589
$dbi->execute($CREATE_TABLE->{0});
590
$dbi->register_filter(twice => sub { $_[0] * 2 });
591
$dbi->register_filter(three_times => sub { $_[0] * 3});
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
592
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
593
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
594
              'key2' => {out => 'three_times', in => 'twice'});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
595
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
596
$result = $dbi->execute($SELECT_SOURCES->{0});
597
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
598
is_deeply($row, {key1 => 2, key2 => 6}, "insert");
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
599
$result = $dbi->select(table => 'table1');
600
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
601
is_deeply($row, {key1 => 6, key2 => 12}, "insert");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
602

            
603
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
604
$dbi->execute($CREATE_TABLE->{0});
605
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
606
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
607
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
608
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
609
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => undef});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
610
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2});
611
$result = $dbi->execute($SELECT_SOURCES->{0});
612
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
613
is_deeply($row, {key1 => 4, key2 => 2}, "update");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
614

            
615
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
616
$dbi->execute($CREATE_TABLE->{0});
617
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
618
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
619
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
620
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
621
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1=> undef});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
622
$dbi->delete(table => 'table1', where => {key1 => 1});
623
$result = $dbi->execute($SELECT_SOURCES->{0});
624
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
625
is_deeply($rows, [], "delete");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
626

            
627
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
628
$dbi->execute($CREATE_TABLE->{0});
629
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
630
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
631
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
632
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
633
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
634
$result = $dbi->select(table => 'table1', where => {key1 => 1});
635
$result->filter({'key2' => 'twice'});
636
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
637
is_deeply($rows, [{key1 => 4, key2 => 4}], "select");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
638

            
639
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
640
$dbi->execute($CREATE_TABLE->{0});
641
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
642
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
643
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
644
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
645
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
646
$result = $dbi->execute("select * from table1 where {= key1} and {= key2};",
647
                        param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
648
                        table => ['table1']);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
649
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
650
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
651

            
652
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
653
$dbi->execute($CREATE_TABLE->{0});
654
$dbi->execute($CREATE_TABLE->{2});
655
$dbi->register_filter(twice => sub { $_[0] * 2 });
656
$dbi->register_filter(three_times => sub { $_[0] * 3 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
657
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
658
    'table1', 'key2' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
659
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
660
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
661
    'table2', 'key3' => {out => 'three_times', in => 'three_times'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
662
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
663
$dbi->insert(table => 'table1', param => {key1 => 5, key2 => 2}, filter => {key2 => undef});
664
$dbi->insert(table => 'table2', param => {key1 => 5, key3 => 6}, filter => {key3 => undef});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
665
$result = $dbi->select(
666
     table => ['table1', 'table2'],
667
     column => ['key2', 'key3'],
668
     where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
669

            
670
$result->filter({'key2' => 'twice'});
671
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
672
is_deeply($rows, [{key2 => 4, key3 => 18}], "select : join");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
673

            
674
$result = $dbi->select(
675
     table => ['table1', 'table2'],
676
     column => ['key2', 'key3'],
677
     where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
678

            
679
$result->filter({'key2' => 'twice'});
680
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
681
is_deeply($rows, [{key2 => 4, key3 => 18}], "select : join : omit");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
682

            
pod fix
Yuki Kimoto authored on 2011-01-21
683
test 'each_column';
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
684
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
685
$dbi->execute($CREATE_TABLE->{2});
686
$dbi->execute($CREATE_TABLE->{3});
687

            
688
$infos = [];
pod fix
Yuki Kimoto authored on 2011-01-21
689
$dbi->each_column(sub {
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
690
    my ($self, $table, $column, $cinfo) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
691
    
692
    if ($table =~ /^table/) {
693
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
694
         push @$infos, $info;
695
    }
696
});
697
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
698
is_deeply($infos, 
699
    [
700
        ['table1', 'key1', 'key1'],
701
        ['table1', 'key2', 'key2'],
702
        ['table2', 'key1', 'key1'],
703
        ['table2', 'key3', 'key3']
704
    ]
cleanup
Yuki Kimoto authored on 2011-01-23
705
    
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
706
);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
707

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
708
test 'table';
709
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
710
$dbi->execute($CREATE_TABLE->{0});
711
$table = $dbi->table('table1');
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
712
$table->insert(param => {key1 => 1, key2 => 2});
713
$table->insert(param => {key1 => 3, key2 => 4});
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
714
$rows = $table->select->fetch_hash_all;
715
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}],
cleanup
Yuki Kimoto authored on 2011-01-23
716
                 "select");
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
717
$rows = $table->select(where => {key2 => 2}, append => 'order by key1',
718
                              column => ['key1', 'key2'])->fetch_hash_all;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
719
is_deeply($rows, [{key1 => 1, key2 => 2}],
cleanup
Yuki Kimoto authored on 2011-01-23
720
                 "insert insert select");
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
721
$table->update(param => {key1 => 3}, where => {key2 => 2});
722
$table->update(param => {key1 => 5}, where => {key2 => 4});
723
$rows = $table->select(where => {key2 => 2})->fetch_hash_all;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
724
is_deeply($rows, [{key1 => 3, key2 => 2}],
cleanup
Yuki Kimoto authored on 2011-01-23
725
                 "update");
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
726
$table->delete(where => {key2 => 2});
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
727
$rows = $table->select->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
728
is_deeply($rows, [{key1 => 5, key2 => 4}], "delete");
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
729
$table->update_all(param => {key1 => 3});
730
$rows = $table->select->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
731
is_deeply($rows, [{key1 => 3, key2 => 4}], "update_all");
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
732
$table->delete_all;
733
$rows = $table->select->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
734
is_deeply($rows, [], "delete_all");
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
735

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
736
$dbi->dbh->do($CREATE_TABLE->{2});
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
737
$dbi->table('table2')->method(
738
    ppp => sub {
739
        my $self = shift;
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
740
    
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
741
        return $self->name;
742
    }
743
);
744
is($dbi->table('table2')->ppp, 'table2', "method");
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
745

            
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
746
$dbi->table('table2')->method({
747
    qqq => sub {
748
        my $self = shift;
many changed
Yuki Kimoto authored on 2011-01-23
749
    
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
750
        return $self->name;
751
    }
752
});
753
is($dbi->table('table2')->qqq, 'table2', "method");
many changed
Yuki Kimoto authored on 2011-01-23
754

            
755

            
add examples
Yuki Kimoto authored on 2011-01-07
756
test 'limit';
757
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
758
$dbi->execute($CREATE_TABLE->{0});
759
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
760
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4});
761
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
762
$dbi->register_tag(
add examples
Yuki Kimoto authored on 2011-01-07
763
    limit => sub {
764
        my ($count, $offset) = @_;
765
        
766
        my $s = '';
767
        $s .= "limit $count";
768
        $s .= " offset $offset" if defined $offset;
769
        
770
        return [$s, []];
771
    }
772
);
773
$rows = $dbi->select(
774
  table => 'table1',
775
  where => {key1 => 1},
776
  append => "order by key2 {limit 1 0}"
777
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
778
is_deeply($rows, [{key1 => 1, key2 => 2}]);
add examples
Yuki Kimoto authored on 2011-01-07
779
$rows = $dbi->select(
780
  table => 'table1',
781
  where => {key1 => 1},
782
  append => "order by key2 {limit 2 1}"
783
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
784
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]);
add examples
Yuki Kimoto authored on 2011-01-07
785
$rows = $dbi->select(
786
  table => 'table1',
787
  where => {key1 => 1},
788
  append => "order by key2 {limit 1}"
789
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
790
is_deeply($rows, [{key1 => 1, key2 => 2}]);
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
791

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
792
test 'connect super';
793
{
794
    package MyDBI;
795
    
796
    use base 'DBIx::Custom';
797
    sub connect {
798
        my $self = shift->SUPER::connect(@_);
799
        
800
        return $self;
801
    }
802
    
803
    sub new {
cleanup
Yuki Kimoto authored on 2011-01-25
804
        my $self = shift->SUPER::new(@_);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
805
        
806
        return $self;
807
    }
808
}
809

            
810
$dbi = MyDBI->connect($NEW_ARGS->{0});
811
$dbi->execute($CREATE_TABLE->{0});
812
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
cleanup
Yuki Kimoto authored on 2011-01-23
813
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
814

            
815
$dbi = MyDBI->new($NEW_ARGS->{0});
cleanup
Yuki Kimoto authored on 2011-01-25
816
$dbi->connect;
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
817
$dbi->execute($CREATE_TABLE->{0});
818
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
cleanup
Yuki Kimoto authored on 2011-01-23
819
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
820

            
cleanup
Yuki Kimoto authored on 2011-01-25
821
{
822
    package MyDBI2;
823
    
824
    use base 'DBIx::Custom';
825
    sub connect {
826
        my $self = shift->SUPER::new(@_);
827
        $self->connect;
828
        
829
        return $self;
830
    }
831
}
832

            
833
$dbi = MyDBI->connect($NEW_ARGS->{0});
834
$dbi->execute($CREATE_TABLE->{0});
835
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
836
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
837

            
838
test 'end_filter';
839
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
840
$dbi->execute($CREATE_TABLE->{0});
841
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
842
$result = $dbi->select(table => 'table1');
843
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
844
$result->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 });
845
$row = $result->fetch_first;
846
is_deeply($row, [6, 40]);
847

            
many changed
Yuki Kimoto authored on 2011-01-23
848
$dbi->register_filter(five_times => sub { $_[0] * 5 });
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
849
$result = $dbi->select(table => 'table1');
850
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
many changed
Yuki Kimoto authored on 2011-01-23
851
$result->end_filter({key1 => sub { $_[0] * 3 }, key2 => 'five_times' });
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
852
$row = $result->fetch_hash_first;
853
is_deeply($row, {key1 => 6, key2 => 40});
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
854

            
855

            
856
test 'empty where select';
857
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
858
$dbi->execute($CREATE_TABLE->{0});
859
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
860
$result = $dbi->select(table => 'table1', where => {});
861
$row = $result->fetch_hash_first;
862
is_deeply($row, {key1 => 1, key2 => 2});
863

            
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
864
test 'select query option';
865
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
866
$dbi->execute($CREATE_TABLE->{0});
867
$query = $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, query => 1);
868
is(ref $query, 'DBIx::Custom::Query');
869
$query = $dbi->update(table => 'table1', where => {key1 => 1}, param => {key2 => 2}, query => 1);
870
is(ref $query, 'DBIx::Custom::Query');
871
$query = $dbi->delete(table => 'table1', where => {key1 => 1}, query => 1);
872
is(ref $query, 'DBIx::Custom::Query');
873
$query = $dbi->select(table => 'table1', where => {key1 => 1, key2 => 2}, query => 1);
874
is(ref $query, 'DBIx::Custom::Query');
875

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
876
test 'DBIx::Custom::Where';
experimental extended select...
Yuki Kimoto authored on 2011-01-17
877
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
878
$dbi->execute($CREATE_TABLE->{0});
879
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
880
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
881
$where = $dbi->where->clause(['and', '{= key1}', '{= key2}']);
882
is("$where", "where ( {= key1} and {= key2} )", 'no param');
883

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
884
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
885
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
886
             ->param({key1 => 1});
added test
Yuki Kimoto authored on 2011-01-19
887

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
888
$result = $dbi->select(
889
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
890
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
891
);
892
$row = $result->fetch_hash_all;
893
is_deeply($row, [{key1 => 1, key2 => 2}]);
894

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
895
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
896
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
897
             ->param({key1 => 1, key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
898
$result = $dbi->select(
899
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
900
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
901
);
902
$row = $result->fetch_hash_all;
903
is_deeply($row, [{key1 => 1, key2 => 2}]);
904

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
905
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
906
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
907
             ->param({});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
908
$result = $dbi->select(
909
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
910
    where => $where,
experimental extended select...
Yuki Kimoto authored on 2011-01-17
911
);
912
$row = $result->fetch_hash_all;
913
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
914

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
915
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
916
             ->clause(['and', ['or', '{> key1}', '{< key1}'], '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
917
             ->param({key1 => [0, 3], key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
918
$result = $dbi->select(
919
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
920
    where => $where,
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
921
); 
experimental extended select...
Yuki Kimoto authored on 2011-01-17
922
$row = $result->fetch_hash_all;
923
is_deeply($row, [{key1 => 1, key2 => 2}]);
924

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
925
$where = $dbi->where;
926
$result = $dbi->select(
927
    table => 'table1',
928
    where => $where
929
);
930
$row = $result->fetch_hash_all;
931
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
932

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
933
eval {
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
934
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
935
             ->clause(['uuu']);
experimental extended select...
Yuki Kimoto authored on 2011-01-17
936
$result = $dbi->select(
937
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
938
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
939
);
940
};
941
ok($@);
942

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
943
$where = $dbi->where;
944
is("$where", '');
945

            
added test
Yuki Kimoto authored on 2011-01-19
946
$where = $dbi->where
947
             ->clause(['or', ('{= key1}') x 2])
948
             ->param({key1 => [1, 3]});
949
$result = $dbi->select(
950
    table => 'table1',
951
    where => $where,
952
);
953
$row = $result->fetch_hash_all;
954
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
955

            
956
$where = $dbi->where
957
             ->clause(['or', ('{= key1}') x 2])
958
             ->param({key1 => [1]});
959
$result = $dbi->select(
960
    table => 'table1',
961
    where => $where,
962
);
963
$row = $result->fetch_hash_all;
964
is_deeply($row, [{key1 => 1, key2 => 2}]);
965

            
966
$where = $dbi->where
967
             ->clause(['or', ('{= key1}') x 2])
968
             ->param({key1 => 1});
969
$result = $dbi->select(
970
    table => 'table1',
971
    where => $where,
972
);
973
$row = $result->fetch_hash_all;
974
is_deeply($row, [{key1 => 1, key2 => 2}]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
975

            
many changed
Yuki Kimoto authored on 2011-01-23
976
$where = $dbi->where
977
             ->clause('{= key1}')
978
             ->param({key1 => 1});
979
$result = $dbi->select(
980
    table => 'table1',
981
    where => $where,
982
);
983
$row = $result->fetch_hash_all;
984
is_deeply($row, [{key1 => 1, key2 => 2}]);
985

            
986
$where = $dbi->where
987
             ->clause('{= key1} {= key2}')
988
             ->param({key1 => 1});
989
eval{$where->to_string};
990
like($@, qr/one column/);
991

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
992
$where = $dbi->where
993
             ->clause('{= key1}')
994
             ->param([]);
995
eval{$where->to_string};
996
like($@, qr/Parameter/);
997

            
998
$where = $dbi->where
999
             ->clause(['or', ('{= key1}') x 3])
1000
             ->param({key1 => [$dbi->not_exists, 1, 3]});
1001
$result = $dbi->select(
1002
    table => 'table1',
1003
    where => $where,
1004
);
1005
$row = $result->fetch_hash_all;
1006
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1007

            
1008
$where = $dbi->where
1009
             ->clause(['or', ('{= key1}') x 3])
1010
             ->param({key1 => [1, $dbi->not_exists, 3]});
1011
$result = $dbi->select(
1012
    table => 'table1',
1013
    where => $where,
1014
);
1015
$row = $result->fetch_hash_all;
1016
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1017

            
1018
$where = $dbi->where
1019
             ->clause(['or', ('{= key1}') x 3])
1020
             ->param({key1 => [1, 3, $dbi->not_exists]});
1021
$result = $dbi->select(
1022
    table => 'table1',
1023
    where => $where,
1024
);
1025
$row = $result->fetch_hash_all;
1026
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1027

            
1028
$where = $dbi->where
1029
             ->clause(['or', ('{= key1}') x 3])
1030
             ->param({key1 => [1, $dbi->not_exists, $dbi->not_exists]});
1031
$result = $dbi->select(
1032
    table => 'table1',
1033
    where => $where,
1034
);
1035
$row = $result->fetch_hash_all;
1036
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1037

            
1038
$where = $dbi->where
1039
             ->clause(['or', ('{= key1}') x 3])
1040
             ->param({key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
1041
$result = $dbi->select(
1042
    table => 'table1',
1043
    where => $where,
1044
);
1045
$row = $result->fetch_hash_all;
1046
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1047

            
1048
$where = $dbi->where
1049
             ->clause(['or', ('{= key1}') x 3])
1050
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
1051
$result = $dbi->select(
1052
    table => 'table1',
1053
    where => $where,
1054
);
1055
$row = $result->fetch_hash_all;
1056
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1057

            
1058
$where = $dbi->where
1059
             ->clause(['or', ('{= key1}') x 3])
1060
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]});
1061
$result = $dbi->select(
1062
    table => 'table1',
1063
    where => $where,
1064
);
1065
$row = $result->fetch_hash_all;
1066
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1067

            
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1068
$where = $dbi->where
1069
             ->clause(['or', ('{= key1}') x 3])
1070
             ->param({key1 => []});
1071
$result = $dbi->select(
1072
    table => 'table1',
1073
    where => $where,
1074
);
1075
$row = $result->fetch_hash_all;
1076
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1077

            
1078
$where = $dbi->where
1079
             ->clause(['and', '{> key1}', '{< key1}' ])
1080
             ->param({key1 => [2, $dbi->not_exists]});
1081
$result = $dbi->select(
1082
    table => 'table1',
1083
    where => $where,
1084
);
1085
$row = $result->fetch_hash_all;
1086
is_deeply($row, [{key1 => 3, key2 => 4}], 'not_exists');
1087

            
1088
$where = $dbi->where
1089
             ->clause(['and', '{> key1}', '{< key1}' ])
1090
             ->param({key1 => [$dbi->not_exists, 2]});
1091
$result = $dbi->select(
1092
    table => 'table1',
1093
    where => $where,
1094
);
1095
$row = $result->fetch_hash_all;
1096
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1097

            
1098
$where = $dbi->where
1099
             ->clause(['and', '{> key1}', '{< key1}' ])
1100
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists]});
1101
$result = $dbi->select(
1102
    table => 'table1',
1103
    where => $where,
1104
);
1105
$row = $result->fetch_hash_all;
1106
is_deeply($row, [{key1 => 1, key2 => 2},{key1 => 3, key2 => 4}], 'not_exists');
1107

            
1108
$where = $dbi->where
1109
             ->clause(['and', '{> key1}', '{< key1}' ])
1110
             ->param({key1 => [0, 2]});
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}], 'not_exists');
1117

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1118
test 'dbi_option default';
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1119
$dbi = DBIx::Custom->new;
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1120
is_deeply($dbi->dbi_option, {});
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1121

            
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1122
test 'register_tag_processor';
1123
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1124
$dbi->register_tag_processor(
1125
    a => sub { 1 }
1126
);
1127
is($dbi->query_builder->tag_processors->{a}->(), 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1128

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1129
test 'register_tag';
1130
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1131
$dbi->register_tag(
1132
    b => sub { 2 }
1133
);
1134
is($dbi->query_builder->tags->{b}->(), 2);
1135

            
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
1136
test 'table not specify exception';
1137
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1138
eval {$dbi->insert};
1139
like($@, qr/table/);
1140
eval {$dbi->update};
1141
like($@, qr/table/);
1142
eval {$dbi->delete};
1143
like($@, qr/table/);
1144
eval {$dbi->select};
1145
like($@, qr/table/);
many changed
Yuki Kimoto authored on 2011-01-23
1146

            
1147

            
1148
test 'more tests';
1149
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1150
eval{$dbi->apply_filter('table', 'column', [])};
1151
like($@, qr/apply_filter/);
1152

            
1153
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1154
like($@, qr/apply_filter/);
1155

            
1156
$dbi->apply_filter(
1157

            
1158
);
1159
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1160
$dbi->execute($CREATE_TABLE->{0});
1161
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1162
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1163
$dbi->apply_filter('table1', 'key2', 
1164
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
1165
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->fetch_hash_all;
1166
is_deeply($rows, [{key1 => 1, key2 => 6}]);
1167

            
1168
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1169
$dbi->execute($CREATE_TABLE->{0});
1170
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1171
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1172
$dbi->apply_filter('table1', 'key2', {});
1173
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->fetch_hash_all;
1174
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1175

            
1176
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1177
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})};
1178
like($@, qr/not registered/);
1179
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})};
1180
like($@, qr/not registered/);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1181
$dbi->method({one => sub { 1 }});
many changed
Yuki Kimoto authored on 2011-01-23
1182
is($dbi->one, 1);
1183

            
1184
eval{DBIx::Custom->connect()};
1185
like($@, qr/connect/);
1186

            
1187
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1188
$dbi->execute($CREATE_TABLE->{0});
1189
$dbi->register_filter(twice => sub { $_[0] * 2 });
1190
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1191
             filter => {key1 => 'twice'});
1192
$row = $dbi->select(table => 'table1')->fetch_hash_first;
1193
is_deeply($row, {key1 => 2, key2 => 2});
1194
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1195
             filter => {key1 => 'no'}) };
1196
like($@, qr//);
1197

            
1198
$dbi->register_filter(one => sub { });
1199
$dbi->default_fetch_filter('one');
1200
ok($dbi->default_fetch_filter);
1201
$dbi->default_bind_filter('one');
1202
ok($dbi->default_bind_filter);
1203
eval{$dbi->default_fetch_filter('no')};
1204
like($@, qr/not registered/);
1205
eval{$dbi->default_bind_filter('no')};
1206
like($@, qr/not registered/);
1207
$dbi->default_bind_filter(undef);
1208
ok(!defined $dbi->default_bind_filter);
1209
$dbi->default_fetch_filter(undef);
1210
ok(!defined $dbi->default_fetch_filter);
1211
eval {$dbi->execute('select * from table1 {= author') };
1212
like($@, qr/Tag not finished/);
1213

            
1214
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1215
$dbi->execute($CREATE_TABLE->{0});
1216
$dbi->register_filter(one => sub { 1 });
1217
$result = $dbi->select(table => 'table1');
1218
eval {$result->filter(key1 => 'no')};
1219
like($@, qr/not registered/);
1220
eval {$result->end_filter(key1 => 'no')};
1221
like($@, qr/not registered/);
1222
$result->default_filter(undef);
1223
ok(!defined $result->default_filter);
1224
$result->default_filter('one');
1225
is($result->default_filter->(), 1);
1226

            
1227
$dbi->table('book');
1228
eval{$dbi->table('book')->no_exists};
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1229
like($@, qr/locate/);
1230

            
1231
test 'dbi_option';
1232
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1233
                             dbi_option => {PrintError => 1});
1234
ok($dbi->dbh->{PrintError});
1235
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1236
                             dbi_options => {PrintError => 1});
1237
ok($dbi->dbh->{PrintError});
1238

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
1239
test 'DBIx::Custom::Result stash()';
1240
$result = DBIx::Custom::Result->new;
1241
is_deeply($result->stash, {}, 'default');
1242
$result->stash->{foo} = 1;
1243
is($result->stash->{foo}, 1, 'get and set');
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
1244

            
1245
test 'base_table';
1246
$dbi = DBIx::Custom->new;
1247
$dbi->base_table->method(
1248
    one => sub { 1 }
1249
);
1250
$table = $dbi->table('book');
1251
$table->method(
1252
    two => sub { 2 }
1253
);
1254
is($dbi->base_table->one, 1, 'method');
1255
is($table->one, 1, 'inherit method');
1256
is($table->two, 2, 'child table method');
1257
eval {$dbi->base_table->two};
1258
ok($@);
1259

            
1260
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1261
$dbi->execute($CREATE_TABLE->{0});
1262
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1263
$result = $dbi->base_table->execute("select * from table1");
1264
is_deeply($result->fetch_hash_all, [{key1 => 1, key2 => 2}], 'dbi method from base_table');
1265
$result = $dbi->table('table1')->execute("select * from table1");
1266
is_deeply($result->fetch_hash_all, [{key1 => 1, key2 => 2}], 'dbi method from table');
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
1267

            
1268
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1269
$dbi->method(
1270
    one => sub { 1 }
1271
);
1272
is($dbi->base_table->one, 1, 'use dbi method');
1273
is($dbi->table('table1')->one, 1, 'use dbi method');
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1274