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

            
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
18
use FindBin;
19
use lib "$FindBin::Bin/dbix-custom-core-sqlite";
20

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

            
24
# Constant varialbes for test
25
my $CREATE_TABLE = {
26
    0 => 'create table table1 (key1 char(255), key2 char(255));',
27
    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
28
    2 => 'create table table2 (key1 char(255), key3 char(255));',
29
    3 => 'create table table1 (key1 Date, key2 datetime);'
removed register_format()
yuki-kimoto authored on 2010-05-26
30
};
31

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

            
36
my $DROP_TABLE = {
37
    0 => 'drop table table1'
38
};
39

            
40
my $NEW_ARGS = {
41
    0 => {data_source => 'dbi:SQLite:dbname=:memory:'}
42
};
43

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

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

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

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

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

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

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

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

            
108

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

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

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

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
151
$source = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};";
152
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
153
$result = $dbi->execute($query, param => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
154
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
155
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
156

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
157
$source = "select * from table1 where {<= key1} and {like key2};";
158
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
159
$result = $dbi->execute($query, param => {key1 => 1, key2 => '%2%'});
160
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
161
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
162

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

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

            
175
test 'DBIx::Custom::SQLTemplate insert tag';
176
$dbi->execute("delete from table1");
add tests
yuki-kimoto authored on 2010-08-10
177
$insert_SOURCE = 'insert into table1 {insert_param key1 key2 key3 key4 key5}';
178
$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
179

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

            
184
test 'DBIx::Custom::SQLTemplate update tag';
185
$dbi->execute("delete from table1");
add tests
yuki-kimoto authored on 2010-08-10
186
$insert_SOURCE = "insert into table1 {insert_param key1 key2 key3 key4 key5}";
187
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
188
$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
189

            
add tests
yuki-kimoto authored on 2010-08-10
190
$update_SOURCE = 'update table1 {update_param key1 key2 key3 key4} where {= key5}';
191
$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
192

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
327

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

            
338
$dbi->execute("delete from table1;");
339
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
340
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
341
$dbi->register_filter(twice => sub { $_[0] * 2 });
342
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'});
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, [{key1 => 3, key2 => 4}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
346

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

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

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

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
359
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
360
$dbi->execute($CREATE_TABLE->{0});
361
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
362
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
363
$where = $dbi->where;
364
$where->clause(['and', '{= key1}', '{= key2}']);
365
$where->param({ke1 => 1, key2 => 2});
366
$dbi->delete(table => 'table1', where => $where);
367
$result = $dbi->select(table => 'table1');
368
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 4}], 'delete() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
369

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

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

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

            
390

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

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

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

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

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

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

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

            
427
$rows = $dbi->select(
428
    table => [qw/table1 table2/],
429
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
430
    relation  => {'table1.key1' => 'table2.key1'}
431
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
432
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
433

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

            
437

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

            
452
test 'filters';
453
$dbi = DBIx::Custom->new;
454

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

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

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

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

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

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

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

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

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

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

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

            
530

            
531
test 'transaction';
532
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
533
$dbi->execute($CREATE_TABLE->{0});
534

            
535
$dbi->begin_work;
536

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

            
543
$dbi->rollback if $@;
544

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

            
549
$dbi->begin_work;
550

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

            
556
$dbi->commit unless $@;
557

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

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

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
568
test 'method';
added helper method
yuki-kimoto authored on 2010-10-17
569
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
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
    one => sub { 1 }
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
    two => sub { 2 }
575
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
576
$dbi->method({
added helper method
yuki-kimoto authored on 2010-10-17
577
    twice => sub {
578
        my $self = shift;
579
        return $_[0] * 2;
580
    }
581
});
582

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

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

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

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
606
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
607
$dbi->execute($CREATE_TABLE->{0});
608
$dbi->register_filter(twice => sub { $_[0] * 2 });
609
$dbi->register_filter(three_times => sub { $_[0] * 3});
610
$dbi->apply_filter(
611
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
612
              'key2' => {out => 'three_times', in => 'twice'});
613
$dbi->apply_filter(
614
    'table1', 'key1' => {out => undef}
615
); 
616
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
617
$result = $dbi->execute($SELECT_SOURCES->{0});
618
$row   = $result->fetch_hash_first;
619
is_deeply($row, {key1 => 1, key2 => 6}, "insert");
620

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
621
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
622
$dbi->execute($CREATE_TABLE->{0});
623
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
624
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
625
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
626
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
627
$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
628
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2});
629
$result = $dbi->execute($SELECT_SOURCES->{0});
630
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
631
is_deeply($row, {key1 => 4, key2 => 2}, "update");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
632

            
633
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
634
$dbi->execute($CREATE_TABLE->{0});
635
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
636
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
637
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
638
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
639
$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
640
$dbi->delete(table => 'table1', where => {key1 => 1});
641
$result = $dbi->execute($SELECT_SOURCES->{0});
642
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
643
is_deeply($rows, [], "delete");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
644

            
645
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
646
$dbi->execute($CREATE_TABLE->{0});
647
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
648
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
649
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
650
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
651
$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
652
$result = $dbi->select(table => 'table1', where => {key1 => 1});
653
$result->filter({'key2' => 'twice'});
654
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
655
is_deeply($rows, [{key1 => 4, key2 => 4}], "select");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
656

            
657
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
658
$dbi->execute($CREATE_TABLE->{0});
659
$dbi->register_filter(twice => sub { $_[0] * 2 });
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
    'table1', 'key1' => {out => 'twice', in => 'twice'}
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 => 2, key2 => 2}, filter => {key1 => undef});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
664
$result = $dbi->execute("select * from table1 where {= key1} and {= key2};",
665
                        param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
666
                        table => ['table1']);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
667
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
668
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
669

            
add table tag
Yuki Kimoto authored on 2011-02-09
670
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
671
$dbi->execute($CREATE_TABLE->{0});
672
$dbi->register_filter(twice => sub { $_[0] * 2 });
673
$dbi->apply_filter(
674
    'table1', 'key1' => {out => 'twice', in => 'twice'}
675
);
676
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
677
$result = $dbi->execute("select * from {table table1} where {= key1} and {= key2};",
678
                        param => {key1 => 1, key2 => 2});
679
$rows   = $result->fetch_hash_all;
680
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute table tag");
681

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
682
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
683
$dbi->execute($CREATE_TABLE->{0});
684
$dbi->execute($CREATE_TABLE->{2});
685
$dbi->register_filter(twice => sub { $_[0] * 2 });
686
$dbi->register_filter(three_times => sub { $_[0] * 3 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
687
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
688
    'table1', 'key2' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
689
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
690
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
691
    'table2', 'key3' => {out => 'three_times', in => 'three_times'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
692
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
693
$dbi->insert(table => 'table1', param => {key1 => 5, key2 => 2}, filter => {key2 => undef});
694
$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
695
$result = $dbi->select(
696
     table => ['table1', 'table2'],
697
     column => ['key2', 'key3'],
698
     where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
699

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

            
704
$result = $dbi->select(
705
     table => ['table1', 'table2'],
706
     column => ['key2', 'key3'],
707
     where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
708

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
713
test 'each_column';
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
714
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
715
$dbi->execute($CREATE_TABLE->{2});
716
$dbi->execute($CREATE_TABLE->{3});
717

            
718
$infos = [];
pod fix
Yuki Kimoto authored on 2011-01-21
719
$dbi->each_column(sub {
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
720
    my ($self, $table, $column, $cinfo) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
721
    
722
    if ($table =~ /^table/) {
723
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
724
         push @$infos, $info;
725
    }
726
});
727
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
728
is_deeply($infos, 
729
    [
730
        ['table1', 'key1', 'key1'],
731
        ['table1', 'key2', 'key2'],
732
        ['table2', 'key1', 'key1'],
733
        ['table2', 'key3', 'key3']
734
    ]
cleanup
Yuki Kimoto authored on 2011-01-23
735
    
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
736
);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
737

            
add examples
Yuki Kimoto authored on 2011-01-07
738
test 'limit';
739
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
740
$dbi->execute($CREATE_TABLE->{0});
741
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
742
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4});
743
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
744
$dbi->register_tag(
add examples
Yuki Kimoto authored on 2011-01-07
745
    limit => sub {
746
        my ($count, $offset) = @_;
747
        
748
        my $s = '';
749
        $s .= "limit $count";
750
        $s .= " offset $offset" if defined $offset;
751
        
752
        return [$s, []];
753
    }
754
);
755
$rows = $dbi->select(
756
  table => 'table1',
757
  where => {key1 => 1},
758
  append => "order by key2 {limit 1 0}"
759
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
760
is_deeply($rows, [{key1 => 1, key2 => 2}]);
add examples
Yuki Kimoto authored on 2011-01-07
761
$rows = $dbi->select(
762
  table => 'table1',
763
  where => {key1 => 1},
764
  append => "order by key2 {limit 2 1}"
765
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
766
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]);
add examples
Yuki Kimoto authored on 2011-01-07
767
$rows = $dbi->select(
768
  table => 'table1',
769
  where => {key1 => 1},
770
  append => "order by key2 {limit 1}"
771
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
772
is_deeply($rows, [{key1 => 1, key2 => 2}]);
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
773

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
774
test 'connect super';
775
{
776
    package MyDBI;
777
    
778
    use base 'DBIx::Custom';
779
    sub connect {
780
        my $self = shift->SUPER::connect(@_);
781
        
782
        return $self;
783
    }
784
    
785
    sub new {
cleanup
Yuki Kimoto authored on 2011-01-25
786
        my $self = shift->SUPER::new(@_);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
787
        
788
        return $self;
789
    }
790
}
791

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
803
{
804
    package MyDBI2;
805
    
806
    use base 'DBIx::Custom';
807
    sub connect {
808
        my $self = shift->SUPER::new(@_);
809
        $self->connect;
810
        
811
        return $self;
812
    }
813
}
814

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

            
820
test 'end_filter';
821
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
822
$dbi->execute($CREATE_TABLE->{0});
823
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
824
$result = $dbi->select(table => 'table1');
825
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
826
$result->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 });
827
$row = $result->fetch_first;
828
is_deeply($row, [6, 40]);
829

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

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
837
$dbi->register_filter(five_times => sub { $_[0] * 5 });
838
$dbi->apply_filter('table1',
839
    key1 => {end => sub { $_[0] * 3 } },
840
    key2 => {end => 'five_times'}
841
);
842
$result = $dbi->select(table => 'table1');
843
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
844
$row = $result->fetch_hash_first;
845
is_deeply($row, {key1 => 6, key2 => 40}, 'apply_filter');
846

            
847
$dbi->register_filter(five_times => sub { $_[0] * 5 });
848
$dbi->apply_filter('table1',
849
    key1 => {end => sub { $_[0] * 3 } },
850
    key2 => {end => 'five_times'}
851
);
852
$result = $dbi->select(table => 'table1');
853
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
854
$result->filter(key1 => undef);
855
$result->end_filter(key1 => undef);
856
$row = $result->fetch_hash_first;
857
is_deeply($row, {key1 => 1, key2 => 40}, 'apply_filter overwrite');
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
858

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1111
$where = $dbi->where
1112
             ->clause(['and', '{> key1}', '{< key1}' ])
1113
             ->param({key1 => [0, 2]});
1114
$result = $dbi->select(
1115
    table => 'table1',
1116
    where => $where,
1117
);
1118
$row = $result->fetch_hash_all;
1119
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1120

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

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

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

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

            
1150

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

            
1156
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1157
like($@, qr/apply_filter/);
1158

            
1159
$dbi->apply_filter(
1160

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

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

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

            
1187
eval{DBIx::Custom->connect()};
1188
like($@, qr/connect/);
1189

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

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

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

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1230
test 'dbi_option';
1231
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1232
                             dbi_option => {PrintError => 1});
1233
ok($dbi->dbh->{PrintError});
1234
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1235
                             dbi_options => {PrintError => 1});
1236
ok($dbi->dbh->{PrintError});
1237

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

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1244
test 'filter __ expression';
1245
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1246
$dbi->execute('create table company (id, name, location_id)');
1247
$dbi->execute('create table location (id, name)');
1248
$dbi->apply_filter('location',
1249
  name => {in => sub { uc $_[0] } }
1250
);
1251

            
1252
$dbi->insert(table => 'company', param => {id => 1, name => 'a', location_id => 2});
1253
$dbi->insert(table => 'location', param => {id => 2, name => 'b'});
1254

            
1255
$result = $dbi->select(
1256
    table => ['company', 'location'], relation => {'company.location_id' => 'location.id'},
1257
    column => ['location.name as location__name']
1258
);
1259
is($result->fetch_first->[0], 'B');
1260

            
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
1261
test 'selection';
1262
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1263
$dbi->execute($CREATE_TABLE->{0});
1264
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1265
$result = $dbi->select(selection => '* from table1', where => {key1 => 1});
1266
is_deeply($result->fetch_hash_all, [{key1 => 1, key2 => 2}]);
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1267

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1268
test 'Model class';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1269
use MyDBI1;
1270
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1271
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1272
$model = $dbi->model('book');
1273
$model->insert({title => 'a', author => 'b'});
1274
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1275
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1276
$model = $dbi->model('company');
1277
$model->insert({name => 'a'});
1278
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1279

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1280
$dbi->model('book');
1281
eval{$dbi->model('book')->no_exists};
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1282
like($@, qr/locate/);
1283

            
1284
{
1285
    package MyDBI4;
1286

            
1287
    use strict;
1288
    use warnings;
1289

            
1290
    use base 'DBIx::Custom';
1291

            
1292
    sub connect {
1293
        my $self = shift->SUPER::connect(@_);
1294
        
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1295
        $self->include_model(
1296
            MyModel2 => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1297
                'book',
1298
                {company => 'Company'}
1299
            ]
1300
        );
1301
    }
1302

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1303
    package MyModel2::Base1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1304

            
1305
    use strict;
1306
    use warnings;
1307

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1308
    use base 'DBIx::Custom::Model';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1309

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1310
    package MyModel2::book;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1311

            
1312
    use strict;
1313
    use warnings;
1314

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1315
    use base 'MyModel2::Base1';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1316

            
1317
    sub insert {
1318
        my ($self, $param) = @_;
1319
        
1320
        return $self->SUPER::insert(param => $param);
1321
    }
1322

            
1323
    sub list { shift->select; }
1324

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1325
    package MyModel2::Company;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1326

            
1327
    use strict;
1328
    use warnings;
1329

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1330
    use base 'MyModel2::Base1';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1331

            
1332
    sub insert {
1333
        my ($self, $param) = @_;
1334
        
1335
        return $self->SUPER::insert(param => $param);
1336
    }
1337

            
1338
    sub list { shift->select; }
1339
}
1340
$dbi = MyDBI4->connect($NEW_ARGS->{0});
1341
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1342
$model = $dbi->model('book');
1343
$model->insert({title => 'a', author => 'b'});
1344
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1345
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1346
$model = $dbi->model('company');
1347
$model->insert({name => 'a'});
1348
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
1349

            
1350
{
1351
     package MyDBI5;
1352

            
1353
    use strict;
1354
    use warnings;
1355

            
1356
    use base 'DBIx::Custom';
1357

            
1358
    sub connect {
1359
        my $self = shift->SUPER::connect(@_);
1360
        
1361
        $self->include_model('MyModel4');
1362
    }
1363
}
1364
$dbi = MyDBI5->connect($NEW_ARGS->{0});
1365
$dbi->execute("create table company (name)");
1366
$model = $dbi->model('company');
1367
$model->insert({name => 'a'});
1368
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'include all model');
1369
$model = $dbi->model('book');
1370
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'include all model');
1371

            
1372