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

            
100
eval{$dbi->insert('table1', {key1 => 1, key2 => 2})};
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

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

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

            
466

            
467
test 'Error case';
468
$dbi = DBIx::Custom->new;
469
eval{$dbi->run_transaction};
470
like($@, qr/Not yet connect to database/, "$test : Yet Connected");
471

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

            
476
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
477
$dbi->connect;
478
$dbi->dbh->{AutoCommit} = 0;
479
eval{$dbi->run_transaction()};
480
like($@, qr/AutoCommit must be true before transaction start/,
481
         "$test : run_transaction auto commit is false");
482

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

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

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

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

            
504

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

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

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

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

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

            
542

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

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

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

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

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

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

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

            
606

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

            
625

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

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

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

            
656

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

            
664

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

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

            
676

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

            
687

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

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

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

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

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

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

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

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

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

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

            
758
$queries[1] = $dbi->create_query($tmpls[1]);
759
ok(!exists DBIx::Custom->_query_caches->{$tmpls[0]}, "$test : cache overflow deleted key");
760
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
761
is_deeply(DBIx::Custom->_query_caches->{$tmpls[1]}{key_infos}, $queries[1]->key_infos, "$test : key_infos cache overflow deleted key");
762
isnt(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
763
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
764
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
765
is_deeply(DBIx::Custom->_query_cache_keys, [@tmpls[1, 2]], "$test : cache key third");
766

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

            
775