DBIx-Custom / t / common.t /
Newer Older
3859 lines | 126.839kb
added common test executing ...
Yuki Kimoto authored on 2011-08-07
1
use Test::More;
2
use strict;
3
use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
4
use Encode qw/encode_utf8/;
cleanup test
Yuki Kimoto authored on 2011-08-10
5
use FindBin;
cleanup
Yuki Kimoto authored on 2011-08-13
6
use Scalar::Util 'isweak';
cleanup test
Yuki Kimoto authored on 2011-08-10
7

            
added common test executing ...
Yuki Kimoto authored on 2011-08-07
8
my $dbi;
9

            
10
plan skip_all => $ENV{DBIX_CUSTOM_SKIP_MESSAGE} || 'common.t is always skipped'
11
  unless $ENV{DBIX_CUSTOM_TEST_RUN}
12
    && eval { $dbi = DBIx::Custom->connect; 1 };
13

            
14
plan 'no_plan';
15

            
finished oracle test
Yuki Kimoto authored on 2011-08-15
16
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
17
sub test { print "# $_[0]\n" }
18

            
cleanup test
Yuki Kimoto authored on 2011-08-15
19
# Constant
20
my $table1 = $dbi->table1;
21
my $table2 = $dbi->table2;
22
my $table2_alias = $dbi->table2_alias;
23
my $table3 = $dbi->table3;
24
my $key1 = $dbi->key1;
25
my $key2 = $dbi->key2;
26
my $key3 = $dbi->key3;
27
my $key4 = $dbi->key4;
28
my $key5 = $dbi->key5;
29
my $key6 = $dbi->key6;
30
my $key7 = $dbi->key7;
31
my $key8 = $dbi->key8;
32
my $key9 = $dbi->key9;
33
my $key10 = $dbi->key10;
34
my $create_table1 = $dbi->create_table1;
35
my $create_table1_2 = $dbi->create_table1_2;
36
my $create_table1_type = $dbi->create_table1_type;
37
my $create_table1_highperformance = $dbi->create_table1_highperformance;
38
my $create_table2 = $dbi->create_table2;
39
my $create_table2_2 = $dbi->create_table2_2;
40
my $create_table3 = $dbi->create_table3;
41
my $create_table_reserved = $dbi->create_table_reserved;
42
my $q = substr($dbi->quote, 0, 1);
43
my $p = substr($dbi->quote, 1, 1) || $q;
44
my $date_typename = $dbi->date_typename;
45
my $datetime_typename = $dbi->datetime_typename;
46
my $date_datatype = $dbi->date_datatype;
47
my $datetime_datatype = $dbi->datetime_datatype;
48

            
49
# Variables
50
my $builder;
51
my $datas;
52
my $sth;
53
my $source;
54
my @sources;
55
my $select_source;
56
my $insert_source;
57
my $update_source;
58
my $param;
59
my $params;
60
my $sql;
61
my $result;
62
my $row;
63
my @rows;
64
my $rows;
65
my $query;
66
my @queries;
67
my $select_query;
68
my $insert_query;
69
my $update_query;
70
my $ret_val;
71
my $infos;
72
my $model;
73
my $model2;
74
my $where;
75
my $update_param;
76
my $insert_param;
77
my $join;
78
my $binary;
79

            
test cleanup
Yuki Kimoto authored on 2011-08-15
80
require MyDBI1;
test cleanup
Yuki Kimoto authored on 2011-08-10
81
{
82
    package MyDBI4;
83

            
84
    use strict;
85
    use warnings;
86

            
87
    use base 'DBIx::Custom';
88

            
89
    sub connect {
90
        my $self = shift->SUPER::connect(@_);
91
        
92
        $self->include_model(
93
            MyModel2 => [
cleanup test
Yuki Kimoto authored on 2011-08-15
94
                $table1,
95
                {class => $table2, name => $table2}
test cleanup
Yuki Kimoto authored on 2011-08-10
96
            ]
97
        );
98
    }
99

            
100
    package MyModel2::Base1;
101

            
102
    use strict;
103
    use warnings;
104

            
105
    use base 'DBIx::Custom::Model';
106

            
test cleanup
Yuki Kimoto authored on 2011-08-10
107
    package MyModel2::table1;
test cleanup
Yuki Kimoto authored on 2011-08-10
108

            
109
    use strict;
110
    use warnings;
111

            
112
    use base 'MyModel2::Base1';
113

            
114
    sub insert {
115
        my ($self, $param) = @_;
116
        
117
        return $self->SUPER::insert(param => $param);
118
    }
119

            
120
    sub list { shift->select; }
121

            
test cleanup
Yuki Kimoto authored on 2011-08-10
122
    package MyModel2::table2;
test cleanup
Yuki Kimoto authored on 2011-08-10
123

            
124
    use strict;
125
    use warnings;
126

            
127
    use base 'MyModel2::Base1';
128

            
129
    sub insert {
130
        my ($self, $param) = @_;
131
        
132
        return $self->SUPER::insert(param => $param);
133
    }
134

            
135
    sub list { shift->select; }
test cleanup
Yuki Kimoto authored on 2011-08-15
136

            
137
    package MyModel2::TABLE1;
138

            
139
    use strict;
140
    use warnings;
141

            
142
    use base 'MyModel2::Base1';
143

            
144
    sub insert {
145
        my ($self, $param) = @_;
146
        
147
        return $self->SUPER::insert(param => $param);
148
    }
149

            
150
    sub list { shift->select; }
151

            
152
    package MyModel2::TABLE2;
153

            
154
    use strict;
155
    use warnings;
156

            
157
    use base 'MyModel2::Base1';
158

            
159
    sub insert {
160
        my ($self, $param) = @_;
161
        
162
        return $self->SUPER::insert(param => $param);
163
    }
164

            
165
    sub list { shift->select; }
test cleanup
Yuki Kimoto authored on 2011-08-10
166
}
167
{
168
     package MyDBI5;
169

            
170
    use strict;
171
    use warnings;
172

            
173
    use base 'DBIx::Custom';
174

            
175
    sub connect {
176
        my $self = shift->SUPER::connect(@_);
177
        
178
        $self->include_model('MyModel4');
179
    }
180
}
181
{
182
    package MyDBI6;
183
    
184
    use base 'DBIx::Custom';
185
    
186
    sub connect {
187
        my $self = shift->SUPER::connect(@_);
188
        
189
        $self->include_model('MyModel5');
190
        
191
        return $self;
192
    }
193
}
194
{
195
    package MyDBI7;
196
    
197
    use base 'DBIx::Custom';
198
    
199
    sub connect {
200
        my $self = shift->SUPER::connect(@_);
201
        
202
        $self->include_model('MyModel6');
203
        
204
        
205
        return $self;
206
    }
207
}
208
{
209
    package MyDBI8;
210
    
211
    use base 'DBIx::Custom';
212
    
213
    sub connect {
214
        my $self = shift->SUPER::connect(@_);
215
        
216
        $self->include_model('MyModel7');
217
        
218
        return $self;
219
    }
220
}
221

            
222
{
223
    package MyDBI9;
224
    
225
    use base 'DBIx::Custom';
226
    
227
    sub connect {
228
        my $self = shift->SUPER::connect(@_);
229
        
cleanup test
Yuki Kimoto authored on 2011-08-10
230
        $self->include_model('MyModel8');
test cleanup
Yuki Kimoto authored on 2011-08-10
231
        
232
        return $self;
233
    }
234
}
235

            
finished oracle test
Yuki Kimoto authored on 2011-08-15
236
test 'join';
237
$dbi = DBIx::Custom->connect;
238
eval { $dbi->execute("drop table $table1") };
239
$dbi->execute($create_table1);
240
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
241
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
242
eval { $dbi->execute("drop table $table2") };
243
$dbi->execute($create_table2);
244
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
245
eval { $dbi->execute("drop table $table3") };
246
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
247
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
248
$rows = $dbi->select(
249
    table => $table1,
250
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
251
    where   => {"$table1.$key2" => 2},
252
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
253
)->all;
254
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
255

            
256
$rows = $dbi->select(
257
    table => $table1,
258
    where   => {$key1 => 1},
259
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
260
)->all;
261
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
262

            
263
eval {
264
    $rows = $dbi->select(
265
        table => $table1,
266
        column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
267
        where   => {"$table1.$key2" => 2},
268
        join  => {"$table1.$key1" => "$table2.$key1"}
269
    );
270
};
271
like ($@, qr/array/);
272

            
273
$rows = $dbi->select(
274
    table => $table1,
275
    where   => {$key1 => 1},
276
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
277
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
278
)->all;
279
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
280

            
281
$rows = $dbi->select(
282
    column => "$table3.$key4 as ${table3}__$key4",
283
    table => $table1,
284
    where   => {"$table1.$key1" => 1},
285
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
286
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
287
)->all;
288
is_deeply($rows, [{"${table3}__$key4" => 4}]);
289

            
290
$rows = $dbi->select(
291
    column => "$table1.$key1 as ${table1}__$key1",
292
    table => $table1,
293
    where   => {"$table3.$key4" => 4},
294
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
295
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
296
)->all;
297
is_deeply($rows, [{"${table1}__$key1" => 1}]);
298

            
299
$dbi = DBIx::Custom->connect;
300
eval { $dbi->execute("drop table $table1") };
301
$dbi->execute($create_table1);
302
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
303
eval { $dbi->execute("drop table $table2") };
304
$dbi->execute($create_table2);
305
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
306
$rows = $dbi->select(
307
    table => $table1,
308
    column => "${q}$table1$p.${q}$key1$p as ${q}${table1}_$key1$p, ${q}$table2$p.${q}$key1$p as ${q}${table2}_$key1$p, ${q}$key2$p, ${q}$key3$p",
309
    where   => {"$table1.$key2" => 2},
310
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
311
)->all;
312
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
313
          'quote');
314

            
315

            
316
$dbi = DBIx::Custom->connect;
317
eval { $dbi->execute("drop table $table1") };
318
$dbi->execute($create_table1);
319
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
320
$sql = <<"EOS";
321
left outer join (
322
  select * from $table1 t1
323
  where t1.$key2 = (
324
    select max(t2.$key2) from $table1 t2
325
    where t1.$key1 = t2.$key1
326
  )
327
) $table3 on $table1.$key1 = $table3.$key1
328
EOS
329
$join = [$sql];
330
$rows = $dbi->select(
331
    table => $table1,
332
    column => "$table3.$key1 as ${table3}__$key1",
333
    join  => $join
334
)->all;
335
$DB::single = 1;
336
is_deeply($rows, [{"${table3}__$key1" => 1}]);
337

            
338
$dbi = DBIx::Custom->connect;
339
eval { $dbi->execute("drop table $table1") };
340
eval { $dbi->execute("drop table $table2") };
341
$dbi->execute($create_table1);
342
$dbi->execute($create_table2);
343
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
344
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
345
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
346
$result = $dbi->select(
347
    table => $table1,
348
    join => [
349
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
350
    ]
351
);
352
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
353
$result = $dbi->select(
354
    table => $table1,
355
    column => [{$table2 => [$key3]}],
356
    join => [
357
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
358
    ]
359
);
360
is_deeply($result->all, [{"$table2.$key3" => 4}]);
361
$result = $dbi->select(
362
    table => $table1,
363
    column => [{$table2 => [$key3]}],
364
    join => [
365
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
366
    ]
367
);
368
is_deeply($result->all, [{"$table2.$key3" => 4}]);
369

            
370
$dbi = DBIx::Custom->connect;
371
eval { $dbi->execute("drop table $table1") };
372
eval { $dbi->execute("drop table $table2") };
373
$dbi->execute($create_table1);
374
$dbi->execute($create_table2);
375
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
376
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
377
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
378
$result = $dbi->select(
379
    table => $table1,
380
    column => [{$table2 => [$key3]}],
381
    join => [
382
        {
383
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
384
            table => [$table1, $table2]
385
        }
386
    ]
387
);
388
is_deeply($result->all, [{"$table2.$key3" => 4}]);
389

            
390
test 'columns';
391
$DB::single = 1;
392
$dbi = MyDBI1->connect;
393
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-08
394

            
cleanup test
Yuki Kimoto authored on 2011-08-15
395
# Create table
test cleanup
Yuki Kimoto authored on 2011-08-10
396
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
397
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
398
$dbi->execute($create_table1);
399
$model = $dbi->create_model(table => $table1);
400
$model->insert({$key1 => 1, $key2 => 2});
401
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-08-15
402

            
cleanup test
Yuki Kimoto authored on 2011-08-15
403
test 'DBIx::Custom::Result test';
404
$dbi->delete_all(table => $table1);
405
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
406
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
407
$source = "select $key1, $key2 from $table1";
408
$query = $dbi->create_query($source);
409
$result = $dbi->execute($query);
cleanup
Yuki Kimoto authored on 2011-08-15
410

            
cleanup test
Yuki Kimoto authored on 2011-08-15
411
@rows = ();
412
while (my $row = $result->fetch) {
413
    push @rows, [@$row];
414
}
415
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
cleanup
Yuki Kimoto authored on 2011-08-15
416

            
cleanup test
Yuki Kimoto authored on 2011-08-15
417
$result = $dbi->execute($query);
418
@rows = ();
419
while (my $row = $result->fetch_hash) {
420
    push @rows, {%$row};
421
}
422
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
423

            
cleanup test
Yuki Kimoto authored on 2011-08-15
424
$result = $dbi->execute($query);
425
$rows = $result->fetch_all;
426
is_deeply($rows, [[1, 2], [3, 4]], "fetch_all");
test cleanup
Yuki Kimoto authored on 2011-08-10
427

            
cleanup test
Yuki Kimoto authored on 2011-08-15
428
$result = $dbi->execute($query);
429
$rows = $result->fetch_hash_all;
430
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "all");
test cleanup
Yuki Kimoto authored on 2011-08-10
431

            
cleanup test
Yuki Kimoto authored on 2011-08-15
432
test 'Insert query return value';
433
$source = "insert into $table1 {insert_param $key1 $key2}";
434
$query = $dbi->execute($source, {}, query => 1);
435
$ret_val = $dbi->execute($query, param => {$key1 => 1, $key2 => 2});
436
ok($ret_val);
test cleanup
Yuki Kimoto authored on 2011-08-10
437

            
cleanup test
Yuki Kimoto authored on 2011-08-15
438
test 'Direct query';
439
$dbi->delete_all(table => $table1);
440
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
441
$dbi->execute($insert_source, param => {$key1 => 1, $key2 => 2});
442
$result = $dbi->execute("select * from $table1");
443
$rows = $result->all;
444
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
445

            
446
test 'Filter basic';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
447
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-08
448
$dbi->register_filter(twice       => sub { $_[0] * 2}, 
449
                    three_times => sub { $_[0] * 3});
450

            
cleanup test
Yuki Kimoto authored on 2011-08-15
451
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
452
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
453
$insert_query->filter({$key1 => 'twice'});
454
$dbi->execute($insert_query, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
455
$result = $dbi->execute("select * from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
456
$rows = $result->filter({$key2 => 'three_times'})->all;
457
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
458

            
459
test 'Filter in';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
460
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
461
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
462
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
463
$dbi->execute($insert_query, param => {$key1 => 2, $key2 => 4});
464
$select_source = "select * from $table1 where {in $table1.$key1 2} and {in $table1.$key2 2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
465
$select_query = $dbi->execute($select_source,{}, query => 1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
466
$select_query->filter({"$table1.$key1" => 'twice'});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
467
$result = $dbi->execute($select_query, param => {"$table1.$key1" => [1,5], "$table1.$key2" => [2,4]});
cleanup test
Yuki Kimoto authored on 2011-08-08
468
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
469
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
470

            
cleanup test
Yuki Kimoto authored on 2011-08-08
471
test 'DBIx::Custom::SQLTemplate basic tag';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
472
$dbi->execute("drop table $table1");
cleanup test
Yuki Kimoto authored on 2011-08-08
473
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
474
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
475
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
476

            
cleanup test
Yuki Kimoto authored on 2011-08-15
477
$source = "select * from $table1 where $key1 = :$key1 and {<> $key2} and {< $key3} and {> $key4} and {>= $key5}";
cleanup test
Yuki Kimoto authored on 2011-08-08
478
$query = $dbi->execute($source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
479
$result = $dbi->execute($query, param => {$key1 => 1, $key2 => 3, $key3 => 4, $key4 => 3, $key5 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-08
480
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
481
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}], "basic tag1");
cleanup test
Yuki Kimoto authored on 2011-08-08
482

            
cleanup test
Yuki Kimoto authored on 2011-08-15
483
$source = "select * from $table1 where $key1 = :$key1 and {<> $key2} and {< $key3} and {> $key4} and {>= $key5}";
cleanup test
Yuki Kimoto authored on 2011-08-08
484
$query = $dbi->execute($source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
485
$result = $dbi->execute($query, {$key1 => 1, $key2 => 3, $key3 => 4, $key4 => 3, $key5 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-08
486
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
487
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}], "basic tag1");
cleanup test
Yuki Kimoto authored on 2011-08-08
488

            
cleanup test
Yuki Kimoto authored on 2011-08-15
489
$source = "select * from $table1 where {<= $key1} and {like $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
490
$query = $dbi->execute($source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
491
$result = $dbi->execute($query, param => {$key1 => 1, $key2 => '%2%'});
cleanup test
Yuki Kimoto authored on 2011-08-08
492
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
493
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}], "basic tag2");
cleanup test
Yuki Kimoto authored on 2011-08-08
494

            
495
test 'DIB::Custom::SQLTemplate in tag';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
496
$dbi->execute("drop table $table1");
cleanup test
Yuki Kimoto authored on 2011-08-08
497
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
498
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
499
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
500

            
cleanup test
Yuki Kimoto authored on 2011-08-15
501
$source = "select * from $table1 where {in $key1 2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
502
$query = $dbi->execute($source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
503
$result = $dbi->execute($query, param => {$key1 => [9, 1]});
cleanup test
Yuki Kimoto authored on 2011-08-08
504
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
505
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-08
506

            
507
test 'DBIx::Custom::SQLTemplate insert tag';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
508
$dbi->delete_all(table => $table1);
509
$insert_source = "insert into $table1 {insert_param $key1 $key2 $key3 $key4 $key5}";
510
$dbi->execute($insert_source, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-08
511

            
cleanup test
Yuki Kimoto authored on 2011-08-15
512
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-08
513
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
514
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-08
515

            
516
test 'DBIx::Custom::SQLTemplate update tag';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
517
$dbi->delete_all(table => $table1);
518
$insert_source = "insert into $table1 {insert_param $key1 $key2 $key3 $key4 $key5}";
519
$dbi->execute($insert_source, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
520
$dbi->execute($insert_source, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
521

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
522
$update_source = "update $table1 {update_param $key1 $key2 $key3 $key4} where {= $key5}";
523
$dbi->execute($update_source, param => {$key1 => 1, $key2 => 1, $key3 => 1, $key4 => 1, $key5 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-08
524

            
cleanup test
Yuki Kimoto authored on 2011-08-15
525
$result = $dbi->execute("select * from $table1 order by $key1");
cleanup test
Yuki Kimoto authored on 2011-08-08
526
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
527
is_deeply($rows, [{$key1 => 1, $key2 => 1, $key3 => 1, $key4 => 1, $key5 => 5},
528
                  {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-08
529

            
cleanup test
Yuki Kimoto authored on 2011-08-08
530
test 'Named placeholder';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
531
$dbi->execute("drop table $table1");
cleanup test
Yuki Kimoto authored on 2011-08-08
532
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
533
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
534
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
535

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
536
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
537
$result = $dbi->execute($source, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-08
538
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
539
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
540

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
541
$source = "select * from $table1 where $key1 = \n:$key1\n and $key2 = :$key2";
542
$result = $dbi->execute($source, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-08
543
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
544
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
545

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
546
$source = "select * from $table1 where $key1 = :$key1 or $key1 = :$key1";
547
$result = $dbi->execute($source, param => {$key1 => [1, 2]});
cleanup test
Yuki Kimoto authored on 2011-08-08
548
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
549
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
550

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
551
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
552
$result = $dbi->execute(
553
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
554
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
555
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
cleanup test
Yuki Kimoto authored on 2011-08-08
556
);
557
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
558
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
559

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
560
$dbi->execute("drop table $table1");
cleanup test
Yuki Kimoto authored on 2011-08-08
561
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
562
$dbi->insert(table => $table1, param => {$key1 => '2011-10-14 12:19:18', $key2 => 2});
563
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
564
$result = $dbi->execute(
565
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
566
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
567
);
568

            
569
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
570
like($rows->[0]->{$key1}, qr/2011-10-14 12:19:18/);
571
is($rows->[0]->{$key2}, 2);
cleanup test
Yuki Kimoto authored on 2011-08-08
572

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
573
$dbi->delete_all(table => $table1);
574
$dbi->insert(table => $table1, param => {$key1 => 'a:b c:d', $key2 => 2});
575
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
576
$result = $dbi->execute(
577
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
578
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
579
);
580
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
581
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
582

            
test cleanup
Yuki Kimoto authored on 2011-08-10
583
test 'Error case';
584
eval {DBIx::Custom->connect(dsn => 'dbi:SQLit')};
585
ok($@, "connect error");
586

            
587
eval{$dbi->execute("{p }", {}, query => 1)};
588
ok($@, "create_query invalid SQL template");
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
589

            
cleanup test
Yuki Kimoto authored on 2011-08-10
590
test 'insert';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
591
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
592
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
593
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
594
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
595
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
596
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
597
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
598

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
599
$dbi->execute("delete from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
600
$dbi->register_filter(
601
    twice       => sub { $_[0] * 2 },
602
    three_times => sub { $_[0] * 3 }
603
);
604
$dbi->default_bind_filter('twice');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
605
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => 'three_times'});
cleanup test
Yuki Kimoto authored on 2011-08-15
606
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
607
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
608
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-10
609
$dbi->default_bind_filter(undef);
610

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
611
$dbi->execute("drop table $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
612
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
613
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, append => '   ');
614
$rows = $dbi->select(table => $table1)->all;
615
is_deeply($rows, [{$key1 => 1, $key2 => 2}], 'insert append');
cleanup test
Yuki Kimoto authored on 2011-08-10
616

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
617
eval{$dbi->insert(table => $table1, noexist => 1)};
cleanup test
Yuki Kimoto authored on 2011-08-10
618
like($@, qr/noexist/, "invalid");
619

            
620
eval{$dbi->insert(table => 'table', param => {';' => 1})};
621
like($@, qr/safety/);
622

            
cleanup test
Yuki Kimoto authored on 2011-08-10
623
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
624
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
625
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
626
$dbi->insert(table => 'table', param => {select => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
627
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
628
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
629
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
cleanup test
Yuki Kimoto authored on 2011-08-10
630

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
631
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
632
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
633
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
634
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
635
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
636
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
637
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
638

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
639
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
640
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
641
$dbi->insert(table => $table1, param => {$key1 => \"'1'", $key2 => 2});
642
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
643
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
644
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
645
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
646

            
test cleanup
Yuki Kimoto authored on 2011-08-10
647
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
648
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
649
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
650
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
651
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
652
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
653
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
654
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
655
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
656
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
657
                  "basic");
658
                  
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
659
$dbi->execute("delete from $table1");
660
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
661
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
662
$dbi->update(table => $table1, param => {$key2 => 12}, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
663
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
664
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
665
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
666
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
667
                  "update key same as search key");
668

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
669
$dbi->update(table => $table1, param => {$key2 => [12]}, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
670
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
671
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
672
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
673
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
674
                  "update key same as search key : param is array ref");
675

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
676
$dbi->execute("delete from $table1");
677
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
678
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
679
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
680
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1},
681
              filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
682
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
683
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
684
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
685
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
686
                  "filter");
687

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
688
$result = $dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1}, append => '   ');
test cleanup
Yuki Kimoto authored on 2011-08-10
689

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
690
eval{$dbi->update(table => $table1, where => {$key1 => 1}, noexist => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
691
like($@, qr/noexist/, "invalid");
692

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
693
eval{$dbi->update(table => $table1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
694
like($@, qr/where/, "not contain where");
695

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
696
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
697
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
698
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
699
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
700
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
701
$where->param({$key1 => 1, $key2 => 2});
702
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
703
$result = $dbi->select(table => $table1);
704
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
705

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
706
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
707
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
708
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
709
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
710
    table => $table1,
711
    param => {$key1 => 3},
test cleanup
Yuki Kimoto authored on 2011-08-10
712
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
713
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
714
        {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
715
    ]
716
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
717
$result = $dbi->select(table => $table1);
718
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
719

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
720
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
721
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
722
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
723
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
724
$where->clause(['and', "$key2 = :$key2"]);
725
$where->param({$key2 => 2});
726
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
727
$result = $dbi->select(table => $table1);
728
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
729

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
730
eval{$dbi->update(table => $table1, param => {';' => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
731
like($@, qr/safety/);
732

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
733
eval{$dbi->update(table => $table1, param => {$key1 => 1}, where => {';' => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
734
like($@, qr/safety/);
735

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
736
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
737
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
738
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
739
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
740
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
741
$dbi->insert(table => 'table', param => {select => 1});
742
$dbi->update(table => 'table', where => {select => 1}, param => {update => 2});
743
$result = $dbi->execute("select * from ${q}table$p");
744
$rows   = $result->all;
745
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
746

            
747
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
748
like($@, qr/safety/);
749

            
750
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
751
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
752
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
753
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
754
$dbi->insert(table => 'table', param => {select => 1});
755
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
756
$result = $dbi->execute("select * from ${q}table$p");
757
$rows   = $result->all;
758
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
759

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
760
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
761
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
762
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
763
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
764
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
765
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
766
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
767
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
768
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
769
                  "basic");
770

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
771
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
772
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
773
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
774
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
775
$dbi->update(table => $table1, param => {$key2 => \"'11'"}, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
776
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
777
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
778
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
779
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
780
                  "basic");
781

            
782
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
783
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
784
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
785
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
786
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
787
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
788
$dbi->update_all(table => $table1, param => {$key2 => 10}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
789
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
790
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
791
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
792
                  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
793
                  "filter");
794

            
795

            
796
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
797
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
798
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
799
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
800
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
801
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
802
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
803
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
804
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
805

            
cleanup test
Yuki Kimoto authored on 2011-08-15
806
$dbi->execute("delete from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
807
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
808
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
809
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
810
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
811
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
812
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
813
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
814

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
815
$dbi->delete(table => $table1, where => {$key1 => 1}, append => '   ');
test cleanup
Yuki Kimoto authored on 2011-08-10
816

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
817
$dbi->delete_all(table => $table1);
818
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
819
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
820
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
821
$rows = $dbi->select(table => $table1)->all;
822
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
823

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
824
eval{$dbi->delete(table => $table1, where => {$key1 => 1}, noexist => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
825
like($@, qr/noexist/, "invalid");
826

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
827
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
828
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
829
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
830
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
831
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
832
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
833
$where->param({ke1 => 1, $key2 => 2});
834
$dbi->delete(table => $table1, where => $where);
835
$result = $dbi->select(table => $table1);
836
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
837

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
838
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
839
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
840
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
841
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
842
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
843
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
844
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
845
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
846
        {ke1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
847
    ]
848
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
849
$result = $dbi->select(table => $table1);
850
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
851

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
852
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
853
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
854
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
855
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
856
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
857
$rows   = $result->all;
858
is_deeply($rows, [], "basic");
859

            
860
test 'delete error';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
861
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
862
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
863
eval{$dbi->delete(table => $table1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
864
like($@, qr/"where" must be specified/,
865
         "where key-value pairs not specified");
866

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
867
eval{$dbi->delete(table => $table1, where => {';' => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
868
like($@, qr/safety/);
869

            
test cleanup
Yuki Kimoto authored on 2011-08-10
870
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
871
$dbi = DBIx::Custom->connect;
872
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
873
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
874
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
875
$dbi->insert(table => 'table', param => {select => 1});
876
$dbi->delete(table => 'table', where => {select => 1});
877
$result = $dbi->execute("select * from ${q}table$p");
878
$rows   = $result->all;
879
is_deeply($rows, [], "reserved word");
880

            
881
test 'delete_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
882
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
883
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
884
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
885
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
886
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
887
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
888
$rows   = $result->all;
889
is_deeply($rows, [], "basic");
890

            
891

            
892
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
893
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
894
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
895
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
896
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
897
$rows = $dbi->select(table => $table1)->all;
898
is_deeply($rows, [{$key1 => 1, $key2 => 2},
899
                  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
900

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
901
$rows = $dbi->select(table => $table1, column => [$key1])->all;
902
is_deeply($rows, [{$key1 => 1}, {$key1 => 3}], "table and columns and where key");
test cleanup
Yuki Kimoto authored on 2011-08-10
903

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
904
$rows = $dbi->select(table => $table1, where => {$key1 => 1})->all;
905
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table and columns and where key");
test cleanup
Yuki Kimoto authored on 2011-08-10
906

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
907
$rows = $dbi->select(table => $table1, column => [$key1], where => {$key1 => 3})->all;
908
is_deeply($rows, [{$key1 => 3}], "table and columns and where key");
test cleanup
Yuki Kimoto authored on 2011-08-10
909

            
910
$dbi->register_filter(decrement => sub { $_[0] - 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
911
$rows = $dbi->select(table => $table1, where => {$key1 => 2}, filter => {$key1 => 'decrement'})
test cleanup
Yuki Kimoto authored on 2011-08-10
912
            ->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
913
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
914

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
915
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
916
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
917
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
test cleanup
Yuki Kimoto authored on 2011-08-10
918
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
919
    table => [$table1, $table2],
920
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
921
    where   => {"$table1.$key2" => 2},
922
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
923
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
924
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], "relation : exists where");
test cleanup
Yuki Kimoto authored on 2011-08-10
925

            
926
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
927
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
928
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
929
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
930
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
931
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], "relation : no exists where");
test cleanup
Yuki Kimoto authored on 2011-08-10
932

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
933
eval{$dbi->select(table => $table1, noexist => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
934
like($@, qr/noexist/, "invalid");
935

            
936
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
937
eval { $dbi->execute("drop table ${q}table$p") };
938
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
939
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
940
$dbi->insert(table => 'table', param => {select => 1, update => 2});
941
$result = $dbi->select(table => 'table', where => {select => 1});
942
$rows   = $result->all;
943
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
944

            
945
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
946
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
947
$dbi->register_filter(
948
    twice       => sub { $_[0] * 2 },
949
    three_times => sub { $_[0] * 3 }
950
);
951
$dbi->default_fetch_filter('twice');
952
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
953
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
954
$result = $dbi->select(table => $table1);
955
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
956
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
957
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
958

            
959
test 'filters';
960
$dbi = DBIx::Custom->new;
961

            
962
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
963
   'あ', "decode_utf8");
964

            
965
is($dbi->filters->{encode_utf8}->('あ'),
966
   encode_utf8('あ'), "encode_utf8");
967

            
cleanup test
Yuki Kimoto authored on 2011-08-10
968
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
969
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
970
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
971
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
972
$dbi->begin_work;
973
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
974
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
975
$dbi->rollback;
976
$dbi->dbh->{AutoCommit} = 1;
977

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
978
$result = $dbi->select(table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
979
ok(! $result->fetch_first, "rollback");
980

            
test cleanup
Yuki Kimoto authored on 2011-08-10
981

            
982
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
983
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
984
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
985
$dbi->begin_work;
986
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
987
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
988
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
989
$dbi->commit;
990
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
991
$result = $dbi->select(table => $table1);
992
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
993
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
994

            
995
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
996
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
997
$dbi->execute($create_table1);
998
{
999
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1000
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1001
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1002
    like($@, qr/\.t /, "fail : not verbose");
1003
}
1004
{
1005
    local $Carp::Verbose = 1;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1006
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1007
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1008
}
1009

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1010
eval{$dbi->execute('select * from $table1', no_exists => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1011
like($@, qr/wrong/, "invald SQL");
1012

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1013
$query = $dbi->execute("select * from $table1 where $key1 = :$key1", {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1014
$dbi->dbh->disconnect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1015
eval{$dbi->execute($query, param => {$key1 => {a => 1}})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1016
ok($@, "execute fail");
1017

            
1018
{
1019
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1020
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1021
    like($@, qr/\Q.t /, "caller spec : not vebose");
1022
}
1023
{
1024
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1025
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1026
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1027
}
1028

            
1029

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1030
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1031
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1032
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1033
$dbi->execute($create_table1);
1034

            
1035
$dbi->begin_work;
1036

            
1037
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1038
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1039
    die "Error";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1040
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1041
};
1042

            
1043
$dbi->rollback if $@;
1044

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1045
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1046
$rows = $result->all;
1047
is_deeply($rows, [], "rollback");
1048

            
1049
$dbi->begin_work;
1050

            
1051
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1052
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1053
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1054
};
1055

            
1056
$dbi->commit unless $@;
1057

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1058
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1059
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1060
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1061

            
1062
$dbi->dbh->{AutoCommit} = 0;
1063
eval{ $dbi->begin_work };
1064
ok($@, "exception");
1065
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1066

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1067
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1068
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1069
$dbi->cache(1);
1070
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1071
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1072
$dbi->execute($source, {}, query => 1);
1073
is_deeply($dbi->{_cached}->{$source}, 
cleanup test
Yuki Kimoto authored on 2011-08-15
1074
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1075

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1076
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1077
$dbi->execute($create_table1);
1078
$dbi->{_cached} = {};
1079
$dbi->cache(0);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1080
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1081
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1082

            
1083
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1084
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1085
$dbi->execute($create_table1);
1086
{
1087
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1088
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1089
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1090
    like($@, qr/\.t /, "fail : not verbose");
1091
}
1092
{
1093
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1094
    eval{$dbi->execute('select * frm $table1')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1095
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1096
}
1097

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1098
eval{$dbi->execute('select * from $table1', no_exists => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1099
like($@, qr/wrong/, "invald SQL");
1100

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1101
$query = $dbi->execute("select * from $table1 where $key1 = :$key1", {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1102
$dbi->dbh->disconnect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1103
eval{$dbi->execute($query, param => {$key1 => {a => 1}})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1104
ok($@, "execute fail");
1105

            
1106
{
1107
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1108
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1109
    like($@, qr/\Q.t /, "caller spec : not vebose");
1110
}
1111
{
1112
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1113
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1114
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1115
}
1116

            
1117
test 'method';
1118
$dbi->method(
1119
    one => sub { 1 }
1120
);
1121
$dbi->method(
1122
    two => sub { 2 }
1123
);
1124
$dbi->method({
1125
    twice => sub {
1126
        my $self = shift;
1127
        return $_[0] * 2;
1128
    }
1129
});
1130

            
1131
is($dbi->one, 1, "first");
1132
is($dbi->two, 2, "second");
1133
is($dbi->twice(5), 10 , "second");
1134

            
1135
eval {$dbi->XXXXXX};
1136
ok($@, "not exists");
1137

            
1138
test 'out filter';
1139
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1140
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1141
$dbi->execute($create_table1);
1142
$dbi->register_filter(twice => sub { $_[0] * 2 });
1143
$dbi->register_filter(three_times => sub { $_[0] * 3});
1144
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1145
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1146
              $key2 => {out => 'three_times', in => 'twice'});
1147
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1148
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1149
$row   = $result->fetch_hash_first;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1150
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1151
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1152
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1153
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1154

            
1155
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1156
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1157
$dbi->execute($create_table1);
1158
$dbi->register_filter(twice => sub { $_[0] * 2 });
1159
$dbi->register_filter(three_times => sub { $_[0] * 3});
1160
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1161
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1162
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1163
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1164
    $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1165
); 
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1166
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1167
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1168
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1169
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1170

            
1171
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1172
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1173
$dbi->execute($create_table1);
1174
$dbi->register_filter(twice => sub { $_[0] * 2 });
1175
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1176
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1177
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1178
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => undef});
1179
$dbi->update(table => $table1, param => {$key1 => 2}, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1180
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1181
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1182
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
test cleanup
Yuki Kimoto authored on 2011-08-10
1183

            
1184
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1185
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1186
$dbi->execute($create_table1);
1187
$dbi->register_filter(twice => sub { $_[0] * 2 });
1188
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1189
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1190
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1191
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1=> undef});
1192
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1193
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1194
$rows   = $result->all;
1195
is_deeply($rows, [], "delete");
1196

            
1197
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1198
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1199
$dbi->execute($create_table1);
1200
$dbi->register_filter(twice => sub { $_[0] * 2 });
1201
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1202
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1203
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1204
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
1205
$result = $dbi->select(table => $table1, where => {$key1 => 1});
1206
$result->filter({$key2 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1207
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1208
is_deeply($rows, [{$key1 => 4, $key2 => 4}], "select");
test cleanup
Yuki Kimoto authored on 2011-08-10
1209

            
1210
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1211
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1212
$dbi->execute($create_table1);
1213
$dbi->register_filter(twice => sub { $_[0] * 2 });
1214
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1215
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1216
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1217
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1218
$result = $dbi->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1219
                        param => {$key1 => 1, $key2 => 2},
1220
                        table => [$table1]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1221
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1222
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute");
test cleanup
Yuki Kimoto authored on 2011-08-10
1223

            
1224
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1225
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1226
$dbi->execute($create_table1);
1227
$dbi->register_filter(twice => sub { $_[0] * 2 });
1228
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1229
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1230
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1231
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1232
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1233
                        param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1234
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1235
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1236

            
1237
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1238
eval { $dbi->execute("drop table $table1") };
1239
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1240
$dbi->execute($create_table1);
1241
$dbi->execute($create_table2);
1242
$dbi->register_filter(twice => sub { $_[0] * 2 });
1243
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1244
$dbi->apply_filter(
cleanup test
Yuki Kimoto authored on 2011-08-15
1245
    $table1, $key2 => {out => 'twice', in => 'twice'}
1246
);
1247
$dbi->apply_filter(
1248
    $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1249
);
cleanup test
Yuki Kimoto authored on 2011-08-15
1250
$dbi->insert(table => $table1, param => {$key1 => 5, $key2 => 2}, filter => {$key2 => undef});
1251
$dbi->insert(table => $table2, param => {$key1 => 5, $key3 => 6}, filter => {$key3 => undef});
1252
$result = $dbi->select(
1253
     table => [$table1, $table2],
1254
     column => [$key2, $key3],
1255
     where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1256

            
1257
$result->filter({$key2 => 'twice'});
1258
$rows   = $result->all;
1259
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1260

            
1261
$result = $dbi->select(
1262
     table => [$table1, $table2],
1263
     column => [$key2, $key3],
1264
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1265

            
1266
$result->filter({$key2 => 'twice'});
1267
$rows   = $result->all;
1268
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join : omit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1269

            
1270
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1271
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1272
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1273
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1274
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1275
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1276

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1277
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1278
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1279
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1280
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1281
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1282
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1283

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1284
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1285
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1286
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1287
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1288
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1289

            
1290
test 'end_filter';
1291
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1292
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1293
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1294
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1295
$result = $dbi->select(table => $table1);
1296
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1297
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1298
$row = $result->fetch_first;
1299
is_deeply($row, [6, 40]);
1300

            
1301
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1302
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1303
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1304
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1305
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1306
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1307
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1308
$row = $result->fetch_first;
1309
is_deeply($row, [6, 12]);
1310

            
1311
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1312
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1313
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1314
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1315
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1316
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1317
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1318
$row = $result->fetch_first;
1319
is_deeply($row, [6, 12]);
1320

            
1321
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1322
$result = $dbi->select(table => $table1);
1323
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1324
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1325
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1326
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1327

            
1328
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1329
$dbi->apply_filter($table1,
1330
    $key1 => {end => sub { $_[0] * 3 } },
1331
    $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1332
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1333
$result = $dbi->select(table => $table1);
1334
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1335
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1336
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1337

            
1338
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1339
$dbi->apply_filter($table1,
1340
    $key1 => {end => sub { $_[0] * 3 } },
1341
    $key2 => {end => 'five_times'}
1342
);
1343
$result = $dbi->select(table => $table1);
1344
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1345
$result->filter($key1 => undef);
1346
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1347
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1348
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1349

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1350
test 'remove_end_filter and remove_filter';
1351
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1352
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1353
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1354
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1355
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1356
$row = $result
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1357
       ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1358
       ->remove_filter
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1359
       ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1360
       ->remove_end_filter
1361
       ->fetch_first;
1362
is_deeply($row, [1, 2]);
1363

            
1364
test 'empty where select';
1365
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1366
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1367
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1368
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1369
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1370
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1371
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1372

            
1373
test 'select query option';
1374
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1375
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1376
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1377
$query = $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1378
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1379
$query = $dbi->update(table => $table1, where => {$key1 => 1}, param => {$key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1380
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1381
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1382
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1383
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1384
is(ref $query, 'DBIx::Custom::Query');
1385

            
1386
test 'where';
1387
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1388
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1389
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1390
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1391
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1392
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1393
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1394

            
1395
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1396
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1397
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1398

            
1399
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1400
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1401
    where => $where
1402
);
1403
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1404
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1405

            
1406
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1407
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1408
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1409
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
1410
        {$key1 => 1}
test cleanup
Yuki Kimoto authored on 2011-08-10
1411
    ]
1412
);
1413
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1414
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1415

            
1416
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1417
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1418
             ->param({$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1419
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1420
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1421
    where => $where
1422
);
1423
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1424
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1425

            
1426
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1427
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
test cleanup
Yuki Kimoto authored on 2011-08-10
1428
             ->param({});
1429
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1430
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1431
    where => $where,
1432
);
1433
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1434
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1435

            
1436
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1437
             ->clause(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"])
1438
             ->param({$key1 => [0, 3], $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1439
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1440
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1441
    where => $where,
1442
); 
1443
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1444
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1445

            
1446
$where = $dbi->where;
1447
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1448
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1449
    where => $where
1450
);
1451
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1452
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1453

            
1454
eval {
1455
$where = $dbi->where
1456
             ->clause(['uuu']);
1457
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1458
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1459
    where => $where
1460
);
1461
};
1462
ok($@);
1463

            
1464
$where = $dbi->where;
1465
is("$where", '');
1466

            
1467
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1468
             ->clause(['or', ("$key1 = :$key1") x 2])
1469
             ->param({$key1 => [1, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1470
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1471
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1472
    where => $where,
1473
);
1474
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1475
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1476

            
1477
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1478
             ->clause(['or', ("$key1 = :$key1") x 2])
1479
             ->param({$key1 => [1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1480
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1481
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1482
    where => $where,
1483
);
1484
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1485
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1486

            
1487
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1488
             ->clause(['or', ("$key1 = :$key1") x 2])
1489
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1490
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1491
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1492
    where => $where,
1493
);
1494
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1495
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1496

            
1497
$where = $dbi->where
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1498
             ->clause("$key1 = :$key1")
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1499
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1500
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1501
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1502
    where => $where,
1503
);
1504
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1505
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1506

            
1507
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1508
             ->clause("$key1 = :$key1 $key2 = :$key2")
1509
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1510
eval{$where->to_string};
1511
like($@, qr/one column/);
1512

            
1513
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1514
             ->clause(['or', ("$key1 = :$key1") x 3])
1515
             ->param({$key1 => [$dbi->not_exists, 1, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1516
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1517
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1518
    where => $where,
1519
);
1520
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1521
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1522

            
1523
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1524
             ->clause(['or', ("$key1 = :$key1") x 3])
1525
             ->param({$key1 => [1, $dbi->not_exists, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1526
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1527
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1528
    where => $where,
1529
);
1530
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1531
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1532

            
1533
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1534
             ->clause(['or', ("$key1 = :$key1") x 3])
1535
             ->param({$key1 => [1, 3, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1536
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1537
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1538
    where => $where,
1539
);
1540
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1541
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1542

            
1543
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1544
             ->clause(['or', ("$key1 = :$key1") x 3])
1545
             ->param({$key1 => [1, $dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1546
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1547
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1548
    where => $where,
1549
);
1550
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1551
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1552

            
1553
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1554
             ->clause(['or', ("$key1 = :$key1") x 3])
1555
             ->param({$key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1556
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1557
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1558
    where => $where,
1559
);
1560
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1561
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1562

            
1563
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1564
             ->clause(['or', ("$key1 = :$key1") x 3])
1565
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1566
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1567
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1568
    where => $where,
1569
);
1570
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1571
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1572

            
1573
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1574
             ->clause(['or', ("$key1 = :$key1") x 3])
1575
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1576
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1577
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1578
    where => $where,
1579
);
1580
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1581
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1582

            
1583
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1584
             ->clause(['or', ("$key1 = :$key1") x 3])
1585
             ->param({$key1 => []});
test cleanup
Yuki Kimoto authored on 2011-08-10
1586
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1587
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1588
    where => $where,
1589
);
1590
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1591
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1592

            
1593
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1594
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1595
             ->param({$key1 => [2, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1596
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1597
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1598
    where => $where,
1599
);
1600
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1601
is_deeply($row, [{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1602

            
1603
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1604
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1605
             ->param({$key1 => [$dbi->not_exists, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1606
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1607
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1608
    where => $where,
1609
);
1610
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1611
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1612

            
1613
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1614
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1615
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1616
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1617
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1618
    where => $where,
1619
);
1620
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1621
is_deeply($row, [{$key1 => 1, $key2 => 2},{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1622

            
1623
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1624
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1625
             ->param({$key1 => [0, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1626
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1627
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1628
    where => $where,
1629
);
1630
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1631
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1632

            
1633
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1634
             ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1635
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1636
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1637
    where => $where,
1638
);
1639
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1640
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1641

            
1642
eval {$dbi->where(ppp => 1) };
1643
like($@, qr/invalid/);
1644

            
1645
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1646
    clause => ['and', ['or'], ['and', "$key1 = :$key1", "$key2 = :$key2"]],
1647
    param => {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
1648
);
1649
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1650
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1651
    where => $where,
1652
);
1653
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1654
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1655

            
1656

            
1657
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1658
    clause => ['and', ['or'], ['or', ":$key1", ":$key2"]],
test cleanup
Yuki Kimoto authored on 2011-08-10
1659
    param => {}
1660
);
1661
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1662
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1663
    where => $where,
1664
);
1665
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1666
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1667

            
1668
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1669
$where->clause(['and', ":${key1}{=}"]);
1670
$where->param({$key1 => undef});
1671
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1672
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1673
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1674

            
1675
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1676
$where->clause(['and', ":${key1}{=}"]);
1677
$where->param({$key1 => undef});
test cleanup
Yuki Kimoto authored on 2011-08-10
1678
$where->if('defined');
1679
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1680
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1681
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1682
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1683

            
1684
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1685
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1686
$where->param({$key1 => [undef, undef]});
1687
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1688
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1689
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1690
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1691
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1692
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1693

            
1694
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1695
$where->clause(['and', ":${key1}{=}"]);
1696
$where->param({$key1 => [undef, undef]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1697
$where->if('defined');
1698
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1699
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1700
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1701
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
1702
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1703
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1704
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1705

            
1706
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1707
$where->clause(['and', ":${key1}{=}"]);
1708
$where->param({$key1 => 0});
test cleanup
Yuki Kimoto authored on 2011-08-10
1709
$where->if('length');
1710
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1711
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1712
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1713
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1714

            
1715
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1716
$where->clause(['and', ":${key1}{=}"]);
1717
$where->param({$key1 => ''});
test cleanup
Yuki Kimoto authored on 2011-08-10
1718
$where->if('length');
1719
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1720
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1721
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1722
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1723

            
1724
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1725
$where->clause(['and', ":${key1}{=}"]);
1726
$where->param({$key1 => 5});
test cleanup
Yuki Kimoto authored on 2011-08-10
1727
$where->if(sub { ($_[0] || '') eq 5 });
1728
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1729
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1730
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1731
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1732

            
1733
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1734
$where->clause(['and', ":${key1}{=}"]);
1735
$where->param({$key1 => 7});
test cleanup
Yuki Kimoto authored on 2011-08-10
1736
$where->if(sub { ($_[0] || '') eq 5 });
1737
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1738
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1739
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1740
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1741

            
1742
$where = $dbi->where;
1743
$where->param({id => 1, author => 'Ken', price => 1900});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1744
$where->map(id => "$table1.id",
1745
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
1746
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1747
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1748
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1749
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
1750

            
1751
$where = $dbi->where;
1752
$where->param({id => 0, author => 0, price => 0});
1753
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1754
    id => "$table1.id",
1755
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
1756
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
test cleanup
Yuki Kimoto authored on 2011-08-10
1757
      {if => sub { $_[0] eq 0 }}]
1758
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1759
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1760

            
1761
$where = $dbi->where;
1762
$where->param({id => '', author => '', price => ''});
1763
$where->if('length');
1764
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1765
    id => "$table1.id",
1766
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
1767
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
test cleanup
Yuki Kimoto authored on 2011-08-10
1768
      {if => sub { $_[0] eq 1 }}]
1769
);
1770
is_deeply($where->param, {});
1771

            
1772
$where = $dbi->where;
1773
$where->param({id => undef, author => undef, price => undef});
1774
$where->if('length');
1775
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1776
    id => "$table1.id",
1777
    price => ["$table1.price", {if => 'exists'}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1778
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1779
is_deeply($where->param, {"$table1.price" => undef});
test cleanup
Yuki Kimoto authored on 2011-08-10
1780

            
1781
$where = $dbi->where;
1782
$where->param({price => 'a'});
1783
$where->if('length');
1784
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1785
    id => ["$table1.id", {if => 'exists'}],
1786
    price => ["$table1.price", sub { '%' . $_[0] }, {if => 'exists'}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1787
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1788
is_deeply($where->param, {"$table1.price" => '%a'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1789

            
1790
$where = $dbi->where;
1791
$where->param({id => [1, 2], author => 'Ken', price => 1900});
1792
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1793
    id => "$table1.id",
1794
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
1795
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1796
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1797
is_deeply($where->param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1798
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
1799

            
1800
$where = $dbi->where;
1801
$where->if('length');
1802
$where->param({id => ['', ''], author => 'Ken', price => 1900});
1803
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1804
    id => "$table1.id",
1805
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
1806
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1807
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1808
is_deeply($where->param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1809
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
1810

            
1811
$where = $dbi->where;
1812
$where->param({id => ['', ''], author => 'Ken', price => 1900});
1813
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1814
    id => ["$table1.id", {if => 'length'}],
1815
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, {if => 'defined'}],
1816
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1817
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1818
is_deeply($where->param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1819
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
1820

            
1821
test 'register_tag_processor';
1822
$dbi = DBIx::Custom->connect;
1823
$dbi->register_tag_processor(
1824
    a => sub { 1 }
1825
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1826
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1827

            
1828
test 'register_tag';
1829
$dbi = DBIx::Custom->connect;
1830
$dbi->register_tag(
1831
    b => sub { 2 }
1832
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1833
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1834

            
1835
test 'table not specify exception';
1836
$dbi = DBIx::Custom->connect;
1837
eval {$dbi->insert};
1838
like($@, qr/table/);
1839
eval {$dbi->update};
1840
like($@, qr/table/);
1841
eval {$dbi->delete};
1842
like($@, qr/table/);
1843
eval {$dbi->select};
1844
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1845

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1846
test 'more tests';
1847
$dbi = DBIx::Custom->connect;
1848
eval{$dbi->apply_filter('table', 'column', [])};
1849
like($@, qr/apply_filter/);
1850

            
1851
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1852
like($@, qr/apply_filter/);
1853

            
1854
$dbi->apply_filter(
1855

            
1856
);
1857
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1858
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1859
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1860
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1861
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1862
$dbi->apply_filter($table1, $key2, 
test cleanup
Yuki Kimoto authored on 2011-08-10
1863
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1864
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
1865
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1866

            
1867
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1868
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1869
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1870
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1871
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1872
$dbi->apply_filter($table1, $key2, {});
1873
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1874
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1875

            
1876
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1877
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1878
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1879
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1880
like($@, qr/not registered/);
1881
$dbi->method({one => sub { 1 }});
1882
is($dbi->one, 1);
1883

            
1884
eval{DBIx::Custom->connect(dsn => undef)};
1885
like($@, qr/_connect/);
1886

            
1887
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1888
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1889
$dbi->execute($create_table1);
1890
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1891
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1892
             filter => {$key1 => 'twice'});
1893
$row = $dbi->select(table => $table1)->one;
1894
is_deeply($row, {$key1 => 2, $key2 => 2});
1895
eval {$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1896
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
1897
like($@, qr//);
1898

            
1899
$dbi->register_filter(one => sub { });
1900
$dbi->default_fetch_filter('one');
1901
ok($dbi->default_fetch_filter);
1902
$dbi->default_bind_filter('one');
1903
ok($dbi->default_bind_filter);
1904
eval{$dbi->default_fetch_filter('no')};
1905
like($@, qr/not registered/);
1906
eval{$dbi->default_bind_filter('no')};
1907
like($@, qr/not registered/);
1908
$dbi->default_bind_filter(undef);
1909
ok(!defined $dbi->default_bind_filter);
1910
$dbi->default_fetch_filter(undef);
1911
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1912
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1913
like($@, qr/Tag not finished/);
1914

            
1915
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1916
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1917
$dbi->execute($create_table1);
1918
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1919
$result = $dbi->select(table => $table1);
1920
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1921
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1922
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1923
like($@, qr/not registered/);
1924
$result->default_filter(undef);
1925
ok(!defined $result->default_filter);
1926
$result->default_filter('one');
1927
is($result->default_filter->(), 1);
1928

            
1929
test 'dbi_option';
1930
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
1931
ok($dbi->dbh->{PrintError});
1932
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
1933
ok($dbi->dbh->{PrintError});
1934

            
1935
test 'DBIx::Custom::Result stash()';
1936
$result = DBIx::Custom::Result->new;
1937
is_deeply($result->stash, {}, 'default');
1938
$result->stash->{foo} = 1;
1939
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
1940

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1941
test 'delete_at';
1942
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1943
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1944
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1945
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1946
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1947
    table => $table1,
1948
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1949
    where => [1, 2],
1950
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1951
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1952

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1953
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1954
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1955
    table => $table1,
1956
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1957
    where => 1,
1958
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1959
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1960

            
1961
test 'insert_at';
1962
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1963
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1964
$dbi->execute($create_table1_2);
1965
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1966
    primary_key => [$key1, $key2], 
1967
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1968
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1969
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1970
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1971
is($dbi->select(table => $table1)->one->{$key1}, 1);
1972
is($dbi->select(table => $table1)->one->{$key2}, 2);
1973
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1974

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1975
$dbi->delete_all(table => $table1);
1976
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1977
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1978
    primary_key => $key1, 
1979
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1980
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1981
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1982
);
1983

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1984
is($dbi->select(table => $table1)->one->{$key1}, 1);
1985
is($dbi->select(table => $table1)->one->{$key2}, 2);
1986
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1987

            
1988
eval {
1989
    $dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1990
        table => $table1,
1991
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1992
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1993
        param => {$key1 => 1, $key2 => 2, $key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
1994
    );
1995
};
1996
like($@, qr/must be/);
1997

            
1998
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1999
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2000
$dbi->execute($create_table1_2);
2001
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2002
    {$key3 => 3},
2003
    primary_key => [$key1, $key2], 
2004
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2005
    where => [1, 2],
2006
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2007
is($dbi->select(table => $table1)->one->{$key1}, 1);
2008
is($dbi->select(table => $table1)->one->{$key2}, 2);
2009
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2010

            
2011
test 'update_at';
2012
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2013
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2014
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2015
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2016
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2017
    table => $table1,
2018
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2019
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2020
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2021
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2022
is($dbi->select(table => $table1)->one->{$key1}, 1);
2023
is($dbi->select(table => $table1)->one->{$key2}, 2);
2024
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2025

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2026
$dbi->delete_all(table => $table1);
2027
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2028
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2029
    table => $table1,
2030
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2031
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2032
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2033
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2034
is($dbi->select(table => $table1)->one->{$key1}, 1);
2035
is($dbi->select(table => $table1)->one->{$key2}, 2);
2036
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2037

            
2038
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2039
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2040
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2041
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2042
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2043
    {$key3 => 4},
2044
    table => $table1,
2045
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2046
    where => [1, 2]
2047
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2048
is($dbi->select(table => $table1)->one->{$key1}, 1);
2049
is($dbi->select(table => $table1)->one->{$key2}, 2);
2050
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2051

            
2052
test 'select_at';
2053
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2054
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2055
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2056
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2057
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2058
    table => $table1,
2059
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2060
    where => [1, 2]
2061
);
2062
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2063
is($row->{$key1}, 1);
2064
is($row->{$key2}, 2);
2065
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2066

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2067
$dbi->delete_all(table => $table1);
2068
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2069
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2070
    table => $table1,
2071
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2072
    where => 1,
2073
);
2074
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2075
is($row->{$key1}, 1);
2076
is($row->{$key2}, 2);
2077
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2078

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2079
$dbi->delete_all(table => $table1);
2080
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2081
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2082
    table => $table1,
2083
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2084
    where => [1, 2]
2085
);
2086
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2087
is($row->{$key1}, 1);
2088
is($row->{$key2}, 2);
2089
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2090

            
2091
eval {
2092
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2093
        table => $table1,
2094
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2095
        where => {},
2096
    );
2097
};
2098
like($@, qr/must be/);
2099

            
2100
eval {
2101
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2102
        table => $table1,
2103
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2104
        where => [1],
2105
    );
2106
};
2107
like($@, qr/same/);
2108

            
2109
eval {
2110
    $result = $dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2111
        table => $table1,
2112
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2113
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2114
        param => {$key1 => 1, $key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-10
2115
    );
2116
};
2117
like($@, qr/must be/);
2118

            
2119
eval {
2120
    $result = $dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2121
        table => $table1,
2122
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2123
        where => {},
2124
    );
2125
};
2126
like($@, qr/must be/);
2127

            
2128
test 'model delete_at';
2129
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2130
eval { $dbi->execute("drop table $table1") };
2131
eval { $dbi->execute("drop table $table2") };
2132
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2133
$dbi->execute($create_table1_2);
2134
$dbi->execute($create_table2_2);
2135
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2136
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2137
$dbi->model($table1)->delete_at(where => [1, 2]);
2138
is_deeply($dbi->select(table => $table1)->all, []);
2139
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2140
$dbi->model($table1)->delete_at(where => [1, 2]);
2141
is_deeply($dbi->select(table => $table1)->all, []);
2142
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2143
$dbi->model($table3)->delete_at(where => [1, 2]);
2144
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2145

            
2146
test 'model insert_at';
2147
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2148
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2149
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2150
$dbi->model($table1)->insert_at(
cleanup test
Yuki Kimoto authored on 2011-08-10
2151
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2152
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2153
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2154
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2155
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2156
is($row->{$key1}, 1);
2157
is($row->{$key2}, 2);
2158
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2159

            
2160
test 'model update_at';
2161
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2162
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2163
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2164
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2165
$dbi->model($table1)->update_at(
cleanup test
Yuki Kimoto authored on 2011-08-10
2166
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2167
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2168
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2169
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2170
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2171
is($row->{$key1}, 1);
2172
is($row->{$key2}, 2);
2173
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2174

            
2175
test 'model select_at';
2176
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2177
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2178
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2179
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2180
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2181
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2182
is($row->{$key1}, 1);
2183
is($row->{$key2}, 2);
2184
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2185

            
2186

            
2187
test 'mycolumn and column';
2188
$dbi = MyDBI7->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2189
eval { $dbi->execute("drop table $table1") };
2190
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2191
$dbi->execute($create_table1);
2192
$dbi->execute($create_table2);
2193
$dbi->separator('__');
2194
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2195
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2196
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2197
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2198
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2199
    column => [$model->mycolumn, $model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2200
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2201
);
2202
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2203
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2204

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2205
test 'insert_param';
2206
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2207
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2208
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2209
$param = {$key1 => 1, $key2 => 2};
test cleanup
Yuki Kimoto authored on 2011-08-10
2210
$insert_param = $dbi->insert_param($param);
2211
$sql = <<"EOS";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2212
insert into $table1 $insert_param
test cleanup
Yuki Kimoto authored on 2011-08-10
2213
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2214
$dbi->execute($sql, param => $param, table => $table1);
2215
is($dbi->select(table => $table1)->one->{$key1}, 1);
2216
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2217

            
2218
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2219
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2220
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2221
$param = {$key1 => 1, $key2 => 2};
test cleanup
Yuki Kimoto authored on 2011-08-10
2222
$insert_param = $dbi->insert_param($param);
2223
$sql = <<"EOS";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2224
insert into $table1 $insert_param
test cleanup
Yuki Kimoto authored on 2011-08-10
2225
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2226
$dbi->execute($sql, param => $param, table => $table1);
2227
is($dbi->select(table => $table1)->one->{$key1}, 1);
2228
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2229

            
2230
eval { $dbi->insert_param({";" => 1}) };
2231
like($@, qr/not safety/);
test cleanup
Yuki Kimoto authored on 2011-08-10
2232

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2233
test 'mycolumn';
2234
$dbi = MyDBI8->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2235
eval { $dbi->execute("drop table $table1") };
2236
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2237
$dbi->execute($create_table1);
2238
$dbi->execute($create_table2);
2239
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2240
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2241
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2242
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2243
$result = $model->select_at(
2244
    column => [
2245
        $model->mycolumn,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2246
        $model->column($table2)
cleanup test
Yuki Kimoto authored on 2011-08-10
2247
    ]
2248
);
2249
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2250
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2251

            
2252
$result = $model->select_at(
2253
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2254
        $model->mycolumn([$key1]),
2255
        $model->column($table2 => [$key1])
cleanup test
Yuki Kimoto authored on 2011-08-10
2256
    ]
2257
);
2258
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2259
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2260
$result = $model->select_at(
2261
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2262
        $model->mycolumn([$key1]),
2263
        {$table2 => [$key1]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2264
    ]
2265
);
2266
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2267
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2268

            
2269
$result = $model->select_at(
2270
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2271
        $model->mycolumn([$key1]),
2272
        ["$table2.$key1", as => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2273
    ]
2274
);
2275
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2276
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2277

            
2278
$result = $model->select_at(
2279
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2280
        $model->mycolumn([$key1]),
2281
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2282
    ]
2283
);
2284
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2285
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2286

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2287
test 'merge_param';
2288
$dbi = DBIx::Custom->new;
2289
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2290
    {$key1 => 1, $key2 => 2, $key3 => 3},
2291
    {$key1 => 1, $key2 => 2},
2292
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2293
];
2294
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2295
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2296

            
2297
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2298
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2299
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2300
];
2301
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2302
is_deeply($param, {$key1 => [1, 2, 3, 4], $key2 => [1, 2, 3], $key3 => [1, 2, 3]});
cleanup test
Yuki Kimoto authored on 2011-08-10
2303

            
2304
test 'select() param option';
2305
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2306
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2307
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2308
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2309
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2310
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2311
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2312
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
2313
$dbi->insert(table => $table2, param => {$key1 => 2, $key3 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-10
2314
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2315
    table => $table1,
2316
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2317
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2318
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
test cleanup
Yuki Kimoto authored on 2011-08-15
2319
              " $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2320
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2321
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2322
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2323

            
2324
test 'select() string where';
2325
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2326
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2327
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2328
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2329
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2330
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2331
    table => $table1,
2332
    where => "$key1 = :$key1 and $key2 = :$key2",
2333
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2334
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2335
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2336

            
2337
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2338
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2339
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2340
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2341
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2342
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2343
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2344
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2345
        "$key1 = :$key1 and $key2 = :$key2",
2346
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2347
    ]
2348
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2349
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2350

            
2351
test 'delete() string where';
2352
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2353
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2354
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2355
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2356
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2357
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2358
    table => $table1,
2359
    where => "$key1 = :$key1 and $key2 = :$key2",
2360
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2361
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2362
$rows = $dbi->select(table => $table1)->all;
2363
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2364

            
2365
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2366
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2367
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2368
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2369
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2370
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2371
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2372
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2373
        "$key1 = :$key1 and $key2 = :$key2",
2374
         {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2375
    ]
2376
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2377
$rows = $dbi->select(table => $table1)->all;
2378
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2379

            
2380

            
2381
test 'update() string where';
2382
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2383
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2384
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2385
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2386
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2387
    table => $table1,
2388
    param => {$key1 => 5},
2389
    where => "$key1 = :$key1 and $key2 = :$key2",
2390
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2391
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2392
$rows = $dbi->select(table => $table1)->all;
2393
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2394

            
2395
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2396
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2397
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2398
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2399
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2400
    table => $table1,
2401
    param => {$key1 => 5},
cleanup test
Yuki Kimoto authored on 2011-08-10
2402
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2403
        "$key1 = :$key1 and $key2 = :$key2",
2404
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2405
    ]
2406
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2407
$rows = $dbi->select(table => $table1)->all;
2408
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2409

            
2410
test 'insert id and primary_key option';
2411
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2412
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2413
$dbi->execute($create_table1_2);
2414
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2415
    primary_key => [$key1, $key2], 
2416
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2417
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2418
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2419
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2420
is($dbi->select(table => $table1)->one->{$key1}, 1);
2421
is($dbi->select(table => $table1)->one->{$key2}, 2);
2422
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2423

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2424
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2425
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2426
    primary_key => $key1, 
2427
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2428
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2429
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2430
);
2431

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2432
is($dbi->select(table => $table1)->one->{$key1}, 0);
2433
is($dbi->select(table => $table1)->one->{$key2}, 2);
2434
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2435

            
2436
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2437
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2438
$dbi->execute($create_table1_2);
2439
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2440
    {$key3 => 3},
2441
    primary_key => [$key1, $key2], 
2442
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2443
    id => [1, 2],
2444
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2445
is($dbi->select(table => $table1)->one->{$key1}, 1);
2446
is($dbi->select(table => $table1)->one->{$key2}, 2);
2447
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2448

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2449
test 'model insert id and primary_key option';
2450
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2451
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2452
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2453
$dbi->model($table1)->insert(
cleanup test
Yuki Kimoto authored on 2011-08-10
2454
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2455
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2456
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2457
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2458
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2459
is($row->{$key1}, 1);
2460
is($row->{$key2}, 2);
2461
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2462

            
2463
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2464
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2465
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2466
$dbi->model($table1)->insert(
2467
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2468
    id => [1, 2]
2469
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2470
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2471
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2472
is($row->{$key1}, 1);
2473
is($row->{$key2}, 2);
2474
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2475

            
2476
test 'update and id option';
2477
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2478
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2479
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2480
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2481
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2482
    table => $table1,
2483
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2484
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2485
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2486
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2487
is($dbi->select(table => $table1)->one->{$key1}, 1);
2488
is($dbi->select(table => $table1)->one->{$key2}, 2);
2489
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2490

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2491
$dbi->delete_all(table => $table1);
2492
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2493
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2494
    table => $table1,
2495
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2496
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2497
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2498
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2499
is($dbi->select(table => $table1)->one->{$key1}, 0);
2500
is($dbi->select(table => $table1)->one->{$key2}, 2);
2501
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2502

            
2503
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2504
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2505
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2506
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2507
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2508
    {$key3 => 4},
2509
    table => $table1,
2510
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2511
    id => [1, 2]
2512
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2513
is($dbi->select(table => $table1)->one->{$key1}, 1);
2514
is($dbi->select(table => $table1)->one->{$key2}, 2);
2515
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2516

            
2517

            
2518
test 'model update and id option';
2519
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2520
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2521
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2522
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2523
$dbi->model($table1)->update(
cleanup test
Yuki Kimoto authored on 2011-08-10
2524
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2525
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2526
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2527
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2528
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2529
is($row->{$key1}, 1);
2530
is($row->{$key2}, 2);
2531
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2532

            
2533

            
2534
test 'delete and id option';
2535
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2536
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2537
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2538
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2539
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2540
    table => $table1,
2541
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2542
    id => [1, 2],
2543
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2544
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2545

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2546
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2547
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2548
    table => $table1,
2549
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2550
    id => 0,
2551
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2552
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2553

            
2554

            
2555
test 'model delete and id option';
2556
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2557
eval { $dbi->execute("drop table $table1") };
2558
eval { $dbi->execute("drop table $table2") };
2559
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2560
$dbi->execute($create_table1_2);
2561
$dbi->execute($create_table2_2);
2562
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2563
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2564
$dbi->model($table1)->delete(id => [1, 2]);
2565
is_deeply($dbi->select(table => $table1)->all, []);
2566
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2567
$dbi->model($table1)->delete(id => [1, 2]);
2568
is_deeply($dbi->select(table => $table1)->all, []);
2569
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2570
$dbi->model($table3)->delete(id => [1, 2]);
2571
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2572

            
2573

            
2574
test 'select and id option';
2575
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2576
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2577
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2578
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2579
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2580
    table => $table1,
2581
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2582
    id => [1, 2]
2583
);
2584
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2585
is($row->{$key1}, 1);
2586
is($row->{$key2}, 2);
2587
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2588

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2589
$dbi->delete_all(table => $table1);
2590
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2591
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2592
    table => $table1,
2593
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2594
    id => 0,
2595
);
2596
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2597
is($row->{$key1}, 0);
2598
is($row->{$key2}, 2);
2599
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2600

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2601
$dbi->delete_all(table => $table1);
2602
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2603
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2604
    table => $table1,
2605
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2606
    id => [1, 2]
2607
);
2608
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2609
is($row->{$key1}, 1);
2610
is($row->{$key2}, 2);
2611
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2612

            
2613

            
2614
test 'model select_at';
2615
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2616
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2617
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2618
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2619
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2620
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2621
is($row->{$key1}, 1);
2622
is($row->{$key2}, 2);
2623
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2624

            
2625
test 'column separator is default .';
2626
$dbi = MyDBI7->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2627
eval { $dbi->execute("drop table $table1") };
2628
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2629
$dbi->execute($create_table1);
2630
$dbi->execute($create_table2);
2631
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2632
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2633
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2634
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2635
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2636
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2637
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2638
);
2639
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2640
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2641

            
2642
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2643
    column => [$model->column($table2 => [$key1, $key3])],
2644
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2645
);
2646
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2647
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2648

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2649
test 'separator';
2650
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2651
eval { $dbi->execute("drop table $table1") };
2652
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2653
$dbi->execute($create_table1);
2654
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2655

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2656
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2657
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2658
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2659
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2660
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2661
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2662
);
2663
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2664
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2665
);
2666
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2667
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2668
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2669
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2670
$result = $model->select(
2671
    column => [
2672
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2673
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2674
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2675
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2676
);
2677
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2678
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2679
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2680

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2681
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2682
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2683
$result = $model->select(
2684
    column => [
2685
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2686
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2687
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2688
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2689
);
2690
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2691
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
2692
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2693

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2694
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2695
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2696
$result = $model->select(
2697
    column => [
2698
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2699
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2700
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2701
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2702
);
2703
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2704
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2705
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2706

            
2707

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2708
test 'filter_off';
2709
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2710
eval { $dbi->execute("drop table $table1") };
2711
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2712
$dbi->execute($create_table1);
2713
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2714

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2715
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2716
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2717
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2718
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2719
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2720
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2721
);
2722
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2723
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2724
$model = $dbi->model($table1);
2725
$result = $model->select(column => $key1);
2726
$result->filter($key1 => sub { $_[0] * 2 });
2727
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2728

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2729
test 'available_datetype';
2730
$dbi = DBIx::Custom->connect;
2731
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2732

            
2733

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2734
test 'select prefix option';
2735
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2736
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2737
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2738
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2739
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2740
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2741

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2742
test 'map_param';
2743
$dbi = DBIx::Custom->connect;
2744
$param = $dbi->map_param(
2745
    {id => 1, author => 'Ken', price => 1900},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2746
    id => "$table1.id",
2747
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2748
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
cleanup test
Yuki Kimoto authored on 2011-08-10
2749
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2750
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2751
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
2752

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2753
$param = $dbi->map_param(
2754
    {id => 0, author => 0, price => 0},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2755
    id => "$table1.id",
2756
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2757
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
cleanup test
Yuki Kimoto authored on 2011-08-10
2758
      {if => sub { $_[0] eq 0 }}]
2759
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2760
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
test cleanup
Yuki Kimoto authored on 2011-08-10
2761

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2762
$param = $dbi->map_param(
2763
    {id => '', author => '', price => ''},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2764
    id => "$table1.id",
2765
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2766
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
cleanup test
Yuki Kimoto authored on 2011-08-10
2767
      {if => sub { $_[0] eq 1 }}]
2768
);
2769
is_deeply($param, {});
test cleanup
Yuki Kimoto authored on 2011-08-10
2770

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2771
$param = $dbi->map_param(
2772
    {id => undef, author => undef, price => undef},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2773
    id => "$table1.id",
2774
    price => ["$table1.price", {if => 'exists'}]
cleanup test
Yuki Kimoto authored on 2011-08-10
2775
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2776
is_deeply($param, {"$table1.price" => undef});
test cleanup
Yuki Kimoto authored on 2011-08-10
2777

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2778
$param = $dbi->map_param(
2779
    {price => 'a'},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2780
    id => ["$table1.id", {if => 'exists'}],
2781
    price => ["$table1.price", sub { '%' . $_[0] }, {if => 'exists'}]
cleanup test
Yuki Kimoto authored on 2011-08-10
2782
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2783
is_deeply($param, {"$table1.price" => '%a'});
test cleanup
Yuki Kimoto authored on 2011-08-10
2784

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2785
test 'order';
2786
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2787
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2788
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2789
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2790
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
2791
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
2792
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2793
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2794
$order->prepend($key1, "$key2 desc");
2795
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2796
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
2797
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2798
$order->prepend("$key1 desc");
2799
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2800
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
2801
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2802

            
2803
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2804
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2805
$result = $dbi->select(table => $table1,
2806
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2807
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2808
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
2809
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
2810
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
2811
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2812

            
2813
test 'tag_parse';
2814
$dbi = DBIx::Custom->connect;
2815
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2816
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2817
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2818
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2819
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2820
ok($@);
2821

            
2822
test 'last_sql';
2823
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2824
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2825
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2826
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
2827
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2828

            
2829
eval{$dbi->execute("aaa")};
cleanup test
Yuki Kimoto authored on 2011-08-15
2830
is($dbi->last_sql, 'aaa');
test cleanup
Yuki Kimoto authored on 2011-08-10
2831

            
2832
test 'DBIx::Custom header';
2833
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2834
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2835
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2836
$result = $dbi->execute("select $key1 as h1, $key2 as h2 from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-15
2837
is_deeply([map { lc } @{$result->header}], [qw/h1 h2/]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2838

            
2839
test 'Named placeholder :name(operater) syntax';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2840
$dbi->execute("drop table $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2841
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2842
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
2843
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
2844

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2845
$source = "select * from $table1 where :${key1}{=} and :${key2}{=}";
2846
$result = $dbi->execute($source, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2847
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2848
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2849

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2850
$source = "select * from $table1 where :${key1}{ = } and :${key2}{=}";
2851
$result = $dbi->execute($source, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2852
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2853
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2854

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2855
$source = "select * from $table1 where :${key1}{<} and :${key2}{=}";
2856
$result = $dbi->execute($source, param => {$key1 => 5, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2857
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2858
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2859

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2860
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
2861
$result = $dbi->execute(
2862
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2863
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2864
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
2865
);
2866
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2867
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2868

            
2869
test 'high perfomance way';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2870
$dbi->execute("drop table $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2871
$dbi->execute($create_table1_highperformance);
2872
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2873
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2874
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2875
];
2876
{
2877
    my $query;
2878
    foreach my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2879
      $query ||= $dbi->insert($row, table => $table1, query => 1);
2880
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
2881
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2882
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2883
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2884
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2885
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2886
      ]
2887
    );
2888
}
2889

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2890
$dbi->execute("drop table $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2891
$dbi->execute($create_table1_highperformance);
2892
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2893
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2894
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2895
];
2896
{
2897
    my $query;
2898
    my $sth;
2899
    foreach my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2900
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2901
      $sth ||= $query->sth;
2902
      $sth->execute(map { $row->{$_} } sort keys %$row);
2903
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2904
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2905
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2906
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2907
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2908
      ]
2909
    );
2910
}
2911

            
2912
test 'result';
2913
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2914
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2915
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2916
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2917
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2918

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2919
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2920
@rows = ();
2921
while (my $row = $result->fetch) {
2922
    push @rows, [@$row];
2923
}
2924
is_deeply(\@rows, [[1, 2], [3, 4]]);
2925

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2926
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2927
@rows = ();
2928
while (my $row = $result->fetch_hash) {
2929
    push @rows, {%$row};
2930
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2931
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2932

            
2933
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2934
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2935
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2936
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2937
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2938

            
2939
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2940
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2941
$rows = $result->fetch_all;
2942
is_deeply($rows, [[1, 2], [3, 4]]);
2943

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2944
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2945
$rows = $result->fetch_hash_all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2946
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2947

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2948
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2949
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2950
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
2951

            
2952
$rows = $result->fetch_all;
2953
is_deeply($rows, [[3, 2], [9, 4]], "array");
2954

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2955
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2956
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2957
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
2958
$rows = $result->fetch_hash_all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2959
is_deeply($rows, [{$key1 => 3, $key2 => 2}, {$key1 => 9, $key2 => 4}], "hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
2960

            
2961
test "query_builder";
2962
$datas = [
2963
    # Basic tests
2964
    {   name            => 'placeholder basic',
2965
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
2966
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
2967
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
2968
    },
2969
    {
2970
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
2971
        source            => "{in k1 3}",
2972
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
2973
        columns_expected   => [qw/k1 k1 k1/]
2974
    },
2975
    
2976
    # Table name
2977
    {
2978
        name            => 'placeholder with table name',
2979
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
2980
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
2981
        columns_expected  => [qw/a.k1 a.k2/]
2982
    },
2983
    {   
2984
        name            => 'placeholder in with table name',
2985
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
2986
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
2987
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
2988
    },
2989
    {
2990
        name            => 'not contain tag',
2991
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
2992
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
2993
        columns_expected  => [],
2994
    }
2995
];
2996

            
2997
for (my $i = 0; $i < @$datas; $i++) {
2998
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
2999
    my $dbi = DBIx::Custom->new;
3000
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3001
    my $query = $builder->build_query($data->{source});
3002
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3003
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3004
}
3005

            
cleanup
Yuki Kimoto authored on 2011-08-13
3006
$dbi = DBIx::Custom->new;
3007
$builder = $dbi->query_builder;
3008
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3009
    p => sub {
3010
        my @args = @_;
3011
        
3012
        my $expand    = "? $args[0] $args[1]";
3013
        my $columns = [2];
3014
        return [$expand, $columns];
3015
    }
3016
);
3017

            
3018
$query = $builder->build_query("{p a b}");
cleanup test
Yuki Kimoto authored on 2011-08-15
3019
is($query->{sql}, "? a b", "register_tag sql");
test cleanup
Yuki Kimoto authored on 2011-08-10
3020
is_deeply($query->{columns}, [2], "register_tag columns");
3021

            
3022
eval{$builder->build_query('{? }')};
3023
like($@, qr/\QColumn name must be specified in tag "{? }"/, "? not arguments");
3024

            
3025
eval{$builder->build_query("{a }")};
3026
like($@, qr/\QTag "a" is not registered/, "tag not exist");
3027

            
cleanup
Yuki Kimoto authored on 2011-08-13
3028
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3029
    q => 'string'
3030
});
3031

            
3032
eval{$builder->build_query("{q}", {})};
3033
like($@, qr/Tag "q" must be sub reference/, "tag not code ref");
3034

            
cleanup
Yuki Kimoto authored on 2011-08-13
3035
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3036
   r => sub {} 
3037
});
3038

            
3039
eval{$builder->build_query("{r}")};
3040
like($@, qr/\QTag "r" must return [STRING, ARRAY_REFERENCE]/, "tag return noting");
3041

            
cleanup
Yuki Kimoto authored on 2011-08-13
3042
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3043
   s => sub { return ["a", ""]} 
3044
});
3045

            
3046
eval{$builder->build_query("{s}")};
3047
like($@, qr/\QTag "s" must return [STRING, ARRAY_REFERENCE]/, "tag return not array columns");
3048

            
cleanup
Yuki Kimoto authored on 2011-08-13
3049
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3050
    t => sub {return ["a", []]}
3051
);
3052

            
3053

            
cleanup
Yuki Kimoto authored on 2011-08-13
3054
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3055
    a => sub {
3056
        return ["? ? ?", ['']];
3057
    }
3058
);
3059
eval{$builder->build_query("{a}")};
3060
like($@, qr/\QPlaceholder count/, "placeholder count is invalid");
3061

            
3062

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3063
test 'Default tag Error case';
3064
eval{$builder->build_query("{= }")};
3065
like($@, qr/Column name must be specified in tag "{= }"/, "basic '=' : key not exist");
3066

            
3067
eval{$builder->build_query("{in }")};
3068
like($@, qr/Column name and count of values must be specified in tag "{in }"/, "in : key not exist");
3069

            
3070
eval{$builder->build_query("{in a}")};
3071
like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/,
3072
     "in : key not exist");
3073

            
3074
eval{$builder->build_query("{in a r}")};
3075
like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/,
3076
     "in : key not exist");
3077

            
3078
test 'variouse source';
3079
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3080
$query = $builder->build_query($source);
3081
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3082

            
3083
$source = "abc";
3084
$query = $builder->build_query($source);
3085
is($query->sql, 'abc', "basic : 2");
3086

            
3087
$source = "{= a}";
3088
$query = $builder->build_query($source);
3089
is($query->sql, 'a = ?', "only tag");
3090

            
3091
$source = "000";
3092
$query = $builder->build_query($source);
3093
is($query->sql, '000', "contain 0 value");
3094

            
3095
$source = "a {= b} }";
3096
eval{$builder->build_query($source)};
3097
like($@, qr/unexpected "}"/, "error : 1");
3098

            
3099
$source = "a {= {}";
3100
eval{$builder->build_query($source)};
3101
like($@, qr/unexpected "{"/, "error : 2");
3102

            
3103
test 'select() wrap option';
3104
$dbi = DBIx::Custom->connect;
3105
eval { $dbi->execute("drop table $table1") };
3106
$dbi->execute($create_table1);
3107
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3108
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3109
$rows = $dbi->select(
3110
    table => $table1,
3111
    column => $key1,
test cleanup
Yuki Kimoto authored on 2011-08-15
3112
    wrap => ["select * from (", ") t where $key1 = 1"]
cleanup test
Yuki Kimoto authored on 2011-08-15
3113
)->all;
3114
is_deeply($rows, [{$key1 => 1}]);
3115

            
3116
eval {
3117
$dbi->select(
3118
    table => $table1,
3119
    column => $key1,
3120
    wrap => 'select * from ('
3121
)
3122
};
3123
like($@, qr/array/);
3124

            
3125
test 'select() sqlfilter option';
3126
$dbi = DBIx::Custom->connect;
3127
eval { $dbi->execute("drop table $table1") };
3128
$dbi->execute($create_table1);
3129
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3130
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3131
$rows = $dbi->select(
3132
    table => $table1,
3133
    column => $key1,
3134
    sqlfilter => sub {
3135
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
3136
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
3137
        return $sql;
3138
    }
3139
)->all;
3140
is_deeply($rows, [{$key1 => 1}]);
3141

            
3142
test 'dbi method from model';
3143
$dbi = MyDBI9->connect;
3144
eval { $dbi->execute("drop table $table1") };
3145
$dbi->execute($create_table1);
3146
$dbi->setup_model;
3147
$model = $dbi->model($table1);
3148
eval{$model->execute("select * from $table1")};
3149
ok(!$@);
3150

            
3151
test 'column table option';
3152
$dbi = MyDBI9->connect;
3153
eval { $dbi->execute("drop table $table1") };
3154
$dbi->execute($create_table1);
3155
eval { $dbi->execute("drop table $table2") };
3156
$dbi->execute($create_table2);
3157
$dbi->setup_model;
3158
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3159
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3160
$model = $dbi->model($table1);
3161
$result = $model->select(
3162
    column => [
3163
        $model->column($table2, {alias => $table2_alias})
3164
    ],
3165
    where => {"$table2_alias.$key3" => 4}
3166
);
3167
is_deeply($result->one, 
3168
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3169

            
3170
$dbi->separator('__');
3171
$result = $model->select(
3172
    column => [
3173
        $model->column($table2, {alias => $table2_alias})
3174
    ],
3175
    where => {"$table2_alias.$key3" => 4}
3176
);
3177
is_deeply($result->one, 
3178
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3179

            
3180
$dbi->separator('-');
3181
$result = $model->select(
3182
    column => [
3183
        $model->column($table2, {alias => $table2_alias})
3184
    ],
3185
    where => {"$table2_alias.$key3" => 4}
3186
);
3187
is_deeply($result->one, 
3188
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3189

            
3190
test 'create_model';
3191
$dbi = DBIx::Custom->connect;
3192
eval { $dbi->execute("drop table $table1") };
3193
eval { $dbi->execute("drop table $table2") };
3194
$dbi->execute($create_table1);
3195
$dbi->execute($create_table2);
3196

            
3197
$dbi->create_model(
3198
    table => $table1,
3199
    join => [
3200
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3201
    ],
3202
    primary_key => [$key1]
3203
);
3204
$model2 = $dbi->create_model(
3205
    table => $table2
3206
);
3207
$dbi->create_model(
3208
    table => $table3,
3209
    filter => [
3210
        $key1 => {in => sub { uc $_[0] }}
3211
    ]
3212
);
3213
$dbi->setup_model;
3214
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3215
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3216
$model = $dbi->model($table1);
3217
$result = $model->select(
3218
    column => [$model->mycolumn, $model->column($table2)],
3219
    where => {"$table1.$key1" => 1}
3220
);
3221
is_deeply($result->one,
3222
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3223
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3224

            
3225
test 'model method';
3226
$dbi = DBIx::Custom->connect;
3227
eval { $dbi->execute("drop table $table2") };
3228
$dbi->execute($create_table2);
3229
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3230
$model = $dbi->create_model(
3231
    table => $table2
3232
);
3233
$model->method(foo => sub { shift->select(@_) });
3234
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
3235

            
3236
test 'update_param';
3237
$dbi = DBIx::Custom->connect;
3238
eval { $dbi->execute("drop table $table1") };
3239
$dbi->execute($create_table1_2);
3240
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3241
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3242

            
3243
$param = {$key2 => 11};
3244
$update_param = $dbi->update_param($param);
3245
$sql = <<"EOS";
3246
update $table1 $update_param
3247
where $key1 = 1
3248
EOS
3249
$dbi->execute($sql, param => $param);
3250
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3251
$rows   = $result->all;
3252
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3253
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3254
                  "basic");
3255

            
3256

            
3257
$dbi = DBIx::Custom->connect;
3258
eval { $dbi->execute("drop table $table1") };
3259
$dbi->execute($create_table1_2);
3260
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3261
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3262

            
3263
$param = {$key2 => 11, $key3 => 33};
3264
$update_param = $dbi->update_param($param);
3265
$sql = <<"EOS";
3266
update $table1 $update_param
3267
where $key1 = 1
3268
EOS
3269
$dbi->execute($sql, param => $param);
3270
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3271
$rows   = $result->all;
3272
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3273
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3274
                  "basic");
3275

            
3276
$dbi = DBIx::Custom->connect;
3277
eval { $dbi->execute("drop table $table1") };
3278
$dbi->execute($create_table1_2);
3279
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3280
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3281

            
3282
$param = {$key2 => 11, $key3 => 33};
3283
$update_param = $dbi->update_param($param, {no_set => 1});
3284
$sql = <<"EOS";
3285
update $table1 set $update_param
3286
where $key1 = 1
3287
EOS
3288
$dbi->execute($sql, param => $param);
3289
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3290
$rows   = $result->all;
3291
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3292
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3293
                  "update param no_set");
3294

            
3295
            
3296
eval { $dbi->update_param({";" => 1}) };
3297
like($@, qr/not safety/);
3298

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3299

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3300
test 'update_param';
3301
$dbi = DBIx::Custom->connect;
3302
eval { $dbi->execute("drop table $table1") };
3303
$dbi->execute($create_table1_2);
3304
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3305
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3306

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3307
$param = {$key2 => 11};
3308
$update_param = $dbi->assign_param($param);
3309
$sql = <<"EOS";
3310
update $table1 set $update_param
3311
where $key1 = 1
3312
EOS
3313
$dbi->execute($sql, param => $param, table => $table1);
3314
$result = $dbi->execute("select * from $table1 order by $key1");
3315
$rows   = $result->all;
3316
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3317
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3318
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3319

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3320
test 'Model class';
3321
$dbi = MyDBI1->connect;
3322
eval { $dbi->execute("drop table $table1") };
3323
$dbi->execute($create_table1);
3324
$model = $dbi->model($table1);
3325
$model->insert({$key1 => 'a', $key2 => 'b'});
3326
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3327
eval { $dbi->execute("drop table $table2") };
3328
$dbi->execute($create_table2);
3329
$model = $dbi->model($table2);
3330
$model->insert({$key1 => 'a'});
3331
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3332
is($dbi->models->{$table1}, $dbi->model($table1));
3333
is($dbi->models->{$table2}, $dbi->model($table2));
3334

            
3335
$dbi = MyDBI4->connect;
3336
eval { $dbi->execute("drop table $table1") };
3337
$dbi->execute($create_table1);
3338
$model = $dbi->model($table1);
3339
$model->insert({$key1 => 'a', $key2 => 'b'});
3340
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3341
eval { $dbi->execute("drop table $table2") };
3342
$dbi->execute($create_table2);
3343
$model = $dbi->model($table2);
3344
$model->insert({$key1 => 'a'});
3345
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3346

            
3347
$dbi = MyDBI5->connect;
3348
eval { $dbi->execute("drop table $table1") };
3349
eval { $dbi->execute("drop table $table2") };
3350
$dbi->execute($create_table1);
3351
$dbi->execute($create_table2);
3352
$model = $dbi->model($table2);
3353
$model->insert({$key1 => 'a'});
3354
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3355
$dbi->insert(table => $table1, param => {$key1 => 1});
3356
$model = $dbi->model($table1);
3357
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3358

            
3359
test 'primary_key';
3360
$dbi = MyDBI1->connect;
3361
$model = $dbi->model($table1);
3362
$model->primary_key([$key1, $key2]);
3363
is_deeply($model->primary_key, [$key1, $key2]);
3364

            
3365
test 'columns';
3366
$dbi = MyDBI1->connect;
3367
$model = $dbi->model($table1);
3368
$model->columns([$key1, $key2]);
3369
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3370

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3371
test 'setup_model';
3372
$dbi = MyDBI1->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3373
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3374
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3375

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3376
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3377
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3378
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3379
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3380
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3381

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3382
test 'each_column';
3383
$dbi = DBIx::Custom->connect;
3384
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3385
eval { $dbi->execute("drop table $table1") };
3386
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3387
eval { $dbi->execute("drop table $table3") };
3388
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3389
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3390

            
3391
$infos = [];
3392
$dbi->each_column(sub {
3393
    my ($self, $table, $column, $cinfo) = @_;
3394
    
3395
    if ($table =~ /^table\d/i) {
3396
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3397
         push @$infos, $info;
3398
    }
3399
});
3400
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3401
is_deeply($infos, 
3402
    [
3403
        [$table1, $key1, $key1],
3404
        [$table1, $key2, $key2],
3405
        [$table2, $key1, $key1],
3406
        [$table2, $key3, $key3]
3407
    ]
3408
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3409
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3410
test 'each_table';
3411
$dbi = DBIx::Custom->connect;
3412
eval { $dbi->execute("drop table $table1") };
3413
eval { $dbi->execute("drop table $table2") };
3414
$dbi->execute($create_table2);
3415
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3416

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3417
$infos = [];
3418
$dbi->each_table(sub {
3419
    my ($self, $table, $table_info) = @_;
3420
    
3421
    if ($table =~ /^table\d/i) {
3422
         my $info = [$table, $table_info->{TABLE_NAME}];
3423
         push @$infos, $info;
3424
    }
3425
});
3426
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3427
is_deeply($infos, 
3428
    [
3429
        [$table1, $table1],
3430
        [$table2, $table2],
3431
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3432
);
3433

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3434
test 'type_rule into';
3435
eval { $dbi->execute("drop table $table1") };
3436
$dbi->execute($create_table1_type);
3437
$dbi = DBIx::Custom->connect;
3438
eval { $dbi->execute("drop table $table1") };
3439
$dbi->execute($create_table1_type);
3440

            
3441
$dbi->type_rule(
3442
    into1 => {
3443
        $date_typename => sub { '2010-' . $_[0] }
3444
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3445
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3446
$dbi->insert({$key1 => '01-01'}, table => $table1);
3447
$result = $dbi->select(table => $table1);
3448
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3449

            
3450
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3451
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3452
$dbi->execute($create_table1_type);
3453
$dbi->type_rule(
3454
    into1 => [
3455
         [$date_typename, $datetime_typename] => sub {
3456
            my $value = shift;
3457
            $value =~ s/02/03/g;
3458
            return $value;
3459
         }
3460
    ]
3461
);
3462
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3463
$result = $dbi->select(table => $table1);
3464
$row = $result->one;
3465
like($row->{$key1}, qr/^2010-01-03/);
3466
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3467

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3468
$dbi = DBIx::Custom->connect;
3469
eval { $dbi->execute("drop table $table1") };
3470
$dbi->execute($create_table1_type);
3471
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3472
$dbi->type_rule(
3473
    into1 => [
3474
        [$date_typename, $datetime_typename] => sub {
3475
            my $value = shift;
3476
            $value =~ s/02/03/g;
3477
            return $value;
3478
        }
3479
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3480
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3481
$result = $dbi->execute(
3482
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3483
    param => {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
3484
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3485
$row = $result->one;
3486
like($row->{$key1}, qr/^2010-01-03/);
3487
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3488

            
3489
$dbi = DBIx::Custom->connect;
3490
eval { $dbi->execute("drop table $table1") };
3491
$dbi->execute($create_table1_type);
3492
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3493
$dbi->type_rule(
3494
    into1 => [
3495
        [$date_typename, $datetime_typename] => sub {
3496
            my $value = shift;
3497
            $value =~ s/02/03/g;
3498
            return $value;
3499
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3500
    ]
3501
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3502
$result = $dbi->execute(
3503
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3504
    param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
3505
    table => $table1
3506
);
3507
$row = $result->one;
3508
like($row->{$key1}, qr/^2010-01-03/);
3509
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3510

            
3511
$dbi = DBIx::Custom->connect;
3512
eval { $dbi->execute("drop table $table1") };
3513
$dbi->execute($create_table1_type);
3514
$dbi->register_filter(convert => sub {
3515
    my $value = shift || '';
3516
    $value =~ s/02/03/;
3517
    return $value;
3518
});
3519
$dbi->type_rule(
3520
    from1 => {
3521
        $date_datatype => 'convert',
3522
    },
3523
    into1 => {
3524
        $date_typename => 'convert',
3525
    }
3526
);
3527
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3528
$result = $dbi->select(table => $table1);
3529
like($result->fetch->[0], qr/^2010-03-03/);
3530

            
3531
test 'type_rule and filter order';
3532
$dbi = DBIx::Custom->connect;
3533
eval { $dbi->execute("drop table $table1") };
3534
$dbi->execute($create_table1_type);
3535
$dbi->type_rule(
3536
    into1 => {
3537
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3538
    },
3539
    into2 => {
3540
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3541
    },
3542
    from1 => {
3543
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3544
    },
3545
    from2 => {
3546
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
3547
    }
3548
);
3549
$dbi->insert({$key1 => '2010-01-03'}, 
3550
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
3551
$result = $dbi->select(table => $table1);
3552
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3553
like($result->fetch_first->[0], qr/^2010-01-09/);
3554

            
3555

            
3556
$dbi = DBIx::Custom->connect;
3557
eval { $dbi->execute("drop table $table1") };
3558
$dbi->execute($create_table1_type);
3559
$dbi->type_rule(
3560
    from1 => {
3561
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3562
    },
3563
    from2 => {
3564
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3565
    },
3566
);
3567
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3568
$result = $dbi->select(table => $table1);
3569
$result->type_rule(
3570
    from1 => {
3571
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3572
    },
3573
    from2 => {
3574
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3575
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3576
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3577
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3578
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3579

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3580
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
3581
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
3582
eval { $dbi->execute("drop table $table1") };
3583
$dbi->execute($create_table1_type);
3584
$dbi->type_rule(
3585
    from1 => {
3586
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3587
    },
3588
    into1 => {
3589
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3590
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3591
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3592
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3593
$result = $dbi->select(table => $table1, type_rule_off => 1);
3594
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3595

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3596
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3597
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3598
$dbi->execute($create_table1_type);
3599
$dbi->type_rule(
3600
    from1 => {
3601
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3602
    },
3603
    into1 => {
3604
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3605
    }
3606
);
3607
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3608
$result = $dbi->select(table => $table1, type_rule_off => 1);
3609
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3610

            
3611
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3612
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3613
$dbi->execute($create_table1_type);
3614
$dbi->type_rule(
3615
    from1 => {
3616
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3617
    },
3618
    into1 => {
3619
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3620
    }
3621
);
3622
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3623
$result = $dbi->select(table => $table1);
3624
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3625

            
3626
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3627
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3628
$dbi->execute($create_table1_type);
3629
$dbi->type_rule(
3630
    from1 => {
3631
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3632
    },
3633
    into1 => {
3634
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3635
    }
3636
);
3637
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3638
$result = $dbi->select(table => $table1);
3639
like($result->fetch->[0], qr/2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3640

            
3641
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3642
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3643
$dbi->execute($create_table1_type);
3644
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
3645
$dbi->type_rule(
3646
    into1 => {
3647
        $date_typename => 'ppp'
3648
    }
3649
);
3650
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3651
$result = $dbi->select(table => $table1);
3652
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3653

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3654
eval{$dbi->type_rule(
3655
    into1 => {
3656
        $date_typename => 'pp'
3657
    }
3658
)};
3659
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3660

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3661
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3662
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3663
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3664
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3665
    $dbi->type_rule(
3666
        from1 => {
3667
            Date => sub { $_[0] * 2 },
3668
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3669
    );
3670
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3671
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3672

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3673
eval {
3674
    $dbi->type_rule(
3675
        into1 => {
3676
            Date => sub { $_[0] * 2 },
3677
        }
3678
    );
3679
};
3680
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3681

            
3682
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3683
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3684
$dbi->execute($create_table1_type);
3685
$dbi->type_rule(
3686
    from1 => {
3687
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3688
    },
3689
    into1 => {
3690
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3691
    }
3692
);
3693
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3694
$result = $dbi->select(table => $table1);
3695
$result->type_rule_off;
3696
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3697

            
3698
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3699
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3700
$dbi->execute($create_table1_type);
3701
$dbi->type_rule(
3702
    from1 => {
3703
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3704
        $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3705
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3706
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3707
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3708
$result = $dbi->select(table => $table1);
3709
$result->type_rule(
3710
    from1 => {
3711
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3712
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3713
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3714
$row = $result->one;
3715
like($row->{$key1}, qr/^2010-01-05/);
3716
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3717

            
3718
$result = $dbi->select(table => $table1);
3719
$result->type_rule(
3720
    from1 => {
3721
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3722
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3723
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3724
$row = $result->one;
3725
like($row->{$key1}, qr/2010-01-05/);
3726
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3727

            
3728
$result = $dbi->select(table => $table1);
3729
$result->type_rule(
3730
    from1 => {
3731
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3732
    }
3733
);
3734
$row = $result->one;
3735
like($row->{$key1}, qr/2010-01-05/);
3736
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3737

            
3738
$result = $dbi->select(table => $table1);
3739
$result->type_rule(
3740
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
3741
);
3742
$row = $result->one;
3743
like($row->{$key1}, qr/2010-01-05/);
3744
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3745

            
3746
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
3747
$result = $dbi->select(table => $table1);
3748
$result->type_rule(
3749
    from1 => [$date_datatype => 'five']
3750
);
3751
$row = $result->one;
3752
like($row->{$key1}, qr/^2010-01-05/);
3753
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3754

            
3755
$result = $dbi->select(table => $table1);
3756
$result->type_rule(
3757
    from1 => [$date_datatype => undef]
3758
);
3759
$row = $result->one;
3760
like($row->{$key1}, qr/^2010-01-03/);
3761
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3762

            
3763
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3764
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3765
$dbi->execute($create_table1_type);
3766
$dbi->type_rule(
3767
    from1 => {
3768
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3769
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3770
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3771
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3772
$result = $dbi->select(table => $table1);
3773
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3774
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3775

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3776
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3777
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3778
$dbi->execute($create_table1_type);
3779
$dbi->type_rule(
3780
    from1 => {
3781
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3782
    },
3783
);
3784
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3785
$result = $dbi->select(table => $table1);
3786
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3787
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3788

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3789
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3790
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3791
$dbi->execute($create_table1_type);
3792
$dbi->type_rule(
3793
    into1 => {
3794
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3795
    },
3796
    into2 => {
3797
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3798
    },
3799
    from1 => {
3800
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3801
    },
3802
    from2 => {
3803
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
3804
    }
3805
);
3806
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3807
$result = $dbi->select(table => $table1);
3808
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/);
3809
$result = $dbi->select(table => $table1);
3810
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3811

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3812
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3813
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3814
$dbi->execute($create_table1_type);
3815
$dbi->type_rule(
3816
    into1 => {
3817
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3818
    },
3819
    into2 => {
3820
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3821
    },
3822
    from1 => {
3823
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
3824
    },
3825
    from2 => {
3826
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3827
    }
3828
);
3829
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
3830
$result = $dbi->select(table => $table1);
3831
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/);
3832
$result = $dbi->select(table => $table1);
3833
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3834

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3835
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3836
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3837
$dbi->execute($create_table1_type);
3838
$dbi->type_rule(
3839
    into1 => {
3840
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3841
    },
3842
    into2 => {
3843
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3844
    },
3845
    from1 => {
3846
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3847
    },
3848
    from2 => {
3849
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
3850
    }
3851
);
3852
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
3853
$result = $dbi->select(table => $table1);
3854
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
3855
$result = $dbi->select(table => $table1);
3856
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3857

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3858

            
cleanup test
Yuki Kimoto authored on 2011-08-08
3859
1;