DBIx-Custom / t / dbix-custom-core-sqlite.t /
Newer Older
1192 lines | 40.982kb
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

            
233

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

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

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

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

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

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

            
283

            
removed register_format()
yuki-kimoto authored on 2010-05-26
284
test 'update_all';
285
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
286
$dbi->execute($CREATE_TABLE->{1});
287
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
288
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
289
$dbi->register_filter(twice => sub { $_[0] * 2 });
290
$dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
291
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
292
$rows   = $result->fetch_hash_all;
293
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
294
                  {key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
295
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
296

            
297

            
298
test 'delete';
299
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
300
$dbi->execute($CREATE_TABLE->{0});
301
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
302
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
303
$dbi->delete(table => 'table1', where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
304
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
305
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
306
is_deeply($rows, [{key1 => 3, key2 => 4}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
307

            
308
$dbi->execute("delete from table1;");
309
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
310
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
311
$dbi->register_filter(twice => sub { $_[0] * 2 });
312
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
313
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
314
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
315
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
316

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

            
319
$dbi->delete_all(table => 'table1');
320
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
321
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
322
$dbi->delete(table => 'table1', where => {key1 => 1, key2 => 2});
323
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
324
is_deeply($rows, [{key1 => 3, key2 => 4}], "delete multi key");
removed register_format()
yuki-kimoto authored on 2010-05-26
325

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

            
329

            
removed register_format()
yuki-kimoto authored on 2010-05-26
330
test 'delete error';
331
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
332
$dbi->execute($CREATE_TABLE->{0});
333
eval{$dbi->delete(table => 'table1')};
add tests
yuki-kimoto authored on 2010-08-10
334
like($@, qr/"where" argument must be specified and contains the pairs of column name and value/,
cleanup
Yuki Kimoto authored on 2011-01-23
335
         "where key-value pairs not specified");
removed register_format()
yuki-kimoto authored on 2010-05-26
336

            
337
test 'delete_all';
338
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
339
$dbi->execute($CREATE_TABLE->{0});
340
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
341
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
342
$dbi->delete_all(table => 'table1');
add tests
yuki-kimoto authored on 2010-08-10
343
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
344
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
345
is_deeply($rows, [], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
346

            
347

            
348
test 'select';
349
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
350
$dbi->execute($CREATE_TABLE->{0});
351
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
352
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
353
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
354
is_deeply($rows, [{key1 => 1, key2 => 2},
cleanup
Yuki Kimoto authored on 2011-01-23
355
                  {key1 => 3, key2 => 4}], "table");
removed register_format()
yuki-kimoto authored on 2010-05-26
356

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

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

            
update document
yuki-kimoto authored on 2010-08-07
363
$rows = $dbi->select(table => 'table1', where => ['{= key1} and {= key2}', {key1 => 1, key2 => 2}])->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
364
is_deeply($rows, [{key1 => 1, key2 => 2}], "table and columns and where string");
update document
yuki-kimoto authored on 2010-08-07
365

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

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

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

            
377
$dbi->execute($CREATE_TABLE->{2});
378
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
379
$rows = $dbi->select(
380
    table => [qw/table1 table2/],
update document
yuki-kimoto authored on 2010-05-27
381
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
removed register_format()
yuki-kimoto authored on 2010-05-26
382
    where   => {'table1.key2' => 2},
added commit method
yuki-kimoto authored on 2010-05-27
383
    relation  => {'table1.key1' => 'table2.key1'}
removed register_format()
yuki-kimoto authored on 2010-05-26
384
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
385
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
386

            
387
$rows = $dbi->select(
388
    table => [qw/table1 table2/],
389
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
390
    relation  => {'table1.key1' => 'table2.key1'}
391
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
392
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
393

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

            
397

            
removed register_format()
yuki-kimoto authored on 2010-05-26
398
test 'fetch filter';
399
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
400
$dbi->register_filter(
401
    twice       => sub { $_[0] * 2 },
402
    three_times => sub { $_[0] * 3 }
403
);
404
$dbi->default_fetch_filter('twice');
405
$dbi->execute($CREATE_TABLE->{0});
406
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
407
$result = $dbi->select(table => 'table1');
408
$result->filter({key1 => 'three_times'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
409
$row = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
410
is_deeply($row, {key1 => 3, key2 => 4}, "default_fetch_filter and filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
411

            
412
test 'filters';
413
$dbi = DBIx::Custom->new;
414

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

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

            
added commit method
yuki-kimoto authored on 2010-05-27
421
test 'transaction';
422
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
423
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
424
$dbi->dbh->begin_work;
added commit method
yuki-kimoto authored on 2010-05-27
425
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
426
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
427
$dbi->dbh->commit;
added commit method
yuki-kimoto authored on 2010-05-27
428
$result = $dbi->select(table => 'table1');
429
is_deeply(scalar $result->fetch_hash_all, [{key1 => 1, key2 => 2}, {key1 => 2, key2 => 3}],
cleanup
Yuki Kimoto authored on 2011-01-23
430
          "commit");
added commit method
yuki-kimoto authored on 2010-05-27
431

            
432
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
433
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
434
$dbi->dbh->begin_work(0);
added commit method
yuki-kimoto authored on 2010-05-27
435
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
436
$dbi->dbh->rollback;
added commit method
yuki-kimoto authored on 2010-05-27
437

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

            
441
test 'cache';
442
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
443
$dbi->execute($CREATE_TABLE->{0});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
444
$source = 'select * from table1 where {= key1} and {= key2};';
445
$dbi->create_query($source);
446
is_deeply($dbi->{_cached}->{$source}, 
cleanup
Yuki Kimoto authored on 2011-01-23
447
          {sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2']}, "cache");
add cache attribute
yuki-kimoto authored on 2010-06-14
448

            
449
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
450
$dbi->execute($CREATE_TABLE->{0});
451
$dbi->{_cached} = {};
452
$dbi->cache(0);
453
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
454
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
455

            
add tests
yuki-kimoto authored on 2010-08-10
456
test 'execute';
457
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
458
$dbi->execute($CREATE_TABLE->{0});
removed experimental registe...
yuki-kimoto authored on 2010-08-24
459
{
460
    local $Carp::Verbose = 0;
461
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
462
    like($@, qr/\Qselect * frm table1;/, "fail prepare");
463
    like($@, qr/\.t /, "fail : not verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
464
}
465
{
466
    local $Carp::Verbose = 1;
467
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
468
    like($@, qr/Custom.*\.t /s, "fail : verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
469
}
add tests
yuki-kimoto authored on 2010-08-10
470

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

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

            
removed experimental registe...
yuki-kimoto authored on 2010-08-24
479
{
480
    local $Carp::Verbose = 0;
481
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
cleanup
Yuki Kimoto authored on 2011-01-23
482
    like($@, qr/\Q.t /, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
483
}
484
{
485
    local $Carp::Verbose = 1;
486
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
cleanup
Yuki Kimoto authored on 2011-01-23
487
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
488
}
cleanup
yuki-kimoto authored on 2010-10-17
489

            
490

            
491
test 'transaction';
492
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
493
$dbi->execute($CREATE_TABLE->{0});
494

            
495
$dbi->begin_work;
496

            
497
eval {
498
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
499
    die "Error";
500
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
501
};
502

            
503
$dbi->rollback if $@;
504

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

            
509
$dbi->begin_work;
510

            
511
eval {
512
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
513
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
514
};
515

            
516
$dbi->commit unless $@;
517

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

            
522
$dbi->dbh->{AutoCommit} = 0;
523
eval{ $dbi->begin_work };
cleanup
Yuki Kimoto authored on 2011-01-23
524
ok($@, "exception");
cleanup
yuki-kimoto authored on 2010-10-17
525
$dbi->dbh->{AutoCommit} = 1;
526

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
528
test 'method';
added helper method
yuki-kimoto authored on 2010-10-17
529
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
530
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
531
    one => sub { 1 }
532
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
533
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
534
    two => sub { 2 }
535
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
536
$dbi->method({
added helper method
yuki-kimoto authored on 2010-10-17
537
    twice => sub {
538
        my $self = shift;
539
        return $_[0] * 2;
540
    }
541
});
542

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

            
547
eval {$dbi->XXXXXX};
cleanup
Yuki Kimoto authored on 2011-01-23
548
like($@, qr/\QCan't locate object method "XXXXXX" via "DBIx::Custom"/, "not exists");
added helper method
yuki-kimoto authored on 2010-10-17
549

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
550
test 'out filter';
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
551
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
552
$dbi->execute($CREATE_TABLE->{0});
553
$dbi->register_filter(twice => sub { $_[0] * 2 });
554
$dbi->register_filter(three_times => sub { $_[0] * 3});
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
555
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
556
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
557
              'key2' => {out => 'three_times', in => 'twice'});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
558
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
559
$result = $dbi->execute($SELECT_SOURCES->{0});
560
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
561
is_deeply($row, {key1 => 2, key2 => 6}, "insert");
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
562
$result = $dbi->select(table => 'table1');
563
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
564
is_deeply($row, {key1 => 6, key2 => 12}, "insert");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
565

            
566
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
567
$dbi->execute($CREATE_TABLE->{0});
568
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
569
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
570
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
571
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
572
$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
573
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2});
574
$result = $dbi->execute($SELECT_SOURCES->{0});
575
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
576
is_deeply($row, {key1 => 4, key2 => 2}, "update");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
577

            
578
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
579
$dbi->execute($CREATE_TABLE->{0});
580
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
581
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
582
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
583
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
584
$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
585
$dbi->delete(table => 'table1', where => {key1 => 1});
586
$result = $dbi->execute($SELECT_SOURCES->{0});
587
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
588
is_deeply($rows, [], "delete");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
589

            
590
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
591
$dbi->execute($CREATE_TABLE->{0});
592
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
593
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
594
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
595
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
596
$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
597
$result = $dbi->select(table => 'table1', where => {key1 => 1});
598
$result->filter({'key2' => 'twice'});
599
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
600
is_deeply($rows, [{key1 => 4, key2 => 4}], "select");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
601

            
602
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
603
$dbi->execute($CREATE_TABLE->{0});
604
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
605
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
606
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
607
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
608
$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
609
$result = $dbi->execute("select * from table1 where {= key1} and {= key2};",
610
                        param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
611
                        table => ['table1']);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
612
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
613
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute");
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->execute($CREATE_TABLE->{2});
618
$dbi->register_filter(twice => sub { $_[0] * 2 });
619
$dbi->register_filter(three_times => sub { $_[0] * 3 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
620
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
621
    'table1', 'key2' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
622
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
623
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
624
    'table2', 'key3' => {out => 'three_times', in => 'three_times'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
625
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
626
$dbi->insert(table => 'table1', param => {key1 => 5, key2 => 2}, filter => {key2 => undef});
627
$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
628
$result = $dbi->select(
629
     table => ['table1', 'table2'],
630
     column => ['key2', 'key3'],
631
     where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
632

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

            
637
$result = $dbi->select(
638
     table => ['table1', 'table2'],
639
     column => ['key2', 'key3'],
640
     where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
641

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
646
test 'each_column';
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
647
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
648
$dbi->execute($CREATE_TABLE->{2});
649
$dbi->execute($CREATE_TABLE->{3});
650

            
651
$infos = [];
pod fix
Yuki Kimoto authored on 2011-01-21
652
$dbi->each_column(sub {
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
653
    my ($self, $table, $column, $cinfo) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
654
    
655
    if ($table =~ /^table/) {
656
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
657
         push @$infos, $info;
658
    }
659
});
660
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
661
is_deeply($infos, 
662
    [
663
        ['table1', 'key1', 'key1'],
664
        ['table1', 'key2', 'key2'],
665
        ['table2', 'key1', 'key1'],
666
        ['table2', 'key3', 'key3']
667
    ]
cleanup
Yuki Kimoto authored on 2011-01-23
668
    
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
669
);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
670

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
671
test 'table';
672
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
673
$dbi->execute($CREATE_TABLE->{0});
674
$table = $dbi->table('table1');
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
675
$table->insert(param => {key1 => 1, key2 => 2});
676
$table->insert(param => {key1 => 3, key2 => 4});
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
677
$rows = $table->select->fetch_hash_all;
678
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}],
cleanup
Yuki Kimoto authored on 2011-01-23
679
                 "select");
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
680
$rows = $table->select(where => {key2 => 2}, append => 'order by key1',
681
                              column => ['key1', 'key2'])->fetch_hash_all;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
682
is_deeply($rows, [{key1 => 1, key2 => 2}],
cleanup
Yuki Kimoto authored on 2011-01-23
683
                 "insert insert select");
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
684
$table->update(param => {key1 => 3}, where => {key2 => 2});
685
$table->update(param => {key1 => 5}, where => {key2 => 4});
686
$rows = $table->select(where => {key2 => 2})->fetch_hash_all;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
687
is_deeply($rows, [{key1 => 3, key2 => 2}],
cleanup
Yuki Kimoto authored on 2011-01-23
688
                 "update");
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
689
$table->delete(where => {key2 => 2});
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
690
$rows = $table->select->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
691
is_deeply($rows, [{key1 => 5, key2 => 4}], "delete");
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
692
$table->update_all(param => {key1 => 3});
693
$rows = $table->select->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
694
is_deeply($rows, [{key1 => 3, key2 => 4}], "update_all");
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
695
$table->delete_all;
696
$rows = $table->select->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
697
is_deeply($rows, [], "delete_all");
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
698

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
699
$dbi->dbh->do($CREATE_TABLE->{2});
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
700
$dbi->table('table2')->method(
701
    ppp => sub {
702
        my $self = shift;
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
703
    
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
704
        return $self->name;
705
    }
706
);
707
is($dbi->table('table2')->ppp, 'table2', "method");
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
708

            
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
709
$dbi->table('table2')->method({
710
    qqq => sub {
711
        my $self = shift;
many changed
Yuki Kimoto authored on 2011-01-23
712
    
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
713
        return $self->name;
714
    }
715
});
716
is($dbi->table('table2')->qqq, 'table2', "method");
many changed
Yuki Kimoto authored on 2011-01-23
717

            
718

            
add examples
Yuki Kimoto authored on 2011-01-07
719
test 'limit';
720
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
721
$dbi->execute($CREATE_TABLE->{0});
722
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
723
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4});
724
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
725
$dbi->register_tag(
add examples
Yuki Kimoto authored on 2011-01-07
726
    limit => sub {
727
        my ($count, $offset) = @_;
728
        
729
        my $s = '';
730
        $s .= "limit $count";
731
        $s .= " offset $offset" if defined $offset;
732
        
733
        return [$s, []];
734
    }
735
);
736
$rows = $dbi->select(
737
  table => 'table1',
738
  where => {key1 => 1},
739
  append => "order by key2 {limit 1 0}"
740
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
741
is_deeply($rows, [{key1 => 1, key2 => 2}]);
add examples
Yuki Kimoto authored on 2011-01-07
742
$rows = $dbi->select(
743
  table => 'table1',
744
  where => {key1 => 1},
745
  append => "order by key2 {limit 2 1}"
746
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
747
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]);
add examples
Yuki Kimoto authored on 2011-01-07
748
$rows = $dbi->select(
749
  table => 'table1',
750
  where => {key1 => 1},
751
  append => "order by key2 {limit 1}"
752
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
753
is_deeply($rows, [{key1 => 1, key2 => 2}]);
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
754

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
755
test 'connect super';
756
{
757
    package MyDBI;
758
    
759
    use base 'DBIx::Custom';
760
    sub connect {
761
        my $self = shift->SUPER::connect(@_);
762
        
763
        return $self;
764
    }
765
    
766
    sub new {
cleanup
Yuki Kimoto authored on 2011-01-25
767
        my $self = shift->SUPER::new(@_);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
768
        
769
        return $self;
770
    }
771
}
772

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
784
{
785
    package MyDBI2;
786
    
787
    use base 'DBIx::Custom';
788
    sub connect {
789
        my $self = shift->SUPER::new(@_);
790
        $self->connect;
791
        
792
        return $self;
793
    }
794
}
795

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

            
801
test 'end_filter';
802
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
803
$dbi->execute($CREATE_TABLE->{0});
804
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
805
$result = $dbi->select(table => 'table1');
806
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
807
$result->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 });
808
$row = $result->fetch_first;
809
is_deeply($row, [6, 40]);
810

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

            
818

            
819
test 'empty where select';
820
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
821
$dbi->execute($CREATE_TABLE->{0});
822
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
823
$result = $dbi->select(table => 'table1', where => {});
824
$row = $result->fetch_hash_first;
825
is_deeply($row, {key1 => 1, key2 => 2});
826

            
827
$result = $dbi->select(table => 'table1', where => [' ', {}]);
828
$row = $result->fetch_hash_first;
829
is_deeply($row, {key1 => 1, key2 => 2});
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
830

            
831

            
832
test 'select query option';
833
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
834
$dbi->execute($CREATE_TABLE->{0});
835
$query = $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, query => 1);
836
is(ref $query, 'DBIx::Custom::Query');
837
$query = $dbi->update(table => 'table1', where => {key1 => 1}, param => {key2 => 2}, query => 1);
838
is(ref $query, 'DBIx::Custom::Query');
839
$query = $dbi->delete(table => 'table1', where => {key1 => 1}, query => 1);
840
is(ref $query, 'DBIx::Custom::Query');
841
$query = $dbi->select(table => 'table1', where => {key1 => 1, key2 => 2}, query => 1);
842
is(ref $query, 'DBIx::Custom::Query');
843

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
844
test 'DBIx::Custom::Where';
experimental extended select...
Yuki Kimoto authored on 2011-01-17
845
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
846
$dbi->execute($CREATE_TABLE->{0});
847
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
848
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
849
$where = $dbi->where->clause(['and', '{= key1}', '{= key2}']);
850
is("$where", "where ( {= key1} and {= key2} )", 'no param');
851

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

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
856
$result = $dbi->select(
857
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
858
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
859
);
860
$row = $result->fetch_hash_all;
861
is_deeply($row, [{key1 => 1, key2 => 2}]);
862

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
863
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
864
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
865
             ->param({key1 => 1, key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
866
$result = $dbi->select(
867
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
868
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
869
);
870
$row = $result->fetch_hash_all;
871
is_deeply($row, [{key1 => 1, key2 => 2}]);
872

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
873
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
874
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
875
             ->param({});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
876
$result = $dbi->select(
877
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
878
    where => $where,
experimental extended select...
Yuki Kimoto authored on 2011-01-17
879
);
880
$row = $result->fetch_hash_all;
881
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
882

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
883
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
884
             ->clause(['and', ['or', '{> key1}', '{< key1}'], '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
885
             ->param({key1 => [0, 3], key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
886
$result = $dbi->select(
887
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
888
    where => $where,
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
889
); 
experimental extended select...
Yuki Kimoto authored on 2011-01-17
890
$row = $result->fetch_hash_all;
891
is_deeply($row, [{key1 => 1, key2 => 2}]);
892

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
893
$where = $dbi->where;
894
$result = $dbi->select(
895
    table => 'table1',
896
    where => $where
897
);
898
$row = $result->fetch_hash_all;
899
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
900

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
901
eval {
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
902
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
903
             ->clause(['uuu']);
experimental extended select...
Yuki Kimoto authored on 2011-01-17
904
$result = $dbi->select(
905
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
906
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
907
);
908
};
909
ok($@);
910

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

            
added test
Yuki Kimoto authored on 2011-01-19
914
$where = $dbi->where
915
             ->clause(['or', ('{= key1}') x 2])
916
             ->param({key1 => [1, 3]});
917
$result = $dbi->select(
918
    table => 'table1',
919
    where => $where,
920
);
921
$row = $result->fetch_hash_all;
922
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
923

            
924
$where = $dbi->where
925
             ->clause(['or', ('{= key1}') x 2])
926
             ->param({key1 => [1]});
927
$result = $dbi->select(
928
    table => 'table1',
929
    where => $where,
930
);
931
$row = $result->fetch_hash_all;
932
is_deeply($row, [{key1 => 1, key2 => 2}]);
933

            
934
$where = $dbi->where
935
             ->clause(['or', ('{= key1}') x 2])
936
             ->param({key1 => 1});
937
$result = $dbi->select(
938
    table => 'table1',
939
    where => $where,
940
);
941
$row = $result->fetch_hash_all;
942
is_deeply($row, [{key1 => 1, key2 => 2}]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
943

            
many changed
Yuki Kimoto authored on 2011-01-23
944
$where = $dbi->where
945
             ->clause('{= key1}')
946
             ->param({key1 => 1});
947
$result = $dbi->select(
948
    table => 'table1',
949
    where => $where,
950
);
951
$row = $result->fetch_hash_all;
952
is_deeply($row, [{key1 => 1, key2 => 2}]);
953

            
954
$where = $dbi->where
955
             ->clause('{= key1} {= key2}')
956
             ->param({key1 => 1});
957
eval{$where->to_string};
958
like($@, qr/one column/);
959

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
960
$where = $dbi->where
961
             ->clause('{= key1}')
962
             ->param([]);
963
eval{$where->to_string};
964
like($@, qr/Parameter/);
965

            
966
$where = $dbi->where
967
             ->clause(['or', ('{= key1}') x 3])
968
             ->param({key1 => [$dbi->not_exists, 1, 3]});
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}, {key1 => 3, key2 => 4}], 'not_exists');
975

            
976
$where = $dbi->where
977
             ->clause(['or', ('{= key1}') x 3])
978
             ->param({key1 => [1, $dbi->not_exists, 3]});
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}, {key1 => 3, key2 => 4}], 'not_exists');
985

            
986
$where = $dbi->where
987
             ->clause(['or', ('{= key1}') x 3])
988
             ->param({key1 => [1, 3, $dbi->not_exists]});
989
$result = $dbi->select(
990
    table => 'table1',
991
    where => $where,
992
);
993
$row = $result->fetch_hash_all;
994
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
995

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

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

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

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

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

            
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1040
test 'register_tag_processor';
1041
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1042
$dbi->register_tag_processor(
1043
    a => sub { 1 }
1044
);
1045
is($dbi->query_builder->tag_processors->{a}->(), 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1046

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1047
test 'register_tag';
1048
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1049
$dbi->register_tag(
1050
    b => sub { 2 }
1051
);
1052
is($dbi->query_builder->tags->{b}->(), 2);
1053

            
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
1054
test 'table not specify exception';
1055
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1056
eval {$dbi->insert};
1057
like($@, qr/table/);
1058
eval {$dbi->update};
1059
like($@, qr/table/);
1060
eval {$dbi->delete};
1061
like($@, qr/table/);
1062
eval {$dbi->select};
1063
like($@, qr/table/);
many changed
Yuki Kimoto authored on 2011-01-23
1064

            
1065

            
1066
test 'more tests';
1067
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1068
eval{$dbi->apply_filter('table', 'column', [])};
1069
like($@, qr/apply_filter/);
1070

            
1071
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1072
like($@, qr/apply_filter/);
1073

            
1074
$dbi->apply_filter(
1075

            
1076
);
1077
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1078
$dbi->execute($CREATE_TABLE->{0});
1079
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1080
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1081
$dbi->apply_filter('table1', 'key2', 
1082
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
1083
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->fetch_hash_all;
1084
is_deeply($rows, [{key1 => 1, key2 => 6}]);
1085

            
1086
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1087
$dbi->execute($CREATE_TABLE->{0});
1088
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1089
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1090
$dbi->apply_filter('table1', 'key2', {});
1091
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->fetch_hash_all;
1092
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1093

            
1094
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1095
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})};
1096
like($@, qr/not registered/);
1097
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})};
1098
like($@, qr/not registered/);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1099
$dbi->method({one => sub { 1 }});
many changed
Yuki Kimoto authored on 2011-01-23
1100
is($dbi->one, 1);
1101

            
1102
eval{DBIx::Custom->connect()};
1103
like($@, qr/connect/);
1104

            
1105
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1106
$dbi->execute($CREATE_TABLE->{0});
1107
$dbi->register_filter(twice => sub { $_[0] * 2 });
1108
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1109
             filter => {key1 => 'twice'});
1110
$row = $dbi->select(table => 'table1')->fetch_hash_first;
1111
is_deeply($row, {key1 => 2, key2 => 2});
1112
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1113
             filter => {key1 => 'no'}) };
1114
like($@, qr//);
1115

            
1116
$dbi->register_filter(one => sub { });
1117
$dbi->default_fetch_filter('one');
1118
ok($dbi->default_fetch_filter);
1119
$dbi->default_bind_filter('one');
1120
ok($dbi->default_bind_filter);
1121
eval{$dbi->default_fetch_filter('no')};
1122
like($@, qr/not registered/);
1123
eval{$dbi->default_bind_filter('no')};
1124
like($@, qr/not registered/);
1125
$dbi->default_bind_filter(undef);
1126
ok(!defined $dbi->default_bind_filter);
1127
$dbi->default_fetch_filter(undef);
1128
ok(!defined $dbi->default_fetch_filter);
1129
eval {$dbi->execute('select * from table1 {= author') };
1130
like($@, qr/Tag not finished/);
1131

            
1132
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1133
$dbi->execute($CREATE_TABLE->{0});
1134
$dbi->register_filter(one => sub { 1 });
1135
$result = $dbi->select(table => 'table1');
1136
eval {$result->filter(key1 => 'no')};
1137
like($@, qr/not registered/);
1138
eval {$result->end_filter(key1 => 'no')};
1139
like($@, qr/not registered/);
1140
$result->default_filter(undef);
1141
ok(!defined $result->default_filter);
1142
$result->default_filter('one');
1143
is($result->default_filter->(), 1);
1144

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

            
1149
test 'dbi_option';
1150
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1151
                             dbi_option => {PrintError => 1});
1152
ok($dbi->dbh->{PrintError});
1153
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1154
                             dbi_options => {PrintError => 1});
1155
ok($dbi->dbh->{PrintError});
1156

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
1157
test 'DBIx::Custom::Result stash()';
1158
$result = DBIx::Custom::Result->new;
1159
is_deeply($result->stash, {}, 'default');
1160
$result->stash->{foo} = 1;
1161
is($result->stash->{foo}, 1, 'get and set');
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
1162

            
1163
test 'base_table';
1164
$dbi = DBIx::Custom->new;
1165
$dbi->base_table->method(
1166
    one => sub { 1 }
1167
);
1168
$table = $dbi->table('book');
1169
$table->method(
1170
    two => sub { 2 }
1171
);
1172
is($dbi->base_table->one, 1, 'method');
1173
is($table->one, 1, 'inherit method');
1174
is($table->two, 2, 'child table method');
1175
eval {$dbi->base_table->two};
1176
ok($@);
1177

            
1178
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1179
$dbi->execute($CREATE_TABLE->{0});
1180
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1181
$result = $dbi->base_table->execute("select * from table1");
1182
is_deeply($result->fetch_hash_all, [{key1 => 1, key2 => 2}], 'dbi method from base_table');
1183
$result = $dbi->table('table1')->execute("select * from table1");
1184
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
1185

            
1186
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1187
$dbi->method(
1188
    one => sub { 1 }
1189
);
1190
is($dbi->base_table->one, 1, 'use dbi method');
1191
is($dbi->table('table1')->one, 1, 'use dbi method');
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1192