DBIx-Custom / t / dbix-custom-core-sqlite.t /
Newer Older
779 lines | 30.562kb
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
19
my $test;
20
sub test {
21
    $test = shift;
22
}
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));',
28
    2 => 'create table table2 (key1 char(255), key3 char(255));'
29
};
30

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

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

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

            
43
# Variables
44
my $dbi;
45
my $sth;
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
46
my $source;
47
my @sources;
add tests
yuki-kimoto authored on 2010-08-10
48
my $select_SOURCE;
49
my $insert_SOURCE;
50
my $update_SOURCE;
removed register_format()
yuki-kimoto authored on 2010-05-26
51
my $params;
52
my $sql;
53
my $result;
54
my $row;
55
my @rows;
56
my $rows;
57
my $query;
58
my @queries;
59
my $select_query;
60
my $insert_query;
61
my $update_query;
62
my $ret_val;
63

            
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
}
removed reconnect method
yuki-kimoto authored on 2010-05-28
80
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : 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
}
removed reconnect method
yuki-kimoto authored on 2010-05-28
87
is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : fetch_hash");
removed register_format()
yuki-kimoto authored on 2010-05-26
88

            
89
$result = $dbi->execute($query);
90
$rows = $result->fetch_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
91
is_deeply($rows, [[1, 2], [3, 4]], "$test : 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;
95
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : 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});
103
ok($ret_val, $test);
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;
113
is_deeply($rows, [{key1 => 1, key2 => 2}], $test);
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;
127
is_deeply($rows, [{key1 => 2, key2 => 6}], "$test : filter fetch_filter");
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;
140
is_deeply($rows, [{key1 => 2, key2 => 4}], "$test : filter");
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;
152
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag1");
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;
158
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2");
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;
170
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic");
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;
179
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic");
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},
193
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : basic");
194

            
195
test 'Error case';
196
eval {DBIx::Custom->connect(data_source => 'dbi:SQLit')};
197
ok($@, "$test : connect error");
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 }")};
201
ok($@, "$test : 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;
210
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : basic");
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;
221
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : 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)};
add tests
yuki-kimoto authored on 2010-08-10
231
like($@, qr/noexist/, "$test: 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}],
244
                  "$test : basic");
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}],
254
                  "$test : update key same as search key");
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}],
261
                  "$test : update key same as search key : param is array ref");
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},
268
              filter => {key2 => 'twice'});
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}],
273
                  "$test : filter");
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)};
add tests
yuki-kimoto authored on 2010-08-10
278
like($@, qr/noexist/, "$test: invalid argument");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
279

            
280
eval{$dbi->update(table => 'table1')};
281
like($@, qr/where/, "$test: not contain where");
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}],
295
                  "$test : filter");
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;
306
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : basic");
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;
315
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : filter");
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;
324
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : delete multi key");
325

            
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
326
eval{$dbi->delete(table => 'table1', noexist => 1)};
add tests
yuki-kimoto authored on 2010-08-10
327
like($@, qr/noexist/, "$test: 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/,
removed register_format()
yuki-kimoto authored on 2010-05-26
335
         "$test : where key-value pairs not specified");
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;
345
is_deeply($rows, [], "$test : basic");
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},
355
                  {key1 => 3, key2 => 4}], "$test : table");
356

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

            
360
$rows = $dbi->select(table => 'table1', where => {key1 => 1})->fetch_hash_all;
361
is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : table and columns and where key");
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;
364
is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : table and columns and where string");
365

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

            
369
$rows = $dbi->select(table => 'table1', append => "order by key1 desc limit 1")->fetch_hash_all;
370
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : append statement");
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;
375
is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : filter");
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;
added commit method
yuki-kimoto authored on 2010-05-27
385
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "$test : relation : exists where");
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;
392
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "$test : 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)};
add tests
yuki-kimoto authored on 2010-08-10
395
like($@, qr/noexist/, "$test: 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;
removed register_format()
yuki-kimoto authored on 2010-05-26
410
is_deeply($row, {key1 => 3, key2 => 4}, "$test: default_fetch_filter and filter");
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('あ')),
416
   'あ', "$test : decode_utf8");
removed register_format()
yuki-kimoto authored on 2010-05-26
417

            
418
is($dbi->filters->{encode_utf8}->('あ'),
419
   encode_utf8('あ'), "$test : encode_utf8");
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}],
430
          "$test : commit");
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');
removed reconnect method
yuki-kimoto authored on 2010-05-28
439
ok(! $result->fetch_first, "$test: 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}, 
add cache attribute
yuki-kimoto authored on 2010-06-14
447
          {sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2']}, "$test : cache");
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

            
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
456

            
added check_filter attribute
yuki-kimoto authored on 2010-08-08
457
test 'filter_check in fetching';
458
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
459
$dbi->execute($CREATE_TABLE->{0});
460
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
461
$dbi->default_fetch_filter('not_exists');
462
$result = $dbi->select(table => 'table1');
463
eval{$result->fetch_first};
464
like($@, qr/\QDefault fetch filter "not_exists" is not registered/, "$test : array :default_fetch_filter");
465

            
466
$dbi->default_fetch_filter(undef);
467
$result = $dbi->select(table => 'table1');
468
$result->filter({key1 => 'not_exists'});
469
eval{$result->fetch_first};
470
like($@, qr/\QFetch filter "not_exists" is not registered/, "$test :  array :fetch_filter");
471

            
472
$dbi->filter_check(0);
473
$result = $dbi->select(table => 'table1');
474
$result->filter({Key1 => 'encode_utf8'});
475
eval{$result->fetch_first};
476
ok(!$@, "$test : array : filter_check off");
477

            
478
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
479
$dbi->execute($CREATE_TABLE->{0});
480
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
481
$dbi->default_fetch_filter('not_exists');
482
$result = $dbi->select(table => 'table1');
483
eval{$result->fetch_hash_first};
484
like($@, qr/\QDefault fetch filter "not_exists" is not registered/, "$test : hash :default_fetch_filter");
485

            
486
$dbi->default_fetch_filter(undef);
487
$result = $dbi->select(table => 'table1');
488
$result->filter({key1 => 'not_exists'});
489
eval{$result->fetch_hash_first};
490
like($@, qr/\QFetch filter "not_exists" is not registered/, "$test : hash :fetch_filter");
491

            
492
$dbi->filter_check(0);
493
$result = $dbi->select(table => 'table1');
494
$result->filter({Key1 => 'encode_utf8'});
495
eval{$result->fetch_hash_first};
496
ok(!$@, "$test : hash : filter_check off");
497

            
add tests
yuki-kimoto authored on 2010-08-08
498
test 'filter_check in parameter binding';
added check_filter attribute
yuki-kimoto authored on 2010-08-08
499
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
500
$dbi->execute($CREATE_TABLE->{0});
501
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
502

            
add tests
yuki-kimoto authored on 2010-08-08
503
$dbi->default_bind_filter('not_exists');
504
eval{$dbi->select(table => 'table1')};
505
like($@, qr/\QDefault bind filter "not_exists" is not registered/, "$test : default_bind_filter");
added check_filter attribute
yuki-kimoto authored on 2010-08-08
506

            
add tests
yuki-kimoto authored on 2010-08-08
507
$dbi->default_bind_filter(undef);
508
eval{$dbi->select(table => 'table1', filter => {key1 => 'not_exists'})};
509
like($@, qr/\QBind filter "not_exists" is not registered/, "$test : bind_filter");
added check_filter attribute
yuki-kimoto authored on 2010-08-08
510

            
add tests
yuki-kimoto authored on 2010-08-10
511
test 'execute';
512
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
513
$dbi->execute($CREATE_TABLE->{0});
removed experimental registe...
yuki-kimoto authored on 2010-08-24
514
{
515
    local $Carp::Verbose = 0;
516
    eval{$dbi->execute('select * frm table1')};
517
    like($@, qr/\Qselect * frm table1;/, "$test : fail prepare");
518
    like($@, qr/\.t /, "$test: fail : not verbose");
519
}
520
{
521
    local $Carp::Verbose = 1;
522
    eval{$dbi->execute('select * frm table1')};
523
    like($@, qr/Custom.*\.t /s, "$test : fail : verbose");
524
}
add tests
yuki-kimoto authored on 2010-08-10
525

            
526
eval{$dbi->execute('select * from table1', no_exists => 1)};
527
like($@, qr/\Q"no_exists" is invalid argument/, "$test : invald SQL");
528

            
529
$query = $dbi->create_query('select * from table1 where {= key1}');
530
$dbi->dbh->disconnect;
531
eval{$dbi->execute($query, param => {key1 => {a => 1}})};
532
ok($@, "$test: execute fail");
533

            
removed experimental registe...
yuki-kimoto authored on 2010-08-24
534
{
535
    local $Carp::Verbose = 0;
536
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
537
    like($@, qr/\Q.t /, "$test : caller spec : not vebose");
538
}
539
{
540
    local $Carp::Verbose = 1;
541
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
542
    like($@, qr/QueryBuilder.*\.t /s, "$test : caller spec : not vebose");
543
}
cleanup
yuki-kimoto authored on 2010-10-17
544

            
545

            
546
test 'transaction';
547
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
548
$dbi->execute($CREATE_TABLE->{0});
549

            
550
$dbi->begin_work;
551

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

            
558
$dbi->rollback if $@;
559

            
560
$result = $dbi->select(table => 'table1');
561
$rows = $result->fetch_hash_all;
562
is_deeply($rows, [], "$test : rollback");
563

            
564
$dbi->begin_work;
565

            
566
eval {
567
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
568
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
569
};
570

            
571
$dbi->commit unless $@;
572

            
573
$result = $dbi->select(table => 'table1');
574
$rows = $result->fetch_hash_all;
575
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : commit");
576

            
577
$dbi->dbh->{AutoCommit} = 0;
578
eval{ $dbi->begin_work };
579
ok($@, "$test : exception");
580
$dbi->dbh->{AutoCommit} = 1;
581

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

            
583
test 'helper';
584
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
585
$dbi->helper(
586
    one => sub { 1 }
587
);
588
$dbi->helper(
589
    two => sub { 2 }
590
);
591
$dbi->helper({
592
    twice => sub {
593
        my $self = shift;
594
        return $_[0] * 2;
595
    }
596
});
597

            
598
is($dbi->one, 1, "$test : first");
599
is($dbi->two, 2, "$test : second");
600
is($dbi->twice(5), 10 , "$test : second");
601

            
602
eval {$dbi->XXXXXX};
603
like($@, qr/\QCan't locate object method "XXXXXX" via "DBIx::Custom"/, "$test : not exists");
604

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
605
test 'auto bind filter';
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->auto_filter(
611
    'table1', ['key1', 'twice', 'twice'], ['key2', 'three_times', 'three_times']);
612
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
613
$result = $dbi->execute($SELECT_SOURCES->{0});
614
$row   = $result->fetch_hash_first;
615
is_deeply($row, {key1 => 2, key2 => 6}, "$test : insert");
616

            
617
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
618
$dbi->execute($CREATE_TABLE->{0});
619
$dbi->register_filter(twice => sub { $_[0] * 2 });
620
$dbi->register_filter(three_times => sub { $_[0] * 3});
621
$dbi->auto_filter(
622
    'table1', ['key1', 'twice', 'twice'], ['key2', 'three_times', 'three_times']);
623
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, auto_filter_table => undef);
624
$result = $dbi->execute($SELECT_SOURCES->{0});
625
$row   = $result->fetch_hash_first;
626
is_deeply($row, {key1 => 1, key2 => 2}, "$test : insert disabe auto_filter_table 1");
627

            
628
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
629
$dbi->execute($CREATE_TABLE->{0});
630
$dbi->register_filter(twice => sub { $_[0] * 2 });
631
$dbi->register_filter(three_times => sub { $_[0] * 3});
632
$dbi->auto_filter(
633
    'table1', ['key1', 'twice', 'twice'], ['key2', 'three_times', 'three_times']);
634
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, auto_filter_table => []);
635
$result = $dbi->execute($SELECT_SOURCES->{0});
636
$row   = $result->fetch_hash_first;
637
is_deeply($row, {key1 => 1, key2 => 2}, "$test : insert disabe auto_filter_table 2");
638

            
639
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
640
$dbi->execute($CREATE_TABLE->{0});
641
$dbi->register_filter(twice => sub { $_[0] * 2 });
642
$dbi->auto_filter(
643
    'table1', ['key1', 'twice', 'twice']
644
);
645
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, auto_filter_table => undef);
646
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2});
647
$result = $dbi->execute($SELECT_SOURCES->{0});
648
$row   = $result->fetch_hash_first;
649
is_deeply($row, {key1 => 4, key2 => 2}, "$test : update");
650

            
651
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
652
$dbi->execute($CREATE_TABLE->{0});
653
$dbi->register_filter(twice => sub { $_[0] * 2 });
654
$dbi->auto_filter(
655
    'table1', ['key1', 'twice', 'twice']
656
);
657
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, auto_filter_table => undef);
658
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2}, auto_filter_table => []);
659
$result = $dbi->execute($SELECT_SOURCES->{0});
660
$row   = $result->fetch_hash_first;
661
is_deeply($row, {key1 => 2, key2 => 2}, "$test : update : disable bind filter1");
662

            
663
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
664
$dbi->execute($CREATE_TABLE->{0});
665
$dbi->register_filter(twice => sub { $_[0] * 2 });
666
$dbi->auto_filter(
667
    'table1', ['key1', 'twice', 'twice']
668
);
669
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, auto_filter_table => undef);
670
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2}, auto_filter_table => undef);
671
$result = $dbi->execute($SELECT_SOURCES->{0});
672
$row   = $result->fetch_hash_first;
673
is_deeply($row, {key1 => 2, key2 => 2}, "$test : update : disable bind filter2");
674

            
675
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
676
$dbi->execute($CREATE_TABLE->{0});
677
$dbi->register_filter(twice => sub { $_[0] * 2 });
678
$dbi->auto_filter(
679
    'table1', ['key1', 'twice', 'twice']
680
);
681
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, auto_filter_table => undef);
682
$dbi->delete(table => 'table1', where => {key1 => 1});
683
$result = $dbi->execute($SELECT_SOURCES->{0});
684
$rows   = $result->fetch_hash_all;
685
is_deeply($rows, [], "$test : delete");
686

            
687
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
688
$dbi->execute($CREATE_TABLE->{0});
689
$dbi->register_filter(twice => sub { $_[0] * 2 });
690
$dbi->auto_filter(
691
    'table1', ['key1', 'twice', 'twice']
692
);
693
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, auto_filter_table => undef);
694
$dbi->delete(table => 'table1', where => {key1 => 1}, auto_filter_table => undef);
695
$result = $dbi->execute($SELECT_SOURCES->{0});
696
$rows   = $result->fetch_hash_all;
697
is_deeply($rows, [{key1 => 2, key2 => 2}], "$test : delete : disable1");
698

            
699
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
700
$dbi->execute($CREATE_TABLE->{0});
701
$dbi->register_filter(twice => sub { $_[0] * 2 });
702
$dbi->auto_filter(
703
    'table1', ['key1', 'twice', 'twice']
704
);
705
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, auto_filter_table => undef);
706
$dbi->delete(table => 'table1', where => {key1 => 1}, auto_filter_table => []);
707
$result = $dbi->execute($SELECT_SOURCES->{0});
708
$rows   = $result->fetch_hash_all;
709
is_deeply($rows, [{key1 => 2, key2 => 2}], "$test : delete : disable2");
710

            
711
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
712
$dbi->execute($CREATE_TABLE->{0});
713
$dbi->register_filter(twice => sub { $_[0] * 2 });
714
$dbi->auto_filter(
715
    'table1', ['key1', 'twice', 'twice']
716
);
717
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, auto_filter_table => undef);
718
$result = $dbi->select(table => 'table1', where => {key1 => 1});
719
$result->filter({'key2' => 'twice'});
720
$rows   = $result->fetch_hash_all;
721
is_deeply($rows, [{key1 => 4, key2 => 4}], "$test : select");
722

            
723
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
724
$dbi->execute($CREATE_TABLE->{0});
725
$dbi->register_filter(twice => sub { $_[0] * 2 });
726
$dbi->auto_filter(
727
    'table1', ['key1', 'twice', 'twice']
728
);
729
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, auto_filter_table => undef);
730
$result = $dbi->select(table => 'table1', where => {key1 => 2}, auto_filter_table => []);
731
$result->filter({'key2' => 'twice'});
732
$rows   = $result->fetch_hash_all;
733
is_deeply($rows, [{key1 => 2, key2 => 4}], "$test : select : disable");
734

            
735
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
736
$dbi->execute($CREATE_TABLE->{0});
737
$dbi->register_filter(twice => sub { $_[0] * 2 });
738
$dbi->auto_filter(
739
    'table1', ['key1', 'twice', 'twice']
740
);
741
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, auto_filter_table => undef);
742
$result = $dbi->execute("select * from table1 where {= key1} and {= key2};",
743
                        param => {key1 => 1, key2 => 2},
744
                        auto_filter_table => ['table1']);
745
$rows   = $result->fetch_hash_all;
746
is_deeply($rows, [{key1 => 4, key2 => 2}], "$test : execute");
747

            
748
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
749
$dbi->execute($CREATE_TABLE->{0});
750
$dbi->execute($CREATE_TABLE->{2});
751
$dbi->register_filter(twice => sub { $_[0] * 2 });
752
$dbi->register_filter(three_times => sub { $_[0] * 3 });
753
$dbi->auto_filter(
754
    'table1', ['key2', 'twice', 'twice']
755
);
756
$dbi->auto_filter(
757
    'table2', ['key3', 'three_times', 'three_times']
758
);
759
$dbi->insert(table => 'table1', param => {key1 => 5, key2 => 2}, auto_filter_table => undef);
760
$dbi->insert(table => 'table2', param => {key1 => 5, key3 => 6}, auto_filter_table => undef);
761
$result = $dbi->select(
762
     table => ['table1', 'table2'],
763
     column => ['key2', 'key3'],
764
     where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
765

            
766
$result->filter({'key2' => 'twice'});
767
$rows   = $result->fetch_hash_all;
768
is_deeply($rows, [{key2 => 4, key3 => 18}], "$test : select : join");
769

            
770
$result = $dbi->select(
771
     table => ['table1', 'table2'],
772
     column => ['key2', 'key3'],
773
     where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
774

            
775
$result->filter({'key2' => 'twice'});
776
$rows   = $result->fetch_hash_all;
777
is_deeply($rows, [{key2 => 4, key3 => 18}], "$test : select : join : omit");
778

            
779