DBIx-Custom / t / dbix-custom-core-sqlite.t /
Newer Older
773 lines | 30.795kb
packaging one directory
yuki-kimoto authored on 2009-11-16
1
use Test::More;
2
use strict;
3
use warnings;
4

            
5
BEGIN {
6
    eval { require DBD::SQLite; 1 }
7
        or plan skip_all => 'DBD::SQLite required';
8
    eval { DBD::SQLite->VERSION >= 1.25 }
9
        or plan skip_all => 'DBD::SQLite >= 1.25 required';
10

            
11
    plan 'no_plan';
12
    use_ok('DBIx::Custom');
13
}
14

            
15
# Function for test name
16
my $test;
17
sub test {
18
    $test = shift;
19
}
20

            
21
# Constant varialbes for test
22
my $CREATE_TABLE = {
23
    0 => 'create table table1 (key1 char(255), key2 char(255));',
24
    1 => 'create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));',
25
    2 => 'create table table2 (key1 char(255), key3 char(255));'
26
};
27

            
28
my $SELECT_TMPL = {
29
    0 => 'select * from table1;'
30
};
31

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

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

            
40
# Variables for test
41
my $dbi;
42
my $sth;
43
my $tmpl;
44
my @tmpls;
45
my $select_tmpl;
46
my $insert_tmpl;
47
my $update_tmpl;
48
my $params;
49
my $sql;
50
my $result;
51
my @rows;
52
my $rows;
53
my $query;
54
my @queries;
55
my $select_query;
56
my $insert_query;
57
my $update_query;
58
my $ret_val;
59

            
60

            
61
test 'disconnect';
62
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
63
$dbi->connect;
64
$dbi->disconnect;
65
ok(!$dbi->dbh, $test);
66

            
67

            
68
test 'connected';
69
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
70
ok(!$dbi->connected, "$test : not connected");
71
$dbi->connect;
72
ok($dbi->connected, "$test : connected");
73

            
74

            
75
test 'preapare';
76
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
77
$sth = $dbi->prepare($CREATE_TABLE->{0});
78
ok($sth, "$test : auto connect");
79
$sth->execute;
80
$sth = $dbi->prepare($DROP_TABLE->{0});
81
ok($sth, "$test : basic");
82

            
83

            
84
test 'do';
85
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
86
$ret_val = $dbi->do($CREATE_TABLE->{0});
87
ok(defined $ret_val, "$test : auto connect");
88
$ret_val = $dbi->do($DROP_TABLE->{0});
89
ok(defined $ret_val, "$test : basic");
90

            
version 0.0901
yuki-kimoto authored on 2009-12-17
91
test 'create_table';
92
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
93
$ret_val = $dbi->create_table(
94
                   'table1',
95
                   'key1 char(255)',
96
                   'key2 char(255)'
97
                 );
98
ok(defined $ret_val, "$test : create_table");
99

            
cleanup
yuki-kimoto authored on 2010-02-11
100
$dbi->insert('table1', {key1 => 1, key2 => 2});
version 0.0901
yuki-kimoto authored on 2009-12-17
101
ok(!$@, "$test : table exist");
102

            
103
$ret_val = $dbi->drop_table('table1');
104
ok(defined $ret_val, "$test : drop table");
105

            
106
eval{$dbi->select('table1')};
107
ok($@, "$test : table not exist");
packaging one directory
yuki-kimoto authored on 2009-11-16
108

            
109
# Prepare table
110
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
111
$dbi->connect;
112
$dbi->do($CREATE_TABLE->{0});
113
$sth = $dbi->prepare("insert into table1 (key1, key2) values (?, ?);");
114
$sth->execute(1, 2);
115
$sth->execute(3, 4);
116

            
117

            
118
test 'DBIx::Custom::Result test';
119
$tmpl = "select key1, key2 from table1";
120
$query = $dbi->create_query($tmpl);
version 0.0901
yuki-kimoto authored on 2009-12-17
121
$result = $dbi->query($query);
packaging one directory
yuki-kimoto authored on 2009-11-16
122

            
123
@rows = ();
124
while (my $row = $result->fetch) {
125
    push @rows, [@$row];
126
}
127
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch scalar context");
128

            
version 0.0901
yuki-kimoto authored on 2009-12-17
129
$result = $dbi->query($query);
packaging one directory
yuki-kimoto authored on 2009-11-16
130
@rows = ();
131
while (my @row = $result->fetch) {
132
    push @rows, [@row];
133
}
134
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch list context");
135

            
version 0.0901
yuki-kimoto authored on 2009-12-17
136
$result = $dbi->query($query);
packaging one directory
yuki-kimoto authored on 2009-11-16
137
@rows = ();
138
while (my $row = $result->fetch_hash) {
139
    push @rows, {%$row};
140
}
141
is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : fetch_hash scalar context");
142

            
version 0.0901
yuki-kimoto authored on 2009-12-17
143
$result = $dbi->query($query);
packaging one directory
yuki-kimoto authored on 2009-11-16
144
@rows = ();
145
while (my %row = $result->fetch_hash) {
146
    push @rows, {%row};
147
}
148
is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : fetch hash list context");
149

            
version 0.0901
yuki-kimoto authored on 2009-12-17
150
$result = $dbi->query($query);
packaging one directory
yuki-kimoto authored on 2009-11-16
151
$rows = $result->fetch_all;
152
is_deeply($rows, [[1, 2], [3, 4]], "$test : fetch_all scalar context");
153

            
version 0.0901
yuki-kimoto authored on 2009-12-17
154
$result = $dbi->query($query);
packaging one directory
yuki-kimoto authored on 2009-11-16
155
@rows = $result->fetch_all;
156
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch_all list context");
157

            
version 0.0901
yuki-kimoto authored on 2009-12-17
158
$result = $dbi->query($query);
packaging one directory
yuki-kimoto authored on 2009-11-16
159
@rows = $result->fetch_hash_all;
160
is_deeply($rows, [[1, 2], [3, 4]], "$test : fetch_hash_all scalar context");
161

            
version 0.0901
yuki-kimoto authored on 2009-12-17
162
$result = $dbi->query($query);
packaging one directory
yuki-kimoto authored on 2009-11-16
163
@rows = $result->fetch_all;
164
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch_hash_all list context");
165

            
166

            
167
test 'Insert query return value';
168
$dbi->do($DROP_TABLE->{0});
169
$dbi->do($CREATE_TABLE->{0});
170
$tmpl = "insert into table1 {insert key1 key2}";
171
$query = $dbi->create_query($tmpl);
version 0.0901
yuki-kimoto authored on 2009-12-17
172
$ret_val = $dbi->query($query, {key1 => 1, key2 => 2});
packaging one directory
yuki-kimoto authored on 2009-11-16
173
ok($ret_val, $test);
174

            
175

            
version 0.0901
yuki-kimoto authored on 2009-12-17
176
test 'Direct query';
packaging one directory
yuki-kimoto authored on 2009-11-16
177
$dbi->do($DROP_TABLE->{0});
178
$dbi->do($CREATE_TABLE->{0});
179
$insert_tmpl = "insert into table1 {insert key1 key2}";
version 0.0901
yuki-kimoto authored on 2009-12-17
180
$dbi->query($insert_tmpl, {key1 => 1, key2 => 2}, sub {
packaging one directory
yuki-kimoto authored on 2009-11-16
181
    my $query = shift;
182
    $query->bind_filter(sub {
183
        my ($value, $key) = @_;
184
        if ($key eq 'key2') {
185
            return $value + 1;
186
        }
187
        return $value;
188
    });
189
});
version 0.0901
yuki-kimoto authored on 2009-12-17
190
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
191
$rows = $result->fetch_hash_all;
192
is_deeply($rows, [{key1 => 1, key2 => 3}], $test);
193

            
194

            
195
test 'Filter basic';
196
$dbi->do($DROP_TABLE->{0});
197
$dbi->do($CREATE_TABLE->{0});
198

            
199
$insert_tmpl  = "insert into table1 {insert key1 key2};";
200
$insert_query = $dbi->create_query($insert_tmpl);
201
$insert_query->bind_filter(sub {
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
202
    my ($value, $key, $dbi, $infos) = @_;
203
    my ($table, $column) = @{$infos}{qw/table column/};
204
    
205
    if ($key eq 'key1' && $table eq '' && $column eq 'key1'
206
        && $dbi->isa('DBIx::Custom'))
207
    {
packaging one directory
yuki-kimoto authored on 2009-11-16
208
        return $value * 2;
209
    }
210
    return $value;
211
});
version 0.0901
yuki-kimoto authored on 2009-12-17
212
$dbi->query($insert_query, {key1 => 1, key2 => 2});
packaging one directory
yuki-kimoto authored on 2009-11-16
213
$select_query = $dbi->create_query($SELECT_TMPL->{0});
214
$select_query->fetch_filter(sub {
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
215
    my ($value, $key, $dbi, $infos) = @_;
216
    my ($type, $sth, $i) = @{$infos}{qw/type sth index/};
217
    
218
    if ($key eq 'key2' && $type =~ /char/ && ref $sth eq 'DBI::st' 
219
        && $i == 1 && $dbi->isa('DBIx::Custom'))
220
    {
packaging one directory
yuki-kimoto authored on 2009-11-16
221
        return $value * 3;
222
    }
223
    return $value;
224
});
version 0.0901
yuki-kimoto authored on 2009-12-17
225
$result = $dbi->query($select_query);
packaging one directory
yuki-kimoto authored on 2009-11-16
226
$rows = $result->fetch_hash_all;
227
is_deeply($rows, [{key1 => 2, key2 => 6}], "$test : bind_filter fetch_filter");
228

            
229
$dbi->do("delete from table1;");
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
230
$insert_query->no_bind_filters(['key1']);
231
$select_query->no_fetch_filters(['key2']);
version 0.0901
yuki-kimoto authored on 2009-12-17
232
$dbi->query($insert_query, {key1 => 1, key2 => 2});
233
$result = $dbi->query($select_query);
packaging one directory
yuki-kimoto authored on 2009-11-16
234
$rows = $result->fetch_hash_all;
235
is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : no_fetch_filters no_bind_filters");
236

            
237
$dbi->do($DROP_TABLE->{0});
238
$dbi->do($CREATE_TABLE->{0});
239
$insert_tmpl  = "insert into table1 {insert table1.key1 table1.key2}";
240
$insert_query = $dbi->create_query($insert_tmpl);
241
$insert_query->bind_filter(sub {
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
242
    my ($value, $key, $dbi, $infos) = @_;
243
    my ($table, $column) = @{$infos}{qw/table column/};
244
    
packaging one directory
yuki-kimoto authored on 2009-11-16
245
    if ($key eq 'table1.key1' && $table eq 'table1' && $column eq 'key1') {
246
        return $value * 3;
247
    }
248
    return $value;
249
});
version 0.0901
yuki-kimoto authored on 2009-12-17
250
$dbi->query($insert_query, {table1 => {key1 => 1, key2 => 2}});
packaging one directory
yuki-kimoto authored on 2009-11-16
251
$select_query = $dbi->create_query($SELECT_TMPL->{0});
version 0.0901
yuki-kimoto authored on 2009-12-17
252
$result       = $dbi->query($select_query);
packaging one directory
yuki-kimoto authored on 2009-11-16
253
$rows = $result->fetch_hash_all;
254
is_deeply($rows, [{key1 => 3, key2 => 2}], "$test : insert with table name");
255

            
256
test 'Filter in';
257
$insert_tmpl  = "insert into table1 {insert key1 key2};";
258
$insert_query = $dbi->create_query($insert_tmpl);
version 0.0901
yuki-kimoto authored on 2009-12-17
259
$dbi->query($insert_query, {key1 => 2, key2 => 4});
packaging one directory
yuki-kimoto authored on 2009-11-16
260
$select_tmpl = "select * from table1 where {in table1.key1 2} and {in table1.key2 2}";
261
$select_query = $dbi->create_query($select_tmpl);
262
$select_query->bind_filter(sub {
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
263
    my ($value, $key, $dbi, $infos) = @_;
264
    my ($table, $column) = @{$infos}{qw/table column/};
265
    
packaging one directory
yuki-kimoto authored on 2009-11-16
266
    if ($key eq 'table1.key1' && $table eq 'table1' && $column eq 'key1' || $key eq 'table1.key2') {
267
        return $value * 2;
268
    }
269
    return $value;
270
});
version 0.0901
yuki-kimoto authored on 2009-12-17
271
$result = $dbi->query($select_query, {table1 => {key1 => [1,5], key2 => [2,5]}});
packaging one directory
yuki-kimoto authored on 2009-11-16
272
$rows = $result->fetch_hash_all;
273
is_deeply($rows, [{key1 => 2, key2 => 4}], "$test : bind_filter");
274

            
275

            
276
test 'DBIx::Custom::SQL::Template basic tag';
277
$dbi->do($DROP_TABLE->{0});
278
$dbi->do($CREATE_TABLE->{1});
279
$sth = $dbi->prepare("insert into table1 (key1, key2, key3, key4, key5) values (?, ?, ?, ?, ?);");
280
$sth->execute(1, 2, 3, 4, 5);
281
$sth->execute(6, 7, 8, 9, 10);
282

            
283
$tmpl = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};";
284
$query = $dbi->create_query($tmpl);
version 0.0901
yuki-kimoto authored on 2009-12-17
285
$result = $dbi->query($query, {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
packaging one directory
yuki-kimoto authored on 2009-11-16
286
$rows = $result->fetch_hash_all;
287
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag1");
288

            
289
$tmpl = "select * from table1 where {= table1.key1} and {<> table1.key2} and {< table1.key3} and {> table1.key4} and {>= table1.key5};";
290
$query = $dbi->create_query($tmpl);
version 0.0901
yuki-kimoto authored on 2009-12-17
291
$result = $dbi->query($query, {table1 => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5}});
packaging one directory
yuki-kimoto authored on 2009-11-16
292
$rows = $result->fetch_hash_all;
293
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag1 with table");
294

            
295
$tmpl = "select * from table1 where {= table1.key1} and {<> table1.key2} and {< table1.key3} and {> table1.key4} and {>= table1.key5};";
296
$query = $dbi->create_query($tmpl);
version 0.0901
yuki-kimoto authored on 2009-12-17
297
$result = $dbi->query($query, {'table1.key1' => 1, 'table1.key2' => 3, 'table1.key3' => 4, 'table1.key4' => 3, 'table1.key5' => 5});
packaging one directory
yuki-kimoto authored on 2009-11-16
298
$rows = $result->fetch_hash_all;
299
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag1 with table dot");
300

            
301
$tmpl = "select * from table1 where {<= key1} and {like key2};";
302
$query = $dbi->create_query($tmpl);
version 0.0901
yuki-kimoto authored on 2009-12-17
303
$result = $dbi->query($query, {key1 => 1, key2 => '%2%'});
packaging one directory
yuki-kimoto authored on 2009-11-16
304
$rows = $result->fetch_hash_all;
305
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2");
306

            
307
$tmpl = "select * from table1 where {<= table1.key1} and {like table1.key2};";
308
$query = $dbi->create_query($tmpl);
version 0.0901
yuki-kimoto authored on 2009-12-17
309
$result = $dbi->query($query, {table1 => {key1 => 1, key2 => '%2%'}});
packaging one directory
yuki-kimoto authored on 2009-11-16
310
$rows = $result->fetch_hash_all;
311
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2 with table");
312

            
313
$tmpl = "select * from table1 where {<= table1.key1} and {like table1.key2};";
314
$query = $dbi->create_query($tmpl);
version 0.0901
yuki-kimoto authored on 2009-12-17
315
$result = $dbi->query($query, {'table1.key1' => 1, 'table1.key2' => '%2%'});
packaging one directory
yuki-kimoto authored on 2009-11-16
316
$rows = $result->fetch_hash_all;
317
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2 with table dot");
318

            
319

            
320
test 'DIB::Custom::SQL::Template in tag';
321
$dbi->do($DROP_TABLE->{0});
322
$dbi->do($CREATE_TABLE->{1});
323
$sth = $dbi->prepare("insert into table1 (key1, key2, key3, key4, key5) values (?, ?, ?, ?, ?);");
324
$sth->execute(1, 2, 3, 4, 5);
325
$sth->execute(6, 7, 8, 9, 10);
326

            
327
$tmpl = "select * from table1 where {in key1 2};";
328
$query = $dbi->create_query($tmpl);
version 0.0901
yuki-kimoto authored on 2009-12-17
329
$result = $dbi->query($query, {key1 => [9, 1]});
packaging one directory
yuki-kimoto authored on 2009-11-16
330
$rows = $result->fetch_hash_all;
331
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic");
332

            
333
$tmpl = "select * from table1 where {in table1.key1 2};";
334
$query = $dbi->create_query($tmpl);
version 0.0901
yuki-kimoto authored on 2009-12-17
335
$result = $dbi->query($query, {table1 => {key1 => [9, 1]}});
packaging one directory
yuki-kimoto authored on 2009-11-16
336
$rows = $result->fetch_hash_all;
337
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table");
338

            
339
$tmpl = "select * from table1 where {in table1.key1 2};";
340
$query = $dbi->create_query($tmpl);
version 0.0901
yuki-kimoto authored on 2009-12-17
341
$result = $dbi->query($query, {'table1.key1' => [9, 1]});
packaging one directory
yuki-kimoto authored on 2009-11-16
342
$rows = $result->fetch_hash_all;
343
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table dot");
344

            
345

            
346
test 'DBIx::Custom::SQL::Template insert tag';
347
$dbi->do("delete from table1");
348
$insert_tmpl = 'insert into table1 {insert key1 key2 key3 key4 key5}';
version 0.0901
yuki-kimoto authored on 2009-12-17
349
$dbi->query($insert_tmpl, {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
packaging one directory
yuki-kimoto authored on 2009-11-16
350

            
version 0.0901
yuki-kimoto authored on 2009-12-17
351
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
352
$rows = $result->fetch_hash_all;
353
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic");
354

            
355
$dbi->do("delete from table1");
version 0.0901
yuki-kimoto authored on 2009-12-17
356
$dbi->query($insert_tmpl, {'#insert' => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}});
357
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
358
$rows = $result->fetch_hash_all;
359
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : #insert");
360

            
361
$dbi->do("delete from table1");
362
$insert_tmpl = 'insert into table1 {insert table1.key1 table1.key2 table1.key3 table1.key4 table1.key5}';
version 0.0901
yuki-kimoto authored on 2009-12-17
363
$dbi->query($insert_tmpl, {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}});
364
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
365
$rows = $result->fetch_hash_all;
366
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table name");
367

            
368
$dbi->do("delete from table1");
369
$insert_tmpl = 'insert into table1 {insert table1.key1 table1.key2 table1.key3 table1.key4 table1.key5}';
version 0.0901
yuki-kimoto authored on 2009-12-17
370
$dbi->query($insert_tmpl, {'table1.key1' => 1, 'table1.key2' => 2, 'table1.key3' => 3, 'table1.key4' => 4, 'table1.key5' => 5});
371
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
372
$rows = $result->fetch_hash_all;
373
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table name dot");
374

            
375
$dbi->do("delete from table1");
version 0.0901
yuki-kimoto authored on 2009-12-17
376
$dbi->query($insert_tmpl, {'#insert' => {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}}});
377
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
378
$rows = $result->fetch_hash_all;
379
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : #insert with table name");
380

            
381
$dbi->do("delete from table1");
version 0.0901
yuki-kimoto authored on 2009-12-17
382
$dbi->query($insert_tmpl, {'#insert' => {'table1.key1' => 1, 'table1.key2' => 2, 'table1.key3' => 3, 'table1.key4' => 4, 'table1.key5' => 5}});
383
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
384
$rows = $result->fetch_hash_all;
385
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : #insert with table name dot");
386

            
387

            
388
test 'DBIx::Custom::SQL::Template update tag';
389
$dbi->do("delete from table1");
390
$insert_tmpl = "insert into table1 {insert key1 key2 key3 key4 key5}";
version 0.0901
yuki-kimoto authored on 2009-12-17
391
$dbi->query($insert_tmpl, {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
392
$dbi->query($insert_tmpl, {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
packaging one directory
yuki-kimoto authored on 2009-11-16
393

            
394
$update_tmpl = 'update table1 {update key1 key2 key3 key4} where {= key5}';
version 0.0901
yuki-kimoto authored on 2009-12-17
395
$dbi->query($update_tmpl, {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5});
packaging one directory
yuki-kimoto authored on 2009-11-16
396

            
version 0.0901
yuki-kimoto authored on 2009-12-17
397
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
398
$rows = $result->fetch_hash_all;
399
is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5},
400
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : basic");
401

            
version 0.0901
yuki-kimoto authored on 2009-12-17
402
$dbi->query($update_tmpl, {'#update' => {key1 => 2, key2 => 2, key3 => 2, key4 => 2}, key5 => 5});
403
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
404
$rows = $result->fetch_hash_all;
405
is_deeply($rows, [{key1 => 2, key2 => 2, key3 => 2, key4 => 2, key5 => 5},
406
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : #update");
407

            
408
$update_tmpl = 'update table1 {update table1.key1 table1.key2 table1.key3 table1.key4} where {= table1.key5}';
version 0.0901
yuki-kimoto authored on 2009-12-17
409
$dbi->query($update_tmpl, {table1 => {key1 => 3, key2 => 3, key3 => 3, key4 => 3, key5 => 5}});
410
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
411
$rows = $result->fetch_hash_all;
412
is_deeply($rows, [{key1 => 3, key2 => 3, key3 => 3, key4 => 3, key5 => 5},
413
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : with table name");
414

            
415
$update_tmpl = 'update table1 {update table1.key1 table1.key2 table1.key3 table1.key4} where {= table1.key5}';
version 0.0901
yuki-kimoto authored on 2009-12-17
416
$dbi->query($update_tmpl, {'table1.key1' => 4, 'table1.key2' => 4, 'table1.key3' => 4, 'table1.key4' => 4, 'table1.key5' => 5});
417
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
418
$rows = $result->fetch_hash_all;
419
is_deeply($rows, [{key1 => 4, key2 => 4, key3 => 4, key4 => 4, key5 => 5},
420
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : with table name dot");
421

            
version 0.0901
yuki-kimoto authored on 2009-12-17
422
$dbi->query($update_tmpl, {'#update' => {table1 => {key1 => 5, key2 => 5, key3 => 5, key4 => 5}}, table1 => {key5 => 5}});
423
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
424
$rows = $result->fetch_hash_all;
425
is_deeply($rows, [{key1 => 5, key2 => 5, key3 => 5, key4 => 5, key5 => 5},
426
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : update tag #update with table name");
427

            
version 0.0901
yuki-kimoto authored on 2009-12-17
428
$dbi->query($update_tmpl, {'#update' => {'table1.key1' => 6, 'table1.key2' => 6, 'table1.key3' => 6, 'table1.key4' => 6}, 'table1.key5' => 5});
429
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
430
$rows = $result->fetch_hash_all;
431
is_deeply($rows, [{key1 => 6, key2 => 6, key3 => 6, key4 => 6, key5 => 5},
432
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : update tag #update with table name dot");
433

            
434

            
remove run_transaction().
yuki-kimoto authored on 2010-01-30
435
test 'transaction';
packaging one directory
yuki-kimoto authored on 2009-11-16
436
$dbi->do($DROP_TABLE->{0});
437
$dbi->do($CREATE_TABLE->{0});
remove run_transaction().
yuki-kimoto authored on 2010-01-30
438
$dbi->transaction->run(sub {
packaging one directory
yuki-kimoto authored on 2009-11-16
439
    $insert_tmpl = 'insert into table1 {insert key1 key2}';
version 0.0901
yuki-kimoto authored on 2009-12-17
440
    $dbi->query($insert_tmpl, {key1 => 1, key2 => 2});
441
    $dbi->query($insert_tmpl, {key1 => 3, key2 => 4});
packaging one directory
yuki-kimoto authored on 2009-11-16
442
});
version 0.0901
yuki-kimoto authored on 2009-12-17
443
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
444
$rows   = $result->fetch_hash_all;
445
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : commit");
446

            
447
$dbi->do($DROP_TABLE->{0});
448
$dbi->do($CREATE_TABLE->{0});
449
$dbi->dbh->{RaiseError} = 0;
450
eval{
remove run_transaction().
yuki-kimoto authored on 2010-01-30
451
    $dbi->transaction->run(sub {
packaging one directory
yuki-kimoto authored on 2009-11-16
452
        $insert_tmpl = 'insert into table1 {insert key1 key2}';
version 0.0901
yuki-kimoto authored on 2009-12-17
453
        $dbi->query($insert_tmpl, {key1 => 1, key2 => 2});
packaging one directory
yuki-kimoto authored on 2009-11-16
454
        die "Fatal Error";
version 0.0901
yuki-kimoto authored on 2009-12-17
455
        $dbi->query($insert_tmpl, {key1 => 3, key2 => 4});
packaging one directory
yuki-kimoto authored on 2009-11-16
456
    })
457
};
458
like($@, qr/Fatal Error.*Rollback is success/ms, "$test : Rollback success message");
459
ok(!$dbi->dbh->{RaiseError}, "$test : restore RaiseError value");
version 0.0901
yuki-kimoto authored on 2009-12-17
460
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
461
$rows   = $result->fetch_hash_all;
462
is_deeply($rows, [], "$test : rollback");
463

            
464

            
remove run_transaction().
yuki-kimoto authored on 2010-01-30
465

            
packaging one directory
yuki-kimoto authored on 2009-11-16
466
test 'Error case';
467
$dbi = DBIx::Custom->new;
remove run_transaction().
yuki-kimoto authored on 2010-01-30
468
eval{$dbi->transaction->run};
packaging one directory
yuki-kimoto authored on 2009-11-16
469
like($@, qr/Not yet connect to database/, "$test : Yet Connected");
470

            
471
$dbi = DBIx::Custom->new(data_source => 'dbi:SQLit');
472
eval{$dbi->connect;};
473
ok($@, "$test : connect error");
474

            
475
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
476
$dbi->connect;
477
$dbi->dbh->{AutoCommit} = 0;
remove run_transaction().
yuki-kimoto authored on 2010-01-30
478
eval{$dbi->transaction->run};
packaging one directory
yuki-kimoto authored on 2009-11-16
479
like($@, qr/AutoCommit must be true before transaction start/,
remove run_transaction().
yuki-kimoto authored on 2010-01-30
480
         "$test : transaction auto commit is false");
packaging one directory
yuki-kimoto authored on 2009-11-16
481

            
482
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
483
$sql = 'laksjdf';
484
eval{$dbi->prepare($sql)};
485
like($@, qr/$sql/, "$test : prepare fail");
486

            
487
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
488
$sql = 'laksjdf';
489
eval{$dbi->do($sql, qw/1 2 3/)};
490
like($@, qr/$sql/, "$test : do fail");
491

            
492
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
493
eval{$dbi->create_query("{p }")};
494
ok($@, "$test : create_query invalid SQL template");
495

            
496
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
497
$dbi->do($CREATE_TABLE->{0});
498
$query = $dbi->create_query("select * from table1 where {= key1}");
version 0.0901
yuki-kimoto authored on 2009-12-17
499
eval{$dbi->query($query, {key2 => 1})};
packaging one directory
yuki-kimoto authored on 2009-11-16
500
like($@, qr/Corresponding key is not found in your parameters/, 
501
        "$test : execute corresponding key not found");
502

            
503

            
504
test 'insert';
505
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
506
$dbi->do($CREATE_TABLE->{0});
507
$dbi->insert('table1', {key1 => 1, key2 => 2});
508
$dbi->insert('table1', {key1 => 3, key2 => 4});
version 0.0901
yuki-kimoto authored on 2009-12-17
509
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
510
$rows   = $result->fetch_hash_all;
511
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : basic");
512

            
513
$dbi->do('delete from table1');
514
$dbi->insert('table1', {key1 => 1, key2 => 2}, sub {
515
    my $query = shift;
516
    $query->bind_filter(sub {
517
        my ($value, $key) = @_;
518
        if ($key eq 'key1') {
519
            return $value * 3;
520
        }
521
        return $value;
522
    });
523
});
version 0.0901
yuki-kimoto authored on 2009-12-17
524
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
525
$rows   = $result->fetch_hash_all;
526
is_deeply($rows, [{key1 => 3, key2 => 2}], "$test : edit_query_callback");
527

            
insert, update, delete appnd...
yuki-kimoto authored on 2009-11-16
528
$dbi->insert('table1', {key1 => 1, key2 => 2}, '   ', sub {
529
    my $query = shift;
530
    like($query->sql, qr/insert into table1 \(.+\) values \(\?, \?\)    ;/, 
531
        "$test: append statement");
532
});
packaging one directory
yuki-kimoto authored on 2009-11-16
533

            
534
test 'insert error';
535
eval{$dbi->insert('table1')};
536
like($@, qr/Key-value pairs for insert must be specified to 'insert' second argument/, "$test : insert key-value not specifed");
537

            
insert, update, delete appnd...
yuki-kimoto authored on 2009-11-16
538
eval{$dbi->insert('table1', {key1 => 1, key2 => 2}, '', 'aaa')};
packaging one directory
yuki-kimoto authored on 2009-11-16
539
like($@, qr/Query edit callback must be code reference/, "$test : query edit callback not code ref");
540

            
541

            
542
test 'update';
543
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
544
$dbi->do($CREATE_TABLE->{1});
545
$dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
546
$dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
547
$dbi->update('table1', {key2 => 11}, {key1 => 1});
version 0.0901
yuki-kimoto authored on 2009-12-17
548
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
549
$rows   = $result->fetch_hash_all;
550
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
551
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
552
                  "$test : basic");
553
                  
554
$dbi->do("delete from table1");
555
$dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
556
$dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
557
$dbi->update('table1', {key2 => 12}, {key2 => 2, key3 => 3});
version 0.0901
yuki-kimoto authored on 2009-12-17
558
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
559
$rows   = $result->fetch_hash_all;
560
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
561
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
562
                  "$test : update key same as search key");
563

            
564
$dbi->do("delete from table1");
565
$dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
566
$dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
567
$dbi->update('table1', {key2 => 11}, {key1 => 1}, sub {
568
    my $query = shift;
569
    $query->bind_filter(sub {
570
        my ($value, $key) = @_;
571
        if ($key eq 'key2') {
572
            return $value * 2;
573
        }
574
        return $value;
575
    });
576
});
version 0.0901
yuki-kimoto authored on 2009-12-17
577
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
578
$rows   = $result->fetch_hash_all;
579
is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5},
580
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
581
                  "$test : query edit callback");
582

            
insert, update, delete appnd...
yuki-kimoto authored on 2009-11-16
583
$dbi->update('table1', {key2 => 11}, {key1 => 1}, '   ', sub {
584
    my $query = shift;
585
    is($query->sql, 'update table1 set key2 = ? where key1 = ?    ;',
586
       "$test: append statement");
587
});
588

            
packaging one directory
yuki-kimoto authored on 2009-11-16
589

            
590
test 'update error';
591
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
592
$dbi->do($CREATE_TABLE->{1});
593
eval{$dbi->update('table1')};
594
like($@, qr/Key-value pairs for update must be specified to 'update' second argument/,
595
         "$test : update key-value pairs not specified");
596

            
597
eval{$dbi->update('table1', {key2 => 1})};
598
like($@, qr/Key-value pairs for where clause must be specified to 'update' third argument/,
599
         "$test : where key-value pairs not specified");
600

            
insert, update, delete appnd...
yuki-kimoto authored on 2009-11-16
601
eval{$dbi->update('table1', {key2 => 1}, {key2 => 3}, '', 'aaa')};
packaging one directory
yuki-kimoto authored on 2009-11-16
602
like($@, qr/Query edit callback must be code reference/, 
603
         "$test : query edit callback not code reference");
604

            
605

            
606
test 'update_all';
607
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
608
$dbi->do($CREATE_TABLE->{1});
609
$dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
610
$dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
611
$dbi->update_all('table1', {key2 => 10}, sub {
612
    my $query = shift;
613
    $query->bind_filter(sub {
614
        my ($value, $key) = @_;
615
        return $value * 2;
616
    })
617
});
version 0.0901
yuki-kimoto authored on 2009-12-17
618
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
619
$rows   = $result->fetch_hash_all;
620
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
621
                  {key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
622
                  "$test : query edit callback");
623

            
624

            
625
test 'delete';
626
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
627
$dbi->do($CREATE_TABLE->{0});
628
$dbi->insert('table1', {key1 => 1, key2 => 2});
629
$dbi->insert('table1', {key1 => 3, key2 => 4});
630
$dbi->delete('table1', {key1 => 1});
version 0.0901
yuki-kimoto authored on 2009-12-17
631
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
632
$rows   = $result->fetch_hash_all;
633
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : basic");
634

            
635
$dbi->do("delete from table1;");
636
$dbi->insert('table1', {key1 => 1, key2 => 2});
637
$dbi->insert('table1', {key1 => 3, key2 => 4});
638
$dbi->delete('table1', {key2 => 1}, sub {
639
    my $query = shift;
640
    $query->bind_filter(sub {
641
        my ($value, $key) = @_;
642
        return $value * 2;
643
    });
644
});
version 0.0901
yuki-kimoto authored on 2009-12-17
645
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
646
$rows   = $result->fetch_hash_all;
647
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : query edit callback");
648

            
insert, update, delete appnd...
yuki-kimoto authored on 2009-11-16
649
$dbi->delete('table1', {key1 => 1}, '   ', sub {
650
    my $query = shift;
651
    is($query->sql, 'delete from table1 where key1 = ?    ;',
652
       "$test: append statement");
653
});
654

            
655

            
packaging one directory
yuki-kimoto authored on 2009-11-16
656
$dbi->delete_all('table1');
657
$dbi->insert('table1', {key1 => 1, key2 => 2});
658
$dbi->insert('table1', {key1 => 3, key2 => 4});
659
$dbi->delete('table1', {key1 => 1, key2 => 2});
660
$rows = $dbi->select('table1')->fetch_hash_all;
661
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : delete multi key");
662

            
663

            
664
test 'delete error';
665
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
666
$dbi->do($CREATE_TABLE->{0});
667
eval{$dbi->delete('table1')};
668
like($@, qr/Key-value pairs for where clause must be specified to 'delete' second argument/,
669
         "$test : where key-value pairs not specified");
670

            
insert, update, delete appnd...
yuki-kimoto authored on 2009-11-16
671
eval{$dbi->delete('table1', {key1 => 1}, '', 'aaa')};
packaging one directory
yuki-kimoto authored on 2009-11-16
672
like($@, qr/Query edit callback must be code reference/, 
673
         "$test : query edit callback not code ref");
674

            
675

            
676
test 'delete_all';
677
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
678
$dbi->do($CREATE_TABLE->{0});
679
$dbi->insert('table1', {key1 => 1, key2 => 2});
680
$dbi->insert('table1', {key1 => 3, key2 => 4});
681
$dbi->delete_all('table1');
version 0.0901
yuki-kimoto authored on 2009-12-17
682
$result = $dbi->query($SELECT_TMPL->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
683
$rows   = $result->fetch_hash_all;
684
is_deeply($rows, [], "$test : basic");
685

            
686

            
687
test 'select';
688
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
689
$dbi->do($CREATE_TABLE->{0});
690
$dbi->insert('table1', {key1 => 1, key2 => 2});
691
$dbi->insert('table1', {key1 => 3, key2 => 4});
692
$rows = $dbi->select('table1')->fetch_hash_all;
693
is_deeply($rows, [{key1 => 1, key2 => 2},
694
                  {key1 => 3, key2 => 4}], "$test : table");
695

            
696
$rows = $dbi->select('table1', ['key1'])->fetch_hash_all;
697
is_deeply($rows, [{key1 => 1}, {key1 => 3}], "$test : table and columns and where key");
698

            
699
$rows = $dbi->select('table1', {key1 => 1})->fetch_hash_all;
700
is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : table and columns and where key");
701

            
702
$rows = $dbi->select('table1', ['key1'], {key1 => 3})->fetch_hash_all;
703
is_deeply($rows, [{key1 => 3}], "$test : table and columns and where key");
704

            
705
$rows = $dbi->select('table1', "order by key1 desc limit 1")->fetch_hash_all;
706
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : append statement");
707

            
708
$rows = $dbi->select('table1', {key1 => 2}, sub {
709
    my $query = shift;
710
    $query->bind_filter(sub {
711
        my ($value, $key) = @_;
712
        if ($key eq 'key1') {
713
            return $value - 1;
714
        }
715
        return $value;
716
    });
717
})->fetch_hash_all;
718
is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : query edit call back");
719

            
720
$dbi->do($CREATE_TABLE->{2});
721
$dbi->insert('table2', {key1 => 1, key3 => 5});
722
$rows = $dbi->select([qw/table1 table2/],
723
                     ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
724
                     {'table1.key2' => 2},
725
                     "where table1.key1 = table2.key1")->fetch_hash_all;
726
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "$test : join");
727

            
728
test 'Cache';
729
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
730
DBIx::Custom->query_cache_max(2);
731
$dbi->do($CREATE_TABLE->{0});
cleanup
yuki-kimoto authored on 2009-12-22
732
delete $DBIx::Custom::CLASS_ATTRS->{_query_caches};
733
delete $DBIx::Custom::CLASS_ATTRS->{_query_cache_keys};
packaging one directory
yuki-kimoto authored on 2009-11-16
734
$tmpls[0] = "insert into table1 {insert key1 key2}";
735
$queries[0] = $dbi->create_query($tmpls[0]);
736
is(DBIx::Custom->_query_caches->{$tmpls[0]}{sql}, $queries[0]->sql, "$test : sql first");
737
is(DBIx::Custom->_query_caches->{$tmpls[0]}{key_infos}, $queries[0]->key_infos, "$test : key_infos first");
738
is_deeply(DBIx::Custom->_query_cache_keys, [@tmpls], "$test : cache key first");
739

            
740
$tmpls[1] = "select * from table1";
741
$queries[1] = $dbi->create_query($tmpls[1]);
742
is(DBIx::Custom->_query_caches->{$tmpls[0]}{sql}, $queries[0]->sql, "$test : sql first");
743
is(DBIx::Custom->_query_caches->{$tmpls[0]}{key_infos}, $queries[0]->key_infos, "$test : key_infos first");
744
is(DBIx::Custom->_query_caches->{$tmpls[1]}{sql}, $queries[1]->sql, "$test : sql second");
745
is(DBIx::Custom->_query_caches->{$tmpls[1]}{key_infos}, $queries[1]->key_infos, "$test : key_infos second");
746
is_deeply(DBIx::Custom->_query_cache_keys, [@tmpls], "$test : cache key second");
747

            
748
$tmpls[2] = "select key1, key2 from table1";
749
$queries[2] = $dbi->create_query($tmpls[2]);
750
ok(!exists DBIx::Custom->_query_caches->{$tmpls[0]}, "$test : cache overflow deleted key");
751
is(DBIx::Custom->_query_caches->{$tmpls[1]}{sql}, $queries[1]->sql, "$test : sql cache overflow deleted key");
752
is(DBIx::Custom->_query_caches->{$tmpls[1]}{key_infos}, $queries[1]->key_infos, "$test : key_infos cache overflow deleted key");
753
is(DBIx::Custom->_query_caches->{$tmpls[2]}{sql}, $queries[2]->sql, "$test : sql cache overflow deleted key");
754
is(DBIx::Custom->_query_caches->{$tmpls[2]}{key_infos}, $queries[2]->key_infos, "$test : key_infos cache overflow deleted key");
755
is_deeply(DBIx::Custom->_query_cache_keys, [@tmpls[1, 2]], "$test : cache key third");
756

            
757
$queries[1] = $dbi->create_query($tmpls[1]);
758
ok(!exists DBIx::Custom->_query_caches->{$tmpls[0]}, "$test : cache overflow deleted key");
759
is(DBIx::Custom->_query_caches->{$tmpls[1]}{sql}, $queries[1]->sql, "$test : sql cache overflow deleted key");
fix timeformat tests
yuki-kimoto authored on 2009-11-23
760
is_deeply(DBIx::Custom->_query_caches->{$tmpls[1]}{key_infos}, $queries[1]->key_infos, "$test : key_infos cache overflow deleted key");
packaging one directory
yuki-kimoto authored on 2009-11-16
761
is(DBIx::Custom->_query_caches->{$tmpls[2]}{sql}, $queries[2]->sql, "$test : sql cache overflow deleted key");
fix timeformat tests
yuki-kimoto authored on 2009-11-23
762
is_deeply(DBIx::Custom->_query_caches->{$tmpls[2]}{key_infos}, $queries[2]->key_infos, "$test : key_infos cache overflow deleted key");
packaging one directory
yuki-kimoto authored on 2009-11-16
763
is_deeply(DBIx::Custom->_query_cache_keys, [@tmpls[1, 2]], "$test : cache key third");
764

            
fix timeformat tests
yuki-kimoto authored on 2009-11-23
765
$query = $dbi->create_query($tmpls[0]);
766
$query->bind_filter('aaa');
767
$query = $dbi->create_query($tmpls[0]);
768
ok(!$query->bind_filter, "$test : only cached sql and key_infos");
769
$query->bind_filter('bbb');
770
$query = $dbi->create_query($tmpls[0]);
771
ok(!$query->bind_filter, "$test : only cached sql and key_infos");
772

            
773