DBIx-Custom / t / common.t /
Newer Older
3847 lines | 126.565kb
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;
6
use lib "$FindBin::Bin/common";
cleanup
Yuki Kimoto authored on 2011-08-13
7
use Scalar::Util 'isweak';
cleanup test
Yuki Kimoto authored on 2011-08-10
8

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

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

            
15
plan 'no_plan';
16

            
test cleanup
Yuki Kimoto authored on 2011-08-10
17
use MyDBI1;
18
{
19
    package MyDBI4;
20

            
21
    use strict;
22
    use warnings;
23

            
24
    use base 'DBIx::Custom';
25

            
26
    sub connect {
27
        my $self = shift->SUPER::connect(@_);
28
        
29
        $self->include_model(
30
            MyModel2 => [
test cleanup
Yuki Kimoto authored on 2011-08-10
31
                'table1',
cleanup
Yuki Kimoto authored on 2011-08-10
32
                {class => 'table2', name => 'table2'}
test cleanup
Yuki Kimoto authored on 2011-08-10
33
            ]
34
        );
35
    }
36

            
37
    package MyModel2::Base1;
38

            
39
    use strict;
40
    use warnings;
41

            
42
    use base 'DBIx::Custom::Model';
43

            
test cleanup
Yuki Kimoto authored on 2011-08-10
44
    package MyModel2::table1;
test cleanup
Yuki Kimoto authored on 2011-08-10
45

            
46
    use strict;
47
    use warnings;
48

            
49
    use base 'MyModel2::Base1';
50

            
51
    sub insert {
52
        my ($self, $param) = @_;
53
        
54
        return $self->SUPER::insert(param => $param);
55
    }
56

            
57
    sub list { shift->select; }
58

            
test cleanup
Yuki Kimoto authored on 2011-08-10
59
    package MyModel2::table2;
test cleanup
Yuki Kimoto authored on 2011-08-10
60

            
61
    use strict;
62
    use warnings;
63

            
64
    use base 'MyModel2::Base1';
65

            
66
    sub insert {
67
        my ($self, $param) = @_;
68
        
69
        return $self->SUPER::insert(param => $param);
70
    }
71

            
72
    sub list { shift->select; }
73
}
74
{
75
     package MyDBI5;
76

            
77
    use strict;
78
    use warnings;
79

            
80
    use base 'DBIx::Custom';
81

            
82
    sub connect {
83
        my $self = shift->SUPER::connect(@_);
84
        
85
        $self->include_model('MyModel4');
86
    }
87
}
88
{
89
    package MyDBI6;
90
    
91
    use base 'DBIx::Custom';
92
    
93
    sub connect {
94
        my $self = shift->SUPER::connect(@_);
95
        
96
        $self->include_model('MyModel5');
97
        
98
        return $self;
99
    }
100
}
101
{
102
    package MyDBI7;
103
    
104
    use base 'DBIx::Custom';
105
    
106
    sub connect {
107
        my $self = shift->SUPER::connect(@_);
108
        
109
        $self->include_model('MyModel6');
110
        
111
        
112
        return $self;
113
    }
114
}
115
{
116
    package MyDBI8;
117
    
118
    use base 'DBIx::Custom';
119
    
120
    sub connect {
121
        my $self = shift->SUPER::connect(@_);
122
        
123
        $self->include_model('MyModel7');
124
        
125
        return $self;
126
    }
127
}
128

            
129
{
130
    package MyDBI9;
131
    
132
    use base 'DBIx::Custom';
133
    
134
    sub connect {
135
        my $self = shift->SUPER::connect(@_);
136
        
cleanup test
Yuki Kimoto authored on 2011-08-10
137
        $self->include_model('MyModel8');
test cleanup
Yuki Kimoto authored on 2011-08-10
138
        
139
        return $self;
140
    }
141
}
142

            
cleanup test
Yuki Kimoto authored on 2011-08-08
143
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
144
sub test { print "# $_[0]\n" }
145

            
added common test executing ...
Yuki Kimoto authored on 2011-08-07
146
# Constant
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
147
my $table1 = $dbi->table1;
148
my $table2 = $dbi->table2;
149
my $table2_alias = $dbi->table2_alias;
150
my $table3 = $dbi->table3;
151
my $key1 = $dbi->key1;
152
my $key2 = $dbi->key2;
153
my $key3 = $dbi->key3;
154
my $key4 = $dbi->key4;
155
my $key5 = $dbi->key5;
156
my $key6 = $dbi->key6;
157
my $key7 = $dbi->key7;
158
my $key8 = $dbi->key8;
159
my $key9 = $dbi->key9;
160
my $key10 = $dbi->key10;
added common test executing ...
Yuki Kimoto authored on 2011-08-07
161
my $create_table1 = $dbi->create_table1;
cleanup test
Yuki Kimoto authored on 2011-08-08
162
my $create_table1_2 = $dbi->create_table1_2;
test cleanup
Yuki Kimoto authored on 2011-08-10
163
my $create_table1_type = $dbi->create_table1_type;
test cleanup
Yuki Kimoto authored on 2011-08-10
164
my $create_table1_highperformance = $dbi->create_table1_highperformance;
test cleanup
Yuki Kimoto authored on 2011-08-10
165
my $create_table2 = $dbi->create_table2;
test cleanup
Yuki Kimoto authored on 2011-08-10
166
my $create_table2_2 = $dbi->create_table2_2;
167
my $create_table3 = $dbi->create_table3;
test cleanup
Yuki Kimoto authored on 2011-08-10
168
my $create_table_reserved = $dbi->create_table_reserved;
cleanup test
Yuki Kimoto authored on 2011-08-10
169
my $q = substr($dbi->quote, 0, 1);
170
my $p = substr($dbi->quote, 1, 1) || $q;
test cleanup
Yuki Kimoto authored on 2011-08-10
171
my $date_typename = $dbi->date_typename;
172
my $datetime_typename = $dbi->datetime_typename;
173
my $date_datatype = $dbi->date_datatype;
174
my $datetime_datatype = $dbi->datetime_datatype;
added common test executing ...
Yuki Kimoto authored on 2011-08-07
175

            
cleanup test
Yuki Kimoto authored on 2011-08-08
176
# Variables
177
my $builder;
178
my $datas;
179
my $sth;
180
my $source;
181
my @sources;
182
my $select_source;
183
my $insert_source;
184
my $update_source;
185
my $param;
186
my $params;
187
my $sql;
188
my $result;
189
my $row;
190
my @rows;
191
my $rows;
192
my $query;
193
my @queries;
194
my $select_query;
195
my $insert_query;
196
my $update_query;
197
my $ret_val;
198
my $infos;
added common test executing ...
Yuki Kimoto authored on 2011-08-07
199
my $model;
cleanup test
Yuki Kimoto authored on 2011-08-08
200
my $model2;
201
my $where;
202
my $update_param;
203
my $insert_param;
204
my $join;
cleanup test
Yuki Kimoto authored on 2011-08-10
205
my $binary;
added common test executing ...
Yuki Kimoto authored on 2011-08-07
206

            
added SQL Server test
Yuki Kimoto authored on 2011-08-14
207

            
test cleanup
Yuki Kimoto authored on 2011-08-10
208
test 'type_rule into';
test cleanup
Yuki Kimoto authored on 2011-08-15
209
eval { $dbi->execute("drop table $table1") };
210
$dbi->execute($create_table1_type);
test cleanup
Yuki Kimoto authored on 2011-08-10
211
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
212
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
213
$dbi->execute($create_table1_type);
test cleanup
Yuki Kimoto authored on 2011-08-15
214
$dbi->show_tables;
cleanup
Yuki Kimoto authored on 2011-08-15
215

            
test cleanup
Yuki Kimoto authored on 2011-08-15
216
$DB::single = 1;
cleanup
Yuki Kimoto authored on 2011-08-15
217

            
test cleanup
Yuki Kimoto authored on 2011-08-15
218
__END__
cleanup
Yuki Kimoto authored on 2011-08-15
219

            
test cleanup
Yuki Kimoto authored on 2011-08-10
220
$dbi->type_rule(
221
    into1 => {
222
        $date_typename => sub { '2010-' . $_[0] }
223
    }
224
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
225
$dbi->insert({$key1 => '01-01'}, table => $table1);
226
$result = $dbi->select(table => $table1);
227
like($result->one->{$key1}, qr/^2010-01-01/);
test cleanup
Yuki Kimoto authored on 2011-08-10
228

            
229
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
230
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
231
$dbi->execute($create_table1_type);
232
$dbi->type_rule(
233
    into1 => [
234
         [$date_typename, $datetime_typename] => sub {
235
            my $value = shift;
236
            $value =~ s/02/03/g;
237
            return $value;
238
         }
239
    ]
240
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
241
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
242
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
243
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
244
like($row->{$key1}, qr/^2010-01-03/);
245
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
test cleanup
Yuki Kimoto authored on 2011-08-10
246

            
247
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
248
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
249
$dbi->execute($create_table1_type);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
250
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
251
$dbi->type_rule(
252
    into1 => [
253
        [$date_typename, $datetime_typename] => sub {
254
            my $value = shift;
255
            $value =~ s/02/03/g;
256
            return $value;
257
        }
258
    ]
259
);
260
$result = $dbi->execute(
cleanup test
Yuki Kimoto authored on 2011-08-15
261
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
262
    param => {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
test cleanup
Yuki Kimoto authored on 2011-08-10
263
);
264
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
265
like($row->{$key1}, qr/^2010-01-03/);
266
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
test cleanup
Yuki Kimoto authored on 2011-08-10
267

            
268
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
269
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
270
$dbi->execute($create_table1_type);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
271
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
272
$dbi->type_rule(
273
    into1 => [
274
        [$date_typename, $datetime_typename] => sub {
275
            my $value = shift;
276
            $value =~ s/02/03/g;
277
            return $value;
278
        }
279
    ]
280
);
281
$result = $dbi->execute(
cleanup test
Yuki Kimoto authored on 2011-08-15
282
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
283
    param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
284
    table => $table1
test cleanup
Yuki Kimoto authored on 2011-08-10
285
);
286
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
287
like($row->{$key1}, qr/^2010-01-03/);
288
like($row->{$key2}, qr/2010-01-01 01:01:03/);
test cleanup
Yuki Kimoto authored on 2011-08-10
289

            
290
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
291
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
292
$dbi->execute($create_table1_type);
293
$dbi->register_filter(convert => sub {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
294
    my $value = shift || '';
test cleanup
Yuki Kimoto authored on 2011-08-10
295
    $value =~ s/02/03/;
296
    return $value;
297
});
298
$dbi->type_rule(
299
    from1 => {
300
        $date_datatype => 'convert',
301
    },
302
    into1 => {
303
        $date_typename => 'convert',
304
    }
305
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
306
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
307
$result = $dbi->select(table => $table1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
308
like($result->fetch->[0], qr/^2010-03-03/);
test cleanup
Yuki Kimoto authored on 2011-08-10
309

            
test cleanup
Yuki Kimoto authored on 2011-08-10
310
test 'type_rule and filter order';
311
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
312
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
313
$dbi->execute($create_table1_type);
314
$dbi->type_rule(
315
    into1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
316
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
317
    },
318
    into2 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
319
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
320
    },
321
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
322
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
323
    },
324
    from2 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
325
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
326
    }
327
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
328
$dbi->insert({$key1 => '2010-01-03'}, 
329
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
330
$result = $dbi->select(table => $table1);
331
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
332
like($result->fetch_first->[0], qr/^2010-01-09/);
test cleanup
Yuki Kimoto authored on 2011-08-10
333

            
334

            
test cleanup
Yuki Kimoto authored on 2011-08-10
335
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
336
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
337
$dbi->execute($create_table1_type);
338
$dbi->type_rule(
339
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
340
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
341
    },
342
    from2 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
343
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
344
    },
345
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
346
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
347
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
348
$result->type_rule(
349
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
350
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
351
    },
352
    from2 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
353
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
354
    }
355
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
356
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
357
like($result->fetch_first->[0], qr/^2010-01-09/);
test cleanup
Yuki Kimoto authored on 2011-08-10
358

            
test cleanup
Yuki Kimoto authored on 2011-08-10
359
test 'type_rule_off';
360
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
361
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
362
$dbi->execute($create_table1_type);
363
$dbi->type_rule(
364
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
365
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
366
    },
367
    into1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
368
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
369
    }
370
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
371
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
372
$result = $dbi->select(table => $table1, type_rule_off => 1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
373
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
test cleanup
Yuki Kimoto authored on 2011-08-10
374

            
test cleanup
Yuki Kimoto authored on 2011-08-10
375
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
376
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
377
$dbi->execute($create_table1_type);
378
$dbi->type_rule(
379
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
380
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
381
    },
382
    into1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
383
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
384
    }
385
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
386
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
387
$result = $dbi->select(table => $table1, type_rule_off => 1);
388
like($result->one->{$key1}, qr/^2010-01-04/);
test cleanup
Yuki Kimoto authored on 2011-08-10
389

            
test cleanup
Yuki Kimoto authored on 2011-08-10
390
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
391
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
392
$dbi->execute($create_table1_type);
393
$dbi->type_rule(
394
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
395
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
396
    },
397
    into1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
398
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
399
    }
400
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
401
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
402
$result = $dbi->select(table => $table1);
403
like($result->one->{$key1}, qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
404

            
test cleanup
Yuki Kimoto authored on 2011-08-10
405
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
406
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
407
$dbi->execute($create_table1_type);
408
$dbi->type_rule(
409
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
410
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
411
    },
412
    into1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
413
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
414
    }
415
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
416
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
417
$result = $dbi->select(table => $table1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
418
like($result->fetch->[0], qr/2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
419

            
test cleanup
Yuki Kimoto authored on 2011-08-10
420
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
421
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
422
$dbi->execute($create_table1_type);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
423
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
test cleanup
Yuki Kimoto authored on 2011-08-10
424
$dbi->type_rule(
425
    into1 => {
426
        $date_typename => 'ppp'
427
    }
428
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
429
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
430
$result = $dbi->select(table => $table1);
431
like($result->one->{$key1}, qr/^2010-01-04/);
test cleanup
Yuki Kimoto authored on 2011-08-10
432

            
test cleanup
Yuki Kimoto authored on 2011-08-10
433
eval{$dbi->type_rule(
434
    into1 => {
435
        $date_typename => 'pp'
436
    }
437
)};
438
like($@, qr/not registered/);
test cleanup
Yuki Kimoto authored on 2011-08-10
439

            
test cleanup
Yuki Kimoto authored on 2011-08-10
440
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
441
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
442
$dbi->execute($create_table1_type);
443
eval {
444
    $dbi->type_rule(
445
        from1 => {
446
            Date => sub { $_[0] * 2 },
447
        }
448
    );
449
};
450
like($@, qr/lower/);
test cleanup
Yuki Kimoto authored on 2011-08-10
451

            
test cleanup
Yuki Kimoto authored on 2011-08-10
452
eval {
453
    $dbi->type_rule(
454
        into1 => {
455
            Date => sub { $_[0] * 2 },
456
        }
457
    );
458
};
459
like($@, qr/lower/);
test cleanup
Yuki Kimoto authored on 2011-08-10
460

            
test cleanup
Yuki Kimoto authored on 2011-08-10
461
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
462
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
463
$dbi->execute($create_table1_type);
464
$dbi->type_rule(
465
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
466
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
467
    },
468
    into1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
469
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
470
    }
471
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
472
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
473
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
474
$result->type_rule_off;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
475
like($result->one->{$key1}, qr/^2010-01-04/);
test cleanup
Yuki Kimoto authored on 2011-08-10
476

            
test cleanup
Yuki Kimoto authored on 2011-08-10
477
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
478
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
479
$dbi->execute($create_table1_type);
480
$dbi->type_rule(
481
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
482
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
483
        $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
484
    },
485
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
486
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
487
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
488
$result->type_rule(
489
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
490
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
491
    }
492
);
493
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
494
like($row->{$key1}, qr/^2010-01-05/);
495
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
test cleanup
Yuki Kimoto authored on 2011-08-10
496

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
497
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
498
$result->type_rule(
499
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
500
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
501
    }
502
);
503
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
504
like($row->{$key1}, qr/2010-01-05/);
505
like($row->{$key2}, qr/2010-01-01 01:01:03/);
test cleanup
Yuki Kimoto authored on 2011-08-10
506

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
507
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
508
$result->type_rule(
509
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
510
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
511
    }
512
);
513
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
514
like($row->{$key1}, qr/2010-01-05/);
515
like($row->{$key2}, qr/2010-01-01 01:01:03/);
test cleanup
Yuki Kimoto authored on 2011-08-10
516

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
517
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
518
$result->type_rule(
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
519
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
test cleanup
Yuki Kimoto authored on 2011-08-10
520
);
521
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
522
like($row->{$key1}, qr/2010-01-05/);
523
like($row->{$key2}, qr/2010-01-01 01:01:03/);
test cleanup
Yuki Kimoto authored on 2011-08-10
524

            
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
525
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
526
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
527
$result->type_rule(
528
    from1 => [$date_datatype => 'five']
529
);
530
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
531
like($row->{$key1}, qr/^2010-01-05/);
532
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
test cleanup
Yuki Kimoto authored on 2011-08-10
533

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
534
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
535
$result->type_rule(
536
    from1 => [$date_datatype => undef]
537
);
538
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
539
like($row->{$key1}, qr/^2010-01-03/);
540
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
test cleanup
Yuki Kimoto authored on 2011-08-10
541

            
test cleanup
Yuki Kimoto authored on 2011-08-10
542
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
543
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
544
$dbi->execute($create_table1_type);
545
$dbi->type_rule(
546
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
547
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
test cleanup
Yuki Kimoto authored on 2011-08-10
548
    },
549
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
550
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
551
$result = $dbi->select(table => $table1);
552
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
553
like($result->one->{$key1}, qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
554

            
test cleanup
Yuki Kimoto authored on 2011-08-10
555
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
556
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
557
$dbi->execute($create_table1_type);
558
$dbi->type_rule(
559
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
560
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
561
    },
562
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
563
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
564
$result = $dbi->select(table => $table1);
565
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
566
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
567

            
test cleanup
Yuki Kimoto authored on 2011-08-10
568
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
569
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
570
$dbi->execute($create_table1_type);
571
$dbi->type_rule(
572
    into1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
573
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
574
    },
575
    into2 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
576
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
577
    },
578
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
579
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
580
    },
581
    from2 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
582
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
583
    }
584
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
585
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
586
$result = $dbi->select(table => $table1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
587
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
588
$result = $dbi->select(table => $table1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
589
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
590

            
test cleanup
Yuki Kimoto authored on 2011-08-10
591
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
592
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
593
$dbi->execute($create_table1_type);
594
$dbi->type_rule(
595
    into1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
596
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
597
    },
598
    into2 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
599
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
600
    },
601
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
602
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
603
    },
604
    from2 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
605
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
606
    }
607
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
608
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
609
$result = $dbi->select(table => $table1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
610
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
611
$result = $dbi->select(table => $table1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
612
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
613

            
test cleanup
Yuki Kimoto authored on 2011-08-10
614
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
615
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
616
$dbi->execute($create_table1_type);
617
$dbi->type_rule(
618
    into1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
619
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
620
    },
621
    into2 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
622
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
623
    },
624
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
625
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
626
    },
627
    from2 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
628
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
629
    }
630
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
631
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
632
$result = $dbi->select(table => $table1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
633
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
634
$result = $dbi->select(table => $table1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
635
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
636

            
637

            
added common test executing ...
Yuki Kimoto authored on 2011-08-07
638

            
639
# Create table
test cleanup
Yuki Kimoto authored on 2011-08-10
640
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
641
eval { $dbi->execute("drop table $table1") };
added common test executing ...
Yuki Kimoto authored on 2011-08-07
642
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
643
$model = $dbi->create_model(table => $table1);
644
$model->insert({$key1 => 1, $key2 => 2});
645
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]);
added common test executing ...
Yuki Kimoto authored on 2011-08-07
646

            
cleanup test
Yuki Kimoto authored on 2011-08-08
647
test 'DBIx::Custom::Result test';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
648
$dbi->delete_all(table => $table1);
649
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
650
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
651
$source = "select $key1, $key2 from $table1";
cleanup test
Yuki Kimoto authored on 2011-08-08
652
$query = $dbi->create_query($source);
653
$result = $dbi->execute($query);
654

            
655
@rows = ();
656
while (my $row = $result->fetch) {
657
    push @rows, [@$row];
658
}
659
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
660

            
661
$result = $dbi->execute($query);
662
@rows = ();
663
while (my $row = $result->fetch_hash) {
664
    push @rows, {%$row};
665
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
666
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
cleanup test
Yuki Kimoto authored on 2011-08-08
667

            
668
$result = $dbi->execute($query);
669
$rows = $result->fetch_all;
670
is_deeply($rows, [[1, 2], [3, 4]], "fetch_all");
671

            
672
$result = $dbi->execute($query);
673
$rows = $result->fetch_hash_all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
674
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "all");
cleanup test
Yuki Kimoto authored on 2011-08-08
675

            
676
test 'Insert query return value';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
677
$source = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
678
$query = $dbi->execute($source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
679
$ret_val = $dbi->execute($query, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-08
680
ok($ret_val);
681

            
682
test 'Direct query';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
683
$dbi->delete_all(table => $table1);
684
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
685
$dbi->execute($insert_source, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
686
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-08
687
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
688
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
689

            
690
test 'Filter basic';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
691
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-08
692
$dbi->register_filter(twice       => sub { $_[0] * 2}, 
693
                    three_times => sub { $_[0] * 3});
694

            
cleanup test
Yuki Kimoto authored on 2011-08-15
695
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
696
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
697
$insert_query->filter({$key1 => 'twice'});
698
$dbi->execute($insert_query, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
699
$result = $dbi->execute("select * from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
700
$rows = $result->filter({$key2 => 'three_times'})->all;
701
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
702

            
703
test 'Filter in';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
704
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
705
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
706
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
707
$dbi->execute($insert_query, param => {$key1 => 2, $key2 => 4});
708
$select_source = "select * from $table1 where {in $table1.$key1 2} and {in $table1.$key2 2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
709
$select_query = $dbi->execute($select_source,{}, query => 1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
710
$select_query->filter({"$table1.$key1" => 'twice'});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
711
$result = $dbi->execute($select_query, param => {"$table1.$key1" => [1,5], "$table1.$key2" => [2,4]});
cleanup test
Yuki Kimoto authored on 2011-08-08
712
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
713
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
714

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
795
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
796
$result = $dbi->execute(
797
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
798
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
799
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
cleanup test
Yuki Kimoto authored on 2011-08-08
800
);
801
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
802
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
803

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
804
$dbi->execute("drop table $table1");
cleanup test
Yuki Kimoto authored on 2011-08-08
805
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
806
$dbi->insert(table => $table1, param => {$key1 => '2011-10-14 12:19:18', $key2 => 2});
807
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
808
$result = $dbi->execute(
809
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
810
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
811
);
812

            
813
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
814
like($rows->[0]->{$key1}, qr/2011-10-14 12:19:18/);
815
is($rows->[0]->{$key2}, 2);
cleanup test
Yuki Kimoto authored on 2011-08-08
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 => 'a:b c:d', $key2 => 2});
819
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
820
$result = $dbi->execute(
821
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
822
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
823
);
824
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
825
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
826

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
834
test 'insert';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
835
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
836
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
837
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
838
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
839
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
840
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
841
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
842

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
843
$dbi->execute("delete from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
844
$dbi->register_filter(
845
    twice       => sub { $_[0] * 2 },
846
    three_times => sub { $_[0] * 3 }
847
);
848
$dbi->default_bind_filter('twice');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
849
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => 'three_times'});
cleanup test
Yuki Kimoto authored on 2011-08-15
850
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
851
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
852
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-10
853
$dbi->default_bind_filter(undef);
854

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
855
$dbi->execute("drop table $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
856
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
857
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, append => '   ');
858
$rows = $dbi->select(table => $table1)->all;
859
is_deeply($rows, [{$key1 => 1, $key2 => 2}], 'insert append');
cleanup test
Yuki Kimoto authored on 2011-08-10
860

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

            
864
eval{$dbi->insert(table => 'table', param => {';' => 1})};
865
like($@, qr/safety/);
866

            
cleanup test
Yuki Kimoto authored on 2011-08-10
867
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
868
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
869
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
870
$dbi->insert(table => 'table', param => {select => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
871
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
872
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
873
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
cleanup test
Yuki Kimoto authored on 2011-08-10
874

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
875
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
876
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
877
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
878
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
879
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
880
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
881
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
882

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
891
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
892
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
893
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
894
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
895
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
896
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
897
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
898
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
899
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
900
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
901
                  "basic");
902
                  
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
903
$dbi->execute("delete from $table1");
904
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
905
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
906
$dbi->update(table => $table1, param => {$key2 => 12}, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
907
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
908
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
909
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
910
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
911
                  "update key same as search key");
912

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
920
$dbi->execute("delete from $table1");
921
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
922
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
923
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
924
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1},
925
              filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
926
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
927
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
928
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
929
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
930
                  "filter");
931

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
940
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
941
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
942
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
943
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
944
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
945
$where->param({$key1 => 1, $key2 => 2});
946
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
947
$result = $dbi->select(table => $table1);
948
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
949

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
950
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
951
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
952
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
953
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
954
    table => $table1,
955
    param => {$key1 => 3},
test cleanup
Yuki Kimoto authored on 2011-08-10
956
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
957
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
958
        {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
959
    ]
960
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
961
$result = $dbi->select(table => $table1);
962
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
963

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
964
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
965
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
966
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
967
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
968
$where->clause(['and', "$key2 = :$key2"]);
969
$where->param({$key2 => 2});
970
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
971
$result = $dbi->select(table => $table1);
972
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
973

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
980
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
981
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
982
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
983
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
984
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
985
$dbi->insert(table => 'table', param => {select => 1});
986
$dbi->update(table => 'table', where => {select => 1}, param => {update => 2});
987
$result = $dbi->execute("select * from ${q}table$p");
988
$rows   = $result->all;
989
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
990

            
991
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
992
like($@, qr/safety/);
993

            
994
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
995
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
996
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
997
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
998
$dbi->insert(table => 'table', param => {select => 1});
999
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
1000
$result = $dbi->execute("select * from ${q}table$p");
1001
$rows   = $result->all;
1002
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
1003

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1004
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1005
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1006
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
1007
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
1008
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1009
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1010
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1011
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
1012
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
1013
                  "basic");
1014

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1015
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1016
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1017
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
1018
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
1019
$dbi->update(table => $table1, param => {$key2 => \"'11'"}, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1020
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1021
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1022
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
1023
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
1024
                  "basic");
1025

            
1026
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1027
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1028
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1029
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
1030
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
1031
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1032
$dbi->update_all(table => $table1, param => {$key2 => 10}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1033
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1034
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1035
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
1036
                  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
1037
                  "filter");
1038

            
1039

            
1040
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1041
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1042
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1043
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1044
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1045
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1046
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1047
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1048
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1049

            
cleanup test
Yuki Kimoto authored on 2011-08-15
1050
$dbi->execute("delete from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1051
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1052
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1053
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1054
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1055
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1056
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1057
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1058

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1061
$dbi->delete_all(table => $table1);
1062
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1063
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1064
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
1065
$rows = $dbi->select(table => $table1)->all;
1066
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1067

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1071
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1072
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1073
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1074
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1075
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1076
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1077
$where->param({ke1 => 1, $key2 => 2});
1078
$dbi->delete(table => $table1, where => $where);
1079
$result = $dbi->select(table => $table1);
1080
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1081

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1082
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1083
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1084
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1085
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1086
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1087
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1088
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1089
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
1090
        {ke1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
1091
    ]
1092
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1093
$result = $dbi->select(table => $table1);
1094
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1095

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1096
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1097
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1098
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1099
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
1100
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1101
$rows   = $result->all;
1102
is_deeply($rows, [], "basic");
1103

            
1104
test 'delete error';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1105
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1106
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1107
eval{$dbi->delete(table => $table1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1108
like($@, qr/"where" must be specified/,
1109
         "where key-value pairs not specified");
1110

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1114
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
1115
$dbi = DBIx::Custom->connect;
1116
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1117
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1118
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
1119
$dbi->insert(table => 'table', param => {select => 1});
1120
$dbi->delete(table => 'table', where => {select => 1});
1121
$result = $dbi->execute("select * from ${q}table$p");
1122
$rows   = $result->all;
1123
is_deeply($rows, [], "reserved word");
1124

            
1125
test 'delete_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1126
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1127
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1128
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1129
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1130
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1131
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1132
$rows   = $result->all;
1133
is_deeply($rows, [], "basic");
1134

            
1135

            
1136
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1137
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1138
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1139
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1140
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1141
$rows = $dbi->select(table => $table1)->all;
1142
is_deeply($rows, [{$key1 => 1, $key2 => 2},
1143
                  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
1144

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1159
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1160
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1161
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
test cleanup
Yuki Kimoto authored on 2011-08-10
1162
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1163
    table => [$table1, $table2],
1164
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
1165
    where   => {"$table1.$key2" => 2},
1166
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1167
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1168
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
1169

            
1170
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1171
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1172
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1173
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1174
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1175
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
1176

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

            
1180
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
1181
eval { $dbi->execute("drop table ${q}table$p") };
1182
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1183
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
1184
$dbi->insert(table => 'table', param => {select => 1, update => 2});
1185
$result = $dbi->select(table => 'table', where => {select => 1});
1186
$rows   = $result->all;
1187
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
1188

            
1189
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1190
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1191
$dbi->register_filter(
1192
    twice       => sub { $_[0] * 2 },
1193
    three_times => sub { $_[0] * 3 }
1194
);
1195
$dbi->default_fetch_filter('twice');
1196
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1197
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1198
$result = $dbi->select(table => $table1);
1199
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1200
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1201
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1202

            
1203
test 'filters';
1204
$dbi = DBIx::Custom->new;
1205

            
1206
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
1207
   'あ', "decode_utf8");
1208

            
1209
is($dbi->filters->{encode_utf8}->('あ'),
1210
   encode_utf8('あ'), "encode_utf8");
1211

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1212
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1213
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1214
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1215
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1216
$dbi->begin_work;
1217
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1218
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1219
$dbi->rollback;
1220
$dbi->dbh->{AutoCommit} = 1;
1221

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

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

            
1226
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1227
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1228
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1229
$dbi->begin_work;
1230
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1231
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1232
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1233
$dbi->commit;
1234
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1235
$result = $dbi->select(table => $table1);
1236
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1237
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1238

            
1239
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1240
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1241
$dbi->execute($create_table1);
1242
{
1243
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1244
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1245
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1246
    like($@, qr/\.t /, "fail : not verbose");
1247
}
1248
{
1249
    local $Carp::Verbose = 1;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1250
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1251
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1252
}
1253

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

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

            
1262
{
1263
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1264
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1265
    like($@, qr/\Q.t /, "caller spec : not vebose");
1266
}
1267
{
1268
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1269
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1270
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1271
}
1272

            
1273

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1274
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1275
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1276
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1277
$dbi->execute($create_table1);
1278

            
1279
$dbi->begin_work;
1280

            
1281
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1282
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1283
    die "Error";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1284
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1285
};
1286

            
1287
$dbi->rollback if $@;
1288

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

            
1293
$dbi->begin_work;
1294

            
1295
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1296
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1297
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1298
};
1299

            
1300
$dbi->commit unless $@;
1301

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

            
1306
$dbi->dbh->{AutoCommit} = 0;
1307
eval{ $dbi->begin_work };
1308
ok($@, "exception");
1309
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1310

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1311
test 'cache';
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->cache(1);
1314
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1315
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1316
$dbi->execute($source, {}, query => 1);
1317
is_deeply($dbi->{_cached}->{$source}, 
cleanup test
Yuki Kimoto authored on 2011-08-15
1318
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1319

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1320
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1321
$dbi->execute($create_table1);
1322
$dbi->{_cached} = {};
1323
$dbi->cache(0);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1324
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1325
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1326

            
1327
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1328
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1329
$dbi->execute($create_table1);
1330
{
1331
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1332
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1333
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1334
    like($@, qr/\.t /, "fail : not verbose");
1335
}
1336
{
1337
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1338
    eval{$dbi->execute('select * frm $table1')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1339
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1340
}
1341

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

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

            
1350
{
1351
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1352
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1353
    like($@, qr/\Q.t /, "caller spec : not vebose");
1354
}
1355
{
1356
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1357
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1358
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1359
}
1360

            
1361
test 'method';
1362
$dbi->method(
1363
    one => sub { 1 }
1364
);
1365
$dbi->method(
1366
    two => sub { 2 }
1367
);
1368
$dbi->method({
1369
    twice => sub {
1370
        my $self = shift;
1371
        return $_[0] * 2;
1372
    }
1373
});
1374

            
1375
is($dbi->one, 1, "first");
1376
is($dbi->two, 2, "second");
1377
is($dbi->twice(5), 10 , "second");
1378

            
1379
eval {$dbi->XXXXXX};
1380
ok($@, "not exists");
1381

            
1382
test 'out filter';
1383
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1384
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1385
$dbi->execute($create_table1);
1386
$dbi->register_filter(twice => sub { $_[0] * 2 });
1387
$dbi->register_filter(three_times => sub { $_[0] * 3});
1388
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1389
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1390
              $key2 => {out => 'three_times', in => 'twice'});
1391
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1392
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1393
$row   = $result->fetch_hash_first;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1394
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1395
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1396
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1397
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1398

            
1399
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1400
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1401
$dbi->execute($create_table1);
1402
$dbi->register_filter(twice => sub { $_[0] * 2 });
1403
$dbi->register_filter(three_times => sub { $_[0] * 3});
1404
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1405
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1406
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1407
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1408
    $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1409
); 
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1410
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1411
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1412
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1413
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1414

            
1415
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1416
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1417
$dbi->execute($create_table1);
1418
$dbi->register_filter(twice => sub { $_[0] * 2 });
1419
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1420
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1421
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1422
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => undef});
1423
$dbi->update(table => $table1, param => {$key1 => 2}, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1424
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1425
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1426
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
test cleanup
Yuki Kimoto authored on 2011-08-10
1427

            
1428
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1429
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1430
$dbi->execute($create_table1);
1431
$dbi->register_filter(twice => sub { $_[0] * 2 });
1432
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1433
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1434
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1435
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1=> undef});
1436
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1437
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1438
$rows   = $result->all;
1439
is_deeply($rows, [], "delete");
1440

            
1441
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1442
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1443
$dbi->execute($create_table1);
1444
$dbi->register_filter(twice => sub { $_[0] * 2 });
1445
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1446
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1447
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1448
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
1449
$result = $dbi->select(table => $table1, where => {$key1 => 1});
1450
$result->filter({$key2 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1451
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1452
is_deeply($rows, [{$key1 => 4, $key2 => 4}], "select");
test cleanup
Yuki Kimoto authored on 2011-08-10
1453

            
1454
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1455
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1456
$dbi->execute($create_table1);
1457
$dbi->register_filter(twice => sub { $_[0] * 2 });
1458
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1459
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1460
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1461
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1462
$result = $dbi->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1463
                        param => {$key1 => 1, $key2 => 2},
1464
                        table => [$table1]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1465
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1466
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute");
test cleanup
Yuki Kimoto authored on 2011-08-10
1467

            
1468
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1469
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1470
$dbi->execute($create_table1);
1471
$dbi->register_filter(twice => sub { $_[0] * 2 });
1472
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1473
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1474
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1475
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1476
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1477
                        param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1478
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1479
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1480

            
1481
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1482
eval { $dbi->execute("drop table $table1") };
1483
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1484
$dbi->execute($create_table1);
1485
$dbi->execute($create_table2);
1486
$dbi->register_filter(twice => sub { $_[0] * 2 });
1487
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1488
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1489
    $table1, $key2 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1490
);
1491
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1492
    $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1493
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1494
$dbi->insert(table => $table1, param => {$key1 => 5, $key2 => 2}, filter => {$key2 => undef});
1495
$dbi->insert(table => $table2, param => {$key1 => 5, $key3 => 6}, filter => {$key3 => undef});
test cleanup
Yuki Kimoto authored on 2011-08-10
1496
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1497
     table => [$table1, $table2],
1498
     column => [$key2, $key3],
1499
     where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
test cleanup
Yuki Kimoto authored on 2011-08-10
1500

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1501
$result->filter({$key2 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1502
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1503
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
test cleanup
Yuki Kimoto authored on 2011-08-10
1504

            
1505
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1506
     table => [$table1, $table2],
1507
     column => [$key2, $key3],
1508
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
test cleanup
Yuki Kimoto authored on 2011-08-10
1509

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1510
$result->filter({$key2 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1511
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1512
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join : omit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1513

            
1514
test 'each_column';
1515
$dbi = DBIx::Custom->connect;
1516
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1517
eval { $dbi->execute("drop table $table1") };
1518
eval { $dbi->execute("drop table $table2") };
1519
eval { $dbi->execute("drop table $table3") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1520
$dbi->execute($create_table1_type);
1521
$dbi->execute($create_table2);
1522

            
1523
$infos = [];
1524
$dbi->each_column(sub {
1525
    my ($self, $table, $column, $cinfo) = @_;
1526
    
1527
    if ($table =~ /^table\d/) {
1528
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
1529
         push @$infos, $info;
1530
    }
1531
});
1532
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
1533
is_deeply($infos, 
1534
    [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1535
        [$table1, $key1, $key1],
1536
        [$table1, $key2, $key2],
1537
        [$table2, $key1, $key1],
1538
        [$table2, $key3, $key3]
test cleanup
Yuki Kimoto authored on 2011-08-10
1539
    ]
1540
    
1541
);
1542
test 'each_table';
1543
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1544
eval { $dbi->execute("drop table $table1") };
1545
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1546
$dbi->execute($create_table2);
1547
$dbi->execute($create_table1_type);
1548

            
1549
$infos = [];
1550
$dbi->each_table(sub {
1551
    my ($self, $table, $table_info) = @_;
1552
    
1553
    if ($table =~ /^table\d/) {
1554
         my $info = [$table, $table_info->{TABLE_NAME}];
1555
         push @$infos, $info;
1556
    }
1557
});
1558
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
1559
is_deeply($infos, 
1560
    [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1561
        [$table1, $table1],
1562
        [$table2, $table2],
test cleanup
Yuki Kimoto authored on 2011-08-10
1563
    ]
1564
);
1565

            
1566
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1567
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1568
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1569
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1570
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1571
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1572

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1573
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1574
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1575
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1576
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1577
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1578
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1579

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1580
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1581
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1582
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1583
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1584
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1585

            
1586
test 'end_filter';
1587
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1588
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1589
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1590
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1591
$result = $dbi->select(table => $table1);
1592
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1593
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1594
$row = $result->fetch_first;
1595
is_deeply($row, [6, 40]);
1596

            
1597
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1598
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1599
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1600
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1601
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1602
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1603
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1604
$row = $result->fetch_first;
1605
is_deeply($row, [6, 12]);
1606

            
1607
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1608
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1609
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1610
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1611
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1612
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1613
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1614
$row = $result->fetch_first;
1615
is_deeply($row, [6, 12]);
1616

            
1617
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1618
$result = $dbi->select(table => $table1);
1619
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1620
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1621
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1622
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1623

            
1624
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1625
$dbi->apply_filter($table1,
1626
    $key1 => {end => sub { $_[0] * 3 } },
1627
    $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1628
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1629
$result = $dbi->select(table => $table1);
1630
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1631
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1632
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1633

            
1634
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1635
$dbi->apply_filter($table1,
1636
    $key1 => {end => sub { $_[0] * 3 } },
1637
    $key2 => {end => 'five_times'}
1638
);
1639
$result = $dbi->select(table => $table1);
1640
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1641
$result->filter($key1 => undef);
1642
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1643
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1644
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1645

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1646
test 'remove_end_filter and remove_filter';
1647
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1648
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1649
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1650
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1651
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1652
$row = $result
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1653
       ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1654
       ->remove_filter
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1655
       ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1656
       ->remove_end_filter
1657
       ->fetch_first;
1658
is_deeply($row, [1, 2]);
1659

            
1660
test 'empty where select';
1661
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1662
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1663
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1664
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1665
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1666
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1667
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1668

            
1669
test 'select query option';
1670
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1671
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1672
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1673
$query = $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1674
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1675
$query = $dbi->update(table => $table1, where => {$key1 => 1}, param => {$key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1676
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1677
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1678
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1679
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1680
is(ref $query, 'DBIx::Custom::Query');
1681

            
1682
test 'where';
1683
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1684
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1685
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1686
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1687
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1688
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1689
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1690

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

            
1695
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1696
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1697
    where => $where
1698
);
1699
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1700
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1701

            
1702
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1703
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1704
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1705
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
1706
        {$key1 => 1}
test cleanup
Yuki Kimoto authored on 2011-08-10
1707
    ]
1708
);
1709
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1710
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1711

            
1712
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1713
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1714
             ->param({$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1715
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1716
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1717
    where => $where
1718
);
1719
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1720
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1721

            
1722
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1723
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
test cleanup
Yuki Kimoto authored on 2011-08-10
1724
             ->param({});
1725
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1726
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1727
    where => $where,
1728
);
1729
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1730
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1731

            
1732
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1733
             ->clause(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"])
1734
             ->param({$key1 => [0, 3], $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1735
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1736
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1737
    where => $where,
1738
); 
1739
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1740
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1741

            
1742
$where = $dbi->where;
1743
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1744
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1745
    where => $where
1746
);
1747
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1748
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1749

            
1750
eval {
1751
$where = $dbi->where
1752
             ->clause(['uuu']);
1753
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1754
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1755
    where => $where
1756
);
1757
};
1758
ok($@);
1759

            
1760
$where = $dbi->where;
1761
is("$where", '');
1762

            
1763
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1764
             ->clause(['or', ("$key1 = :$key1") x 2])
1765
             ->param({$key1 => [1, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1766
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1767
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1768
    where => $where,
1769
);
1770
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1771
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1772

            
1773
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1774
             ->clause(['or', ("$key1 = :$key1") x 2])
1775
             ->param({$key1 => [1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1776
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1777
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1778
    where => $where,
1779
);
1780
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1781
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1782

            
1783
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1784
             ->clause(['or', ("$key1 = :$key1") x 2])
1785
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1786
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1787
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1788
    where => $where,
1789
);
1790
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1791
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1792

            
1793
$where = $dbi->where
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1794
             ->clause("$key1 = :$key1")
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1795
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1796
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1797
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1798
    where => $where,
1799
);
1800
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1801
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1802

            
1803
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1804
             ->clause("$key1 = :$key1 $key2 = :$key2")
1805
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1806
eval{$where->to_string};
1807
like($@, qr/one column/);
1808

            
1809
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1810
             ->clause(['or', ("$key1 = :$key1") x 3])
1811
             ->param({$key1 => [$dbi->not_exists, 1, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1812
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1813
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1814
    where => $where,
1815
);
1816
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1817
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1818

            
1819
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1820
             ->clause(['or', ("$key1 = :$key1") x 3])
1821
             ->param({$key1 => [1, $dbi->not_exists, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1822
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1823
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1824
    where => $where,
1825
);
1826
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1827
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1828

            
1829
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1830
             ->clause(['or', ("$key1 = :$key1") x 3])
1831
             ->param({$key1 => [1, 3, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1832
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1833
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1834
    where => $where,
1835
);
1836
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1837
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1838

            
1839
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1840
             ->clause(['or', ("$key1 = :$key1") x 3])
1841
             ->param({$key1 => [1, $dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1842
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1843
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1844
    where => $where,
1845
);
1846
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1847
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1848

            
1849
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1850
             ->clause(['or', ("$key1 = :$key1") x 3])
1851
             ->param({$key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1852
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1853
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1854
    where => $where,
1855
);
1856
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1857
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1858

            
1859
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1860
             ->clause(['or', ("$key1 = :$key1") x 3])
1861
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1862
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1863
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1864
    where => $where,
1865
);
1866
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1867
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1868

            
1869
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1870
             ->clause(['or', ("$key1 = :$key1") x 3])
1871
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1872
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1873
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1874
    where => $where,
1875
);
1876
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1877
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1878

            
1879
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1880
             ->clause(['or', ("$key1 = :$key1") x 3])
1881
             ->param({$key1 => []});
test cleanup
Yuki Kimoto authored on 2011-08-10
1882
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1883
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1884
    where => $where,
1885
);
1886
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1887
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1888

            
1889
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1890
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1891
             ->param({$key1 => [2, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1892
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1893
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1894
    where => $where,
1895
);
1896
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1897
is_deeply($row, [{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1898

            
1899
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1900
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1901
             ->param({$key1 => [$dbi->not_exists, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1902
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1903
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1904
    where => $where,
1905
);
1906
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1907
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1908

            
1909
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1910
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1911
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1912
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1913
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1914
    where => $where,
1915
);
1916
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1917
is_deeply($row, [{$key1 => 1, $key2 => 2},{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1918

            
1919
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1920
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1921
             ->param({$key1 => [0, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1922
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1923
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1924
    where => $where,
1925
);
1926
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1927
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1928

            
1929
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1930
             ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1931
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1932
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1933
    where => $where,
1934
);
1935
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1936
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1937

            
1938
eval {$dbi->where(ppp => 1) };
1939
like($@, qr/invalid/);
1940

            
1941
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1942
    clause => ['and', ['or'], ['and', "$key1 = :$key1", "$key2 = :$key2"]],
1943
    param => {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
1944
);
1945
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1946
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1947
    where => $where,
1948
);
1949
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1950
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1951

            
1952

            
1953
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1954
    clause => ['and', ['or'], ['or', ":$key1", ":$key2"]],
test cleanup
Yuki Kimoto authored on 2011-08-10
1955
    param => {}
1956
);
1957
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1958
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1959
    where => $where,
1960
);
1961
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1962
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1963

            
1964
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1965
$where->clause(['and', ":${key1}{=}"]);
1966
$where->param({$key1 => undef});
1967
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1968
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1969
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1970

            
1971
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1972
$where->clause(['and', ":${key1}{=}"]);
1973
$where->param({$key1 => undef});
test cleanup
Yuki Kimoto authored on 2011-08-10
1974
$where->if('defined');
1975
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1976
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1977
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1978
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1979

            
1980
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1981
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1982
$where->param({$key1 => [undef, undef]});
1983
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1984
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1985
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1986
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1987
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1988
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1989

            
1990
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1991
$where->clause(['and', ":${key1}{=}"]);
1992
$where->param({$key1 => [undef, undef]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1993
$where->if('defined');
1994
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1995
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1996
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1997
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
1998
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1999
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2000
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2001

            
2002
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2003
$where->clause(['and', ":${key1}{=}"]);
2004
$where->param({$key1 => 0});
test cleanup
Yuki Kimoto authored on 2011-08-10
2005
$where->if('length');
2006
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2007
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
2008
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2009
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2010

            
2011
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2012
$where->clause(['and', ":${key1}{=}"]);
2013
$where->param({$key1 => ''});
test cleanup
Yuki Kimoto authored on 2011-08-10
2014
$where->if('length');
2015
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2016
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
2017
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2018
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2019

            
2020
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2021
$where->clause(['and', ":${key1}{=}"]);
2022
$where->param({$key1 => 5});
test cleanup
Yuki Kimoto authored on 2011-08-10
2023
$where->if(sub { ($_[0] || '') eq 5 });
2024
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2025
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
2026
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2027
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2028

            
2029
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2030
$where->clause(['and', ":${key1}{=}"]);
2031
$where->param({$key1 => 7});
test cleanup
Yuki Kimoto authored on 2011-08-10
2032
$where->if(sub { ($_[0] || '') eq 5 });
2033
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2034
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
2035
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2036
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2037

            
2038
$where = $dbi->where;
2039
$where->param({id => 1, author => 'Ken', price => 1900});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2040
$where->map(id => "$table1.id",
2041
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2042
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
2043
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2044
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2045
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
2046

            
2047
$where = $dbi->where;
2048
$where->param({id => 0, author => 0, price => 0});
2049
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2050
    id => "$table1.id",
2051
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2052
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
test cleanup
Yuki Kimoto authored on 2011-08-10
2053
      {if => sub { $_[0] eq 0 }}]
2054
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2055
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
test cleanup
Yuki Kimoto authored on 2011-08-10
2056

            
2057
$where = $dbi->where;
2058
$where->param({id => '', author => '', price => ''});
2059
$where->if('length');
2060
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2061
    id => "$table1.id",
2062
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2063
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
test cleanup
Yuki Kimoto authored on 2011-08-10
2064
      {if => sub { $_[0] eq 1 }}]
2065
);
2066
is_deeply($where->param, {});
2067

            
2068
$where = $dbi->where;
2069
$where->param({id => undef, author => undef, price => undef});
2070
$where->if('length');
2071
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2072
    id => "$table1.id",
2073
    price => ["$table1.price", {if => 'exists'}]
test cleanup
Yuki Kimoto authored on 2011-08-10
2074
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2075
is_deeply($where->param, {"$table1.price" => undef});
test cleanup
Yuki Kimoto authored on 2011-08-10
2076

            
2077
$where = $dbi->where;
2078
$where->param({price => 'a'});
2079
$where->if('length');
2080
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2081
    id => ["$table1.id", {if => 'exists'}],
2082
    price => ["$table1.price", sub { '%' . $_[0] }, {if => 'exists'}]
test cleanup
Yuki Kimoto authored on 2011-08-10
2083
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2084
is_deeply($where->param, {"$table1.price" => '%a'});
test cleanup
Yuki Kimoto authored on 2011-08-10
2085

            
2086
$where = $dbi->where;
2087
$where->param({id => [1, 2], author => 'Ken', price => 1900});
2088
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2089
    id => "$table1.id",
2090
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2091
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
2092
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2093
is_deeply($where->param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2094
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
2095

            
2096
$where = $dbi->where;
2097
$where->if('length');
2098
$where->param({id => ['', ''], author => 'Ken', price => 1900});
2099
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2100
    id => "$table1.id",
2101
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2102
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
2103
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2104
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
2105
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
2106

            
2107
$where = $dbi->where;
2108
$where->param({id => ['', ''], author => 'Ken', price => 1900});
2109
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2110
    id => ["$table1.id", {if => 'length'}],
2111
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, {if => 'defined'}],
2112
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
2113
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2114
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
2115
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
2116

            
2117
test 'dbi_option default';
2118
$dbi = DBIx::Custom->new;
2119
is_deeply($dbi->dbi_option, {});
2120

            
2121
test 'register_tag_processor';
2122
$dbi = DBIx::Custom->connect;
2123
$dbi->register_tag_processor(
2124
    a => sub { 1 }
2125
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2126
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2127

            
2128
test 'register_tag';
2129
$dbi = DBIx::Custom->connect;
2130
$dbi->register_tag(
2131
    b => sub { 2 }
2132
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2133
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2134

            
2135
test 'table not specify exception';
2136
$dbi = DBIx::Custom->connect;
2137
eval {$dbi->insert};
2138
like($@, qr/table/);
2139
eval {$dbi->update};
2140
like($@, qr/table/);
2141
eval {$dbi->delete};
2142
like($@, qr/table/);
2143
eval {$dbi->select};
2144
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
2145

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2146
test 'more tests';
2147
$dbi = DBIx::Custom->connect;
2148
eval{$dbi->apply_filter('table', 'column', [])};
2149
like($@, qr/apply_filter/);
2150

            
2151
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
2152
like($@, qr/apply_filter/);
2153

            
2154
$dbi->apply_filter(
2155

            
2156
);
2157
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2158
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2159
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2160
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2161
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
2162
$dbi->apply_filter($table1, $key2, 
test cleanup
Yuki Kimoto authored on 2011-08-10
2163
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2164
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
2165
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2166

            
2167
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2168
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2169
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2170
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2171
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
2172
$dbi->apply_filter($table1, $key2, {});
2173
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
2174
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2175

            
2176
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2177
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2178
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2179
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2180
like($@, qr/not registered/);
2181
$dbi->method({one => sub { 1 }});
2182
is($dbi->one, 1);
2183

            
2184
eval{DBIx::Custom->connect(dsn => undef)};
2185
like($@, qr/_connect/);
2186

            
2187
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2188
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2189
$dbi->execute($create_table1);
2190
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2191
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
2192
             filter => {$key1 => 'twice'});
2193
$row = $dbi->select(table => $table1)->one;
2194
is_deeply($row, {$key1 => 2, $key2 => 2});
2195
eval {$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
2196
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
2197
like($@, qr//);
2198

            
2199
$dbi->register_filter(one => sub { });
2200
$dbi->default_fetch_filter('one');
2201
ok($dbi->default_fetch_filter);
2202
$dbi->default_bind_filter('one');
2203
ok($dbi->default_bind_filter);
2204
eval{$dbi->default_fetch_filter('no')};
2205
like($@, qr/not registered/);
2206
eval{$dbi->default_bind_filter('no')};
2207
like($@, qr/not registered/);
2208
$dbi->default_bind_filter(undef);
2209
ok(!defined $dbi->default_bind_filter);
2210
$dbi->default_fetch_filter(undef);
2211
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2212
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2213
like($@, qr/Tag not finished/);
2214

            
2215
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2216
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2217
$dbi->execute($create_table1);
2218
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2219
$result = $dbi->select(table => $table1);
2220
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2221
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2222
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2223
like($@, qr/not registered/);
2224
$result->default_filter(undef);
2225
ok(!defined $result->default_filter);
2226
$result->default_filter('one');
2227
is($result->default_filter->(), 1);
2228

            
2229
test 'dbi_option';
2230
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2231
ok($dbi->dbh->{PrintError});
2232
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2233
ok($dbi->dbh->{PrintError});
2234

            
2235
test 'DBIx::Custom::Result stash()';
2236
$result = DBIx::Custom::Result->new;
2237
is_deeply($result->stash, {}, 'default');
2238
$result->stash->{foo} = 1;
2239
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2240

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2241
test 'delete_at';
2242
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2243
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2244
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2245
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2246
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2247
    table => $table1,
2248
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2249
    where => [1, 2],
2250
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2251
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2252

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2253
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2254
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2255
    table => $table1,
2256
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2257
    where => 1,
2258
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2259
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2260

            
2261
test 'insert_at';
2262
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2263
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2264
$dbi->execute($create_table1_2);
2265
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2266
    primary_key => [$key1, $key2], 
2267
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2268
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2269
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2270
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2271
is($dbi->select(table => $table1)->one->{$key1}, 1);
2272
is($dbi->select(table => $table1)->one->{$key2}, 2);
2273
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2274

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2275
$dbi->delete_all(table => $table1);
2276
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2277
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2278
    primary_key => $key1, 
2279
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2280
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2281
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2282
);
2283

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

            
2288
eval {
2289
    $dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2290
        table => $table1,
2291
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2292
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2293
        param => {$key1 => 1, $key2 => 2, $key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2294
    );
2295
};
2296
like($@, qr/must be/);
2297

            
2298
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2299
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2300
$dbi->execute($create_table1_2);
2301
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2302
    {$key3 => 3},
2303
    primary_key => [$key1, $key2], 
2304
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2305
    where => [1, 2],
2306
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2307
is($dbi->select(table => $table1)->one->{$key1}, 1);
2308
is($dbi->select(table => $table1)->one->{$key2}, 2);
2309
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2310

            
2311
test 'update_at';
2312
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2313
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2314
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2315
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2316
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2317
    table => $table1,
2318
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2319
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2320
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2321
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2322
is($dbi->select(table => $table1)->one->{$key1}, 1);
2323
is($dbi->select(table => $table1)->one->{$key2}, 2);
2324
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2325

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2326
$dbi->delete_all(table => $table1);
2327
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2328
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2329
    table => $table1,
2330
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2331
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2332
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2333
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2334
is($dbi->select(table => $table1)->one->{$key1}, 1);
2335
is($dbi->select(table => $table1)->one->{$key2}, 2);
2336
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2337

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

            
2352
test 'select_at';
2353
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2354
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2355
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2356
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2357
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2358
    table => $table1,
2359
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2360
    where => [1, 2]
2361
);
2362
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2363
is($row->{$key1}, 1);
2364
is($row->{$key2}, 2);
2365
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2366

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2367
$dbi->delete_all(table => $table1);
2368
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2369
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2370
    table => $table1,
2371
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2372
    where => 1,
2373
);
2374
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2375
is($row->{$key1}, 1);
2376
is($row->{$key2}, 2);
2377
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2378

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2379
$dbi->delete_all(table => $table1);
2380
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2381
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2382
    table => $table1,
2383
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2384
    where => [1, 2]
2385
);
2386
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2387
is($row->{$key1}, 1);
2388
is($row->{$key2}, 2);
2389
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2390

            
2391
eval {
2392
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2393
        table => $table1,
2394
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2395
        where => {},
2396
    );
2397
};
2398
like($@, qr/must be/);
2399

            
2400
eval {
2401
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2402
        table => $table1,
2403
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2404
        where => [1],
2405
    );
2406
};
2407
like($@, qr/same/);
2408

            
2409
eval {
2410
    $result = $dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2411
        table => $table1,
2412
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2413
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2414
        param => {$key1 => 1, $key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-10
2415
    );
2416
};
2417
like($@, qr/must be/);
2418

            
2419
eval {
2420
    $result = $dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2421
        table => $table1,
2422
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2423
        where => {},
2424
    );
2425
};
2426
like($@, qr/must be/);
2427

            
2428
test 'columns';
2429
use MyDBI1;
2430
$dbi = MyDBI1->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2431
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2432

            
2433

            
2434
test 'model delete_at';
2435
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2436
eval { $dbi->execute("drop table $table1") };
2437
eval { $dbi->execute("drop table $table2") };
2438
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2439
$dbi->execute($create_table1_2);
2440
$dbi->execute($create_table2_2);
2441
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2442
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2443
$dbi->model($table1)->delete_at(where => [1, 2]);
2444
is_deeply($dbi->select(table => $table1)->all, []);
2445
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2446
$dbi->model($table1)->delete_at(where => [1, 2]);
2447
is_deeply($dbi->select(table => $table1)->all, []);
2448
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2449
$dbi->model($table3)->delete_at(where => [1, 2]);
2450
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2451

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

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

            
2481
test 'model select_at';
2482
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2483
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2484
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2485
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2486
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2487
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2488
is($row->{$key1}, 1);
2489
is($row->{$key2}, 2);
2490
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2491

            
2492

            
2493
test 'mycolumn and column';
2494
$dbi = MyDBI7->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2495
eval { $dbi->execute("drop table $table1") };
2496
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2497
$dbi->execute($create_table1);
2498
$dbi->execute($create_table2);
2499
$dbi->separator('__');
2500
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2501
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2502
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2503
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2504
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2505
    column => [$model->mycolumn, $model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2506
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2507
);
2508
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2509
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2510

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2511
test 'insert_param';
2512
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2513
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2514
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2515
$param = {$key1 => 1, $key2 => 2};
test cleanup
Yuki Kimoto authored on 2011-08-10
2516
$insert_param = $dbi->insert_param($param);
2517
$sql = <<"EOS";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2518
insert into $table1 $insert_param
test cleanup
Yuki Kimoto authored on 2011-08-10
2519
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2520
$dbi->execute($sql, param => $param, table => $table1);
2521
is($dbi->select(table => $table1)->one->{$key1}, 1);
2522
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2523

            
2524
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2525
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2526
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2527
$param = {$key1 => 1, $key2 => 2};
test cleanup
Yuki Kimoto authored on 2011-08-10
2528
$insert_param = $dbi->insert_param($param);
2529
$sql = <<"EOS";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2530
insert into $table1 $insert_param
test cleanup
Yuki Kimoto authored on 2011-08-10
2531
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2532
$dbi->execute($sql, param => $param, table => $table1);
2533
is($dbi->select(table => $table1)->one->{$key1}, 1);
2534
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2535

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2539
test 'mycolumn';
2540
$dbi = MyDBI8->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2541
eval { $dbi->execute("drop table $table1") };
2542
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2543
$dbi->execute($create_table1);
2544
$dbi->execute($create_table2);
2545
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2546
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2547
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2548
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2549
$result = $model->select_at(
2550
    column => [
2551
        $model->mycolumn,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2552
        $model->column($table2)
cleanup test
Yuki Kimoto authored on 2011-08-10
2553
    ]
2554
);
2555
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2556
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2557

            
2558
$result = $model->select_at(
2559
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2560
        $model->mycolumn([$key1]),
2561
        $model->column($table2 => [$key1])
cleanup test
Yuki Kimoto authored on 2011-08-10
2562
    ]
2563
);
2564
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2565
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2566
$result = $model->select_at(
2567
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2568
        $model->mycolumn([$key1]),
2569
        {$table2 => [$key1]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2570
    ]
2571
);
2572
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2573
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2574

            
2575
$result = $model->select_at(
2576
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2577
        $model->mycolumn([$key1]),
2578
        ["$table2.$key1", as => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2579
    ]
2580
);
2581
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2582
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2583

            
2584
$result = $model->select_at(
2585
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2586
        $model->mycolumn([$key1]),
2587
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2588
    ]
2589
);
2590
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2591
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2592

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2593
test 'merge_param';
2594
$dbi = DBIx::Custom->new;
2595
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2596
    {$key1 => 1, $key2 => 2, $key3 => 3},
2597
    {$key1 => 1, $key2 => 2},
2598
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2599
];
2600
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2601
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2602

            
2603
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2604
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2605
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2606
];
2607
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2608
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
2609

            
2610
test 'select() param option';
2611
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2612
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2613
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2614
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2615
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2616
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2617
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2618
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
2619
$dbi->insert(table => $table2, param => {$key1 => 2, $key3 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-10
2620
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2621
    table => $table1,
2622
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2623
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2624
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
2625
              " as $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2626
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2627
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2628
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2629

            
2630
test 'select() string where';
2631
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2632
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2633
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2634
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2635
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2636
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2637
    table => $table1,
2638
    where => "$key1 = :$key1 and $key2 = :$key2",
2639
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2640
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2641
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2642

            
2643
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2644
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2645
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2646
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2647
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2648
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2649
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2650
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2651
        "$key1 = :$key1 and $key2 = :$key2",
2652
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2653
    ]
2654
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2655
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2656

            
2657
test 'delete() string where';
2658
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2659
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2660
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2661
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2662
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2663
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2664
    table => $table1,
2665
    where => "$key1 = :$key1 and $key2 = :$key2",
2666
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2667
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2668
$rows = $dbi->select(table => $table1)->all;
2669
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2670

            
2671
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2672
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2673
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2674
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2675
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2676
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2677
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2678
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2679
        "$key1 = :$key1 and $key2 = :$key2",
2680
         {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2681
    ]
2682
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2683
$rows = $dbi->select(table => $table1)->all;
2684
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2685

            
2686

            
2687
test 'update() string where';
2688
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2689
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2690
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2691
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2692
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2693
    table => $table1,
2694
    param => {$key1 => 5},
2695
    where => "$key1 = :$key1 and $key2 = :$key2",
2696
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2697
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2698
$rows = $dbi->select(table => $table1)->all;
2699
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2700

            
2701
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2702
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2703
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2704
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2705
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2706
    table => $table1,
2707
    param => {$key1 => 5},
cleanup test
Yuki Kimoto authored on 2011-08-10
2708
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2709
        "$key1 = :$key1 and $key2 = :$key2",
2710
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2711
    ]
2712
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2713
$rows = $dbi->select(table => $table1)->all;
2714
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2715

            
2716
test 'insert id and primary_key option';
2717
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2718
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2719
$dbi->execute($create_table1_2);
2720
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2721
    primary_key => [$key1, $key2], 
2722
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2723
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2724
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2725
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2726
is($dbi->select(table => $table1)->one->{$key1}, 1);
2727
is($dbi->select(table => $table1)->one->{$key2}, 2);
2728
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2729

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2730
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2731
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2732
    primary_key => $key1, 
2733
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2734
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2735
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2736
);
2737

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

            
2742
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2743
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2744
$dbi->execute($create_table1_2);
2745
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2746
    {$key3 => 3},
2747
    primary_key => [$key1, $key2], 
2748
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2749
    id => [1, 2],
2750
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2751
is($dbi->select(table => $table1)->one->{$key1}, 1);
2752
is($dbi->select(table => $table1)->one->{$key2}, 2);
2753
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2754

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2755
test 'model insert id and primary_key option';
2756
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2757
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2758
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2759
$dbi->model($table1)->insert(
cleanup test
Yuki Kimoto authored on 2011-08-10
2760
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2761
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2762
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2763
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2764
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2765
is($row->{$key1}, 1);
2766
is($row->{$key2}, 2);
2767
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2768

            
2769
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2770
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2771
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2772
$dbi->model($table1)->insert(
2773
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2774
    id => [1, 2]
2775
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2776
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2777
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2778
is($row->{$key1}, 1);
2779
is($row->{$key2}, 2);
2780
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2781

            
2782
test 'update and id option';
2783
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2784
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2785
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2786
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2787
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2788
    table => $table1,
2789
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2790
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2791
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2792
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2793
is($dbi->select(table => $table1)->one->{$key1}, 1);
2794
is($dbi->select(table => $table1)->one->{$key2}, 2);
2795
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2796

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2797
$dbi->delete_all(table => $table1);
2798
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2799
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2800
    table => $table1,
2801
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2802
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2803
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2804
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2805
is($dbi->select(table => $table1)->one->{$key1}, 0);
2806
is($dbi->select(table => $table1)->one->{$key2}, 2);
2807
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2808

            
2809
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2810
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2811
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2812
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2813
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2814
    {$key3 => 4},
2815
    table => $table1,
2816
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2817
    id => [1, 2]
2818
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2819
is($dbi->select(table => $table1)->one->{$key1}, 1);
2820
is($dbi->select(table => $table1)->one->{$key2}, 2);
2821
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2822

            
2823

            
2824
test 'model update and id option';
2825
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2826
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2827
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2828
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2829
$dbi->model($table1)->update(
cleanup test
Yuki Kimoto authored on 2011-08-10
2830
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2831
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2832
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2833
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2834
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2835
is($row->{$key1}, 1);
2836
is($row->{$key2}, 2);
2837
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2838

            
2839

            
2840
test 'delete and id option';
2841
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2842
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2843
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2844
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2845
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2846
    table => $table1,
2847
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2848
    id => [1, 2],
2849
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2850
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2851

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2852
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2853
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2854
    table => $table1,
2855
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2856
    id => 0,
2857
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2858
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2859

            
2860

            
2861
test 'model delete and id option';
2862
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2863
eval { $dbi->execute("drop table $table1") };
2864
eval { $dbi->execute("drop table $table2") };
2865
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2866
$dbi->execute($create_table1_2);
2867
$dbi->execute($create_table2_2);
2868
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2869
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2870
$dbi->model($table1)->delete(id => [1, 2]);
2871
is_deeply($dbi->select(table => $table1)->all, []);
2872
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2873
$dbi->model($table1)->delete(id => [1, 2]);
2874
is_deeply($dbi->select(table => $table1)->all, []);
2875
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2876
$dbi->model($table3)->delete(id => [1, 2]);
2877
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2878

            
2879

            
2880
test 'select and id option';
2881
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2882
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2883
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2884
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2885
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2886
    table => $table1,
2887
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2888
    id => [1, 2]
2889
);
2890
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2891
is($row->{$key1}, 1);
2892
is($row->{$key2}, 2);
2893
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2894

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2895
$dbi->delete_all(table => $table1);
2896
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2897
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2898
    table => $table1,
2899
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2900
    id => 0,
2901
);
2902
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2903
is($row->{$key1}, 0);
2904
is($row->{$key2}, 2);
2905
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2906

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2907
$dbi->delete_all(table => $table1);
2908
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2909
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2910
    table => $table1,
2911
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2912
    id => [1, 2]
2913
);
2914
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2915
is($row->{$key1}, 1);
2916
is($row->{$key2}, 2);
2917
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2918

            
2919

            
2920
test 'model select_at';
2921
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2922
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2923
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2924
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2925
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2926
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2927
is($row->{$key1}, 1);
2928
is($row->{$key2}, 2);
2929
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2930

            
2931
test 'column separator is default .';
2932
$dbi = MyDBI7->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2933
eval { $dbi->execute("drop table $table1") };
2934
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2935
$dbi->execute($create_table1);
2936
$dbi->execute($create_table2);
2937
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2938
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2939
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2940
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2941
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2942
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2943
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2944
);
2945
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2946
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2947

            
2948
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2949
    column => [$model->column($table2 => [$key1, $key3])],
2950
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2951
);
2952
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2953
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2954

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2955
test 'separator';
2956
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2957
eval { $dbi->execute("drop table $table1") };
2958
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2959
$dbi->execute($create_table1);
2960
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2961

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2962
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2963
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2964
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2965
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2966
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2967
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2968
);
2969
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2970
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2971
);
2972
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2973
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2974
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2975
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2976
$result = $model->select(
2977
    column => [
2978
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2979
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2980
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2981
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2982
);
2983
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2984
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2985
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2986

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2987
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2988
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2989
$result = $model->select(
2990
    column => [
2991
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2992
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2993
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2994
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2995
);
2996
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2997
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
2998
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2999

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3000
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3001
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3002
$result = $model->select(
3003
    column => [
3004
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3005
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
3006
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3007
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3008
);
3009
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3010
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
3011
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3012

            
3013

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3014
test 'filter_off';
3015
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3016
eval { $dbi->execute("drop table $table1") };
3017
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3018
$dbi->execute($create_table1);
3019
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
3020

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3021
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3022
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
3023
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3024
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
3025
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3026
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
3027
);
3028
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3029
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3030
$model = $dbi->model($table1);
3031
$result = $model->select(column => $key1);
3032
$result->filter($key1 => sub { $_[0] * 2 });
3033
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
3034

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3035
test 'available_datetype';
3036
$dbi = DBIx::Custom->connect;
3037
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
3038

            
3039

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3040
test 'select prefix option';
3041
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3042
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3043
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3044
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3045
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3046
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
3047

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3048
test 'map_param';
3049
$dbi = DBIx::Custom->connect;
3050
$param = $dbi->map_param(
3051
    {id => 1, author => 'Ken', price => 1900},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3052
    id => "$table1.id",
3053
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3054
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
cleanup test
Yuki Kimoto authored on 2011-08-10
3055
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3056
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3057
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
3058

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3059
$param = $dbi->map_param(
3060
    {id => 0, author => 0, price => 0},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3061
    id => "$table1.id",
3062
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3063
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
cleanup test
Yuki Kimoto authored on 2011-08-10
3064
      {if => sub { $_[0] eq 0 }}]
3065
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3066
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3067

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3068
$param = $dbi->map_param(
3069
    {id => '', author => '', price => ''},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3070
    id => "$table1.id",
3071
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3072
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
cleanup test
Yuki Kimoto authored on 2011-08-10
3073
      {if => sub { $_[0] eq 1 }}]
3074
);
3075
is_deeply($param, {});
test cleanup
Yuki Kimoto authored on 2011-08-10
3076

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3077
$param = $dbi->map_param(
3078
    {id => undef, author => undef, price => undef},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3079
    id => "$table1.id",
3080
    price => ["$table1.price", {if => 'exists'}]
cleanup test
Yuki Kimoto authored on 2011-08-10
3081
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3082
is_deeply($param, {"$table1.price" => undef});
test cleanup
Yuki Kimoto authored on 2011-08-10
3083

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3084
$param = $dbi->map_param(
3085
    {price => 'a'},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3086
    id => ["$table1.id", {if => 'exists'}],
3087
    price => ["$table1.price", sub { '%' . $_[0] }, {if => 'exists'}]
cleanup test
Yuki Kimoto authored on 2011-08-10
3088
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3089
is_deeply($param, {"$table1.price" => '%a'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3090

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3091
test 'order';
3092
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3093
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3094
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3095
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3096
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3097
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3098
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3099
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3100
$order->prepend($key1, "$key2 desc");
3101
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3102
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
3103
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3104
$order->prepend("$key1 desc");
3105
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3106
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
3107
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3108

            
3109
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3110
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3111
$result = $dbi->select(table => $table1,
3112
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3113
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3114
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
3115
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
3116
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
3117
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3118

            
3119
test 'tag_parse';
3120
$dbi = DBIx::Custom->connect;
3121
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3122
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3123
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3124
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3125
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3126
ok($@);
3127

            
3128
test 'last_sql';
3129
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3130
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3131
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3132
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
3133
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3134

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

            
3138
test 'DBIx::Custom header';
3139
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3140
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3141
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3142
$result = $dbi->execute("select $key1 as h1, $key2 as h2 from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3143
is_deeply($result->header, [qw/h1 h2/]);
3144

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3166
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3167
$result = $dbi->execute(
3168
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3169
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3170
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3171
);
3172
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3173
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3174

            
3175
test 'high perfomance way';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3176
$dbi->execute("drop table $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3177
$dbi->execute($create_table1_highperformance);
3178
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3179
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3180
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3181
];
3182
{
3183
    my $query;
3184
    foreach my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3185
      $query ||= $dbi->insert($row, table => $table1, query => 1);
3186
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
3187
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3188
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3189
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3190
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3191
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3192
      ]
3193
    );
3194
}
3195

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3196
$dbi->execute("drop table $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3197
$dbi->execute($create_table1_highperformance);
3198
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3199
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3200
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3201
];
3202
{
3203
    my $query;
3204
    my $sth;
3205
    foreach my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3206
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3207
      $sth ||= $query->sth;
3208
      $sth->execute(map { $row->{$_} } sort keys %$row);
3209
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3210
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3211
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3212
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3213
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3214
      ]
3215
    );
3216
}
3217

            
3218
test 'result';
3219
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3220
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3221
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3222
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3223
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3224

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3225
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3226
@rows = ();
3227
while (my $row = $result->fetch) {
3228
    push @rows, [@$row];
3229
}
3230
is_deeply(\@rows, [[1, 2], [3, 4]]);
3231

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3232
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3233
@rows = ();
3234
while (my $row = $result->fetch_hash) {
3235
    push @rows, {%$row};
3236
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3237
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3238

            
3239
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3240
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3241
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3242
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3243
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3244

            
3245
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3246
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3247
$rows = $result->fetch_all;
3248
is_deeply($rows, [[1, 2], [3, 4]]);
3249

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

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

            
3258
$rows = $result->fetch_all;
3259
is_deeply($rows, [[3, 2], [9, 4]], "array");
3260

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

            
3267
test "query_builder";
3268
$datas = [
3269
    # Basic tests
3270
    {   name            => 'placeholder basic',
3271
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3272
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3273
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3274
    },
3275
    {
3276
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3277
        source            => "{in k1 3}",
3278
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3279
        columns_expected   => [qw/k1 k1 k1/]
3280
    },
3281
    
3282
    # Table name
3283
    {
3284
        name            => 'placeholder with table name',
3285
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3286
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3287
        columns_expected  => [qw/a.k1 a.k2/]
3288
    },
3289
    {   
3290
        name            => 'placeholder in with table name',
3291
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3292
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3293
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3294
    },
3295
    {
3296
        name            => 'not contain tag',
3297
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3298
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3299
        columns_expected  => [],
3300
    }
3301
];
3302

            
3303
for (my $i = 0; $i < @$datas; $i++) {
3304
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3305
    my $dbi = DBIx::Custom->new;
3306
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3307
    my $query = $builder->build_query($data->{source});
3308
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3309
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3310
}
3311

            
cleanup
Yuki Kimoto authored on 2011-08-13
3312
$dbi = DBIx::Custom->new;
3313
$builder = $dbi->query_builder;
3314
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3315
    p => sub {
3316
        my @args = @_;
3317
        
3318
        my $expand    = "? $args[0] $args[1]";
3319
        my $columns = [2];
3320
        return [$expand, $columns];
3321
    }
3322
);
3323

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3334
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3335
    q => 'string'
3336
});
3337

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3341
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3342
   r => sub {} 
3343
});
3344

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3348
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3349
   s => sub { return ["a", ""]} 
3350
});
3351

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3355
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3356
    t => sub {return ["a", []]}
3357
);
3358

            
3359

            
cleanup
Yuki Kimoto authored on 2011-08-13
3360
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3361
    a => sub {
3362
        return ["? ? ?", ['']];
3363
    }
3364
);
3365
eval{$builder->build_query("{a}")};
3366
like($@, qr/\QPlaceholder count/, "placeholder count is invalid");
3367

            
3368

            
3369
test 'Default tag Error case';
3370
eval{$builder->build_query("{= }")};
3371
like($@, qr/Column name must be specified in tag "{= }"/, "basic '=' : key not exist");
3372

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

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

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

            
3384
test 'variouse source';
cleanup test
Yuki Kimoto authored on 2011-08-15
3385
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
test cleanup
Yuki Kimoto authored on 2011-08-10
3386
$query = $builder->build_query($source);
cleanup test
Yuki Kimoto authored on 2011-08-15
3387
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3388

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3389
$source = "abc";
test cleanup
Yuki Kimoto authored on 2011-08-10
3390
$query = $builder->build_query($source);
cleanup test
Yuki Kimoto authored on 2011-08-15
3391
is($query->sql, 'abc', "basic : 2");
test cleanup
Yuki Kimoto authored on 2011-08-10
3392

            
3393
$source = "{= a}";
3394
$query = $builder->build_query($source);
cleanup test
Yuki Kimoto authored on 2011-08-15
3395
is($query->sql, 'a = ?', "only tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
3396

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3397
$source = "000";
test cleanup
Yuki Kimoto authored on 2011-08-10
3398
$query = $builder->build_query($source);
cleanup test
Yuki Kimoto authored on 2011-08-15
3399
is($query->sql, '000', "contain 0 value");
test cleanup
Yuki Kimoto authored on 2011-08-10
3400

            
3401
$source = "a {= b} }";
3402
eval{$builder->build_query($source)};
3403
like($@, qr/unexpected "}"/, "error : 1");
3404

            
3405
$source = "a {= {}";
3406
eval{$builder->build_query($source)};
3407
like($@, qr/unexpected "{"/, "error : 2");
3408

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3409
test 'select() wrap option';
3410
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3411
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3412
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3413
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3414
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
3415
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3416
    table => $table1,
3417
    column => $key1,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3418
    wrap => ["select * from (", ") as t where $key1 = 1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
3419
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3420
is_deeply($rows, [{$key1 => 1}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3421

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3422
eval {
3423
$dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3424
    table => $table1,
3425
    column => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
3426
    wrap => 'select * from ('
3427
)
3428
};
3429
like($@, qr/array/);
3430

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3431
test 'select() sqlfilter option';
3432
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3433
eval { $dbi->execute("drop table $table1") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3434
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3435
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3436
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3437
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3438
    table => $table1,
3439
    column => $key1,
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3440
    sqlfilter => sub {
3441
        my $sql = shift;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3442
        $sql = "select * from ( $sql ) as t where $key1 = 1";
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3443
        return $sql;
3444
    }
3445
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3446
is_deeply($rows, [{$key1 => 1}]);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3447

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3448
test 'dbi method from model';
3449
$dbi = MyDBI9->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3450
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3451
$dbi->execute($create_table1);
3452
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3453
$model = $dbi->model($table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3454
eval{$model->execute("select * from $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-10
3455
ok(!$@);
3456

            
3457
test 'column table option';
3458
$dbi = MyDBI9->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3459
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3460
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3461
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3462
$dbi->execute($create_table2);
3463
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3464
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3465
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3466
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3467
$result = $model->select(
3468
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3469
        $model->column($table2, {alias => $table2_alias})
cleanup test
Yuki Kimoto authored on 2011-08-10
3470
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3471
    where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
3472
);
3473
is_deeply($result->one, 
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3474
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-10
3475

            
3476
$dbi->separator('__');
3477
$result = $model->select(
3478
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3479
        $model->column($table2, {alias => $table2_alias})
cleanup test
Yuki Kimoto authored on 2011-08-10
3480
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3481
    where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
3482
);
3483
is_deeply($result->one, 
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3484
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-10
3485

            
3486
$dbi->separator('-');
3487
$result = $model->select(
3488
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3489
        $model->column($table2, {alias => $table2_alias})
cleanup test
Yuki Kimoto authored on 2011-08-10
3490
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3491
    where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
3492
);
3493
is_deeply($result->one, 
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3494
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-10
3495

            
3496
test 'create_model';
3497
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3498
eval { $dbi->execute("drop table $table1") };
3499
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3500
$dbi->execute($create_table1);
3501
$dbi->execute($create_table2);
3502

            
3503
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3504
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
3505
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3506
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
3507
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3508
    primary_key => [$key1]
cleanup test
Yuki Kimoto authored on 2011-08-10
3509
);
3510
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3511
    table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-10
3512
);
3513
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3514
    table => $table3,
cleanup test
Yuki Kimoto authored on 2011-08-10
3515
    filter => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3516
        $key1 => {in => sub { uc $_[0] }}
cleanup test
Yuki Kimoto authored on 2011-08-10
3517
    ]
3518
);
3519
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3520
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3521
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3522
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3523
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3524
    column => [$model->mycolumn, $model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3525
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3526
);
3527
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3528
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3529
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
3530

            
3531
test 'model method';
3532
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3533
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3534
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3535
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
3536
$model = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3537
    table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-10
3538
);
3539
$model->method(foo => sub { shift->select(@_) });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3540
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
3541

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3542
test 'update_param';
3543
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3544
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3545
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3546
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3547
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-10
3548

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3549
$param = {$key2 => 11};
cleanup test
Yuki Kimoto authored on 2011-08-10
3550
$update_param = $dbi->update_param($param);
3551
$sql = <<"EOS";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3552
update $table1 $update_param
3553
where $key1 = 1
cleanup test
Yuki Kimoto authored on 2011-08-10
3554
EOS
3555
$dbi->execute($sql, param => $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3556
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3557
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3558
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3559
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
cleanup test
Yuki Kimoto authored on 2011-08-10
3560
                  "basic");
3561

            
3562

            
3563
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3564
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3565
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3566
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3567
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-10
3568

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3569
$param = {$key2 => 11, $key3 => 33};
cleanup test
Yuki Kimoto authored on 2011-08-10
3570
$update_param = $dbi->update_param($param);
3571
$sql = <<"EOS";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3572
update $table1 $update_param
3573
where $key1 = 1
cleanup test
Yuki Kimoto authored on 2011-08-10
3574
EOS
3575
$dbi->execute($sql, param => $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3576
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3577
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3578
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3579
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
cleanup test
Yuki Kimoto authored on 2011-08-10
3580
                  "basic");
3581

            
3582
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3583
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3584
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3585
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3586
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-10
3587

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3588
$param = {$key2 => 11, $key3 => 33};
cleanup test
Yuki Kimoto authored on 2011-08-10
3589
$update_param = $dbi->update_param($param, {no_set => 1});
3590
$sql = <<"EOS";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3591
update $table1 set $update_param
3592
where $key1 = 1
cleanup test
Yuki Kimoto authored on 2011-08-10
3593
EOS
3594
$dbi->execute($sql, param => $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3595
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3596
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3597
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3598
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
cleanup test
Yuki Kimoto authored on 2011-08-10
3599
                  "update param no_set");
3600

            
3601
            
3602
eval { $dbi->update_param({";" => 1}) };
3603
like($@, qr/not safety/);
3604

            
3605

            
3606
test 'update_param';
3607
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3608
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3609
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3610
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3611
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-10
3612

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3613
$param = {$key2 => 11};
cleanup test
Yuki Kimoto authored on 2011-08-10
3614
$update_param = $dbi->assign_param($param);
3615
$sql = <<"EOS";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3616
update $table1 set $update_param
3617
where $key1 = 1
cleanup test
Yuki Kimoto authored on 2011-08-10
3618
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3619
$dbi->execute($sql, param => $param, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3620
$result = $dbi->execute("select * from $table1 order by $key1");
cleanup test
Yuki Kimoto authored on 2011-08-10
3621
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3622
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3623
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
cleanup test
Yuki Kimoto authored on 2011-08-10
3624
                  "basic");
3625

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3626
test 'join';
3627
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3628
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3629
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3630
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3631
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3632
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3633
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3634
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3635
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3636
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3637
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
cleanup test
Yuki Kimoto authored on 2011-08-10
3638
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3639
    table => $table1,
3640
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3641
    where   => {"$table1.$key2" => 2},
3642
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
3643
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3644
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3645

            
3646
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3647
    table => $table1,
3648
    where   => {$key1 => 1},
3649
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
3650
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3651
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3652

            
3653
eval {
3654
    $rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3655
        table => $table1,
3656
        column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3657
        where   => {"$table1.$key2" => 2},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3658
        join  => {"$table1.$key1" => "$table2.$key1"}
cleanup test
Yuki Kimoto authored on 2011-08-10
3659
    );
3660
};
3661
like ($@, qr/array/);
3662

            
3663
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3664
    table => $table1,
3665
    where   => {$key1 => 1},
3666
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3667
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
cleanup test
Yuki Kimoto authored on 2011-08-10
3668
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3669
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3670

            
3671
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3672
    column => "$table3.$key4 as ${table3}__$key4",
3673
    table => $table1,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3674
    where   => {"$table1.$key1" => 1},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3675
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3676
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
cleanup test
Yuki Kimoto authored on 2011-08-10
3677
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3678
is_deeply($rows, [{"${table3}__$key4" => 4}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3679

            
3680
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3681
    column => "$table1.$key1 as ${table1}__$key1",
3682
    table => $table1,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3683
    where   => {"$table3.$key4" => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3684
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3685
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
cleanup test
Yuki Kimoto authored on 2011-08-10
3686
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3687
is_deeply($rows, [{"${table1}__$key1" => 1}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3688

            
3689
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3690
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3691
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3692
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3693
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3694
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3695
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-10
3696
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3697
    table => $table1,
3698
    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",
3699
    where   => {"$table1.$key2" => 2},
3700
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
cleanup test
Yuki Kimoto authored on 2011-08-10
3701
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3702
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
cleanup test
Yuki Kimoto authored on 2011-08-10
3703
          'quote');
3704

            
3705

            
3706
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3707
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3708
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3709
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
3710
$sql = <<"EOS";
3711
left outer join (
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3712
  select * from $table1 as t1
3713
  where t1.$key2 = (
3714
    select max(t2.$key2) from $table1 as t2
3715
    where t1.$key1 = t2.$key1
cleanup test
Yuki Kimoto authored on 2011-08-10
3716
  )
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3717
) as latest_$table1 on $table1.$key1 = latest_$table1.$key1
cleanup test
Yuki Kimoto authored on 2011-08-10
3718
EOS
3719
$join = [$sql];
3720
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3721
    table => $table1,
3722
    column => "latest_$table1.$key1 as latest_${table1}__$key1",
cleanup test
Yuki Kimoto authored on 2011-08-10
3723
    join  => $join
3724
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3725
is_deeply($rows, [{"latest_${table1}__$key1" => 1}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3726

            
3727
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3728
eval { $dbi->execute("drop table $table1") };
3729
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3730
$dbi->execute($create_table1);
3731
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3732
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3733
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
3734
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-10
3735
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3736
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
3737
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3738
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
3739
    ]
3740
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3741
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3742
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3743
    table => $table1,
3744
    column => [{$table2 => [$key3]}],
cleanup test
Yuki Kimoto authored on 2011-08-10
3745
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3746
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
3747
    ]
3748
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3749
is_deeply($result->all, [{"$table2.$key3" => 4}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3750
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3751
    table => $table1,
3752
    column => [{$table2 => [$key3]}],
cleanup test
Yuki Kimoto authored on 2011-08-10
3753
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3754
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
cleanup test
Yuki Kimoto authored on 2011-08-10
3755
    ]
3756
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3757
is_deeply($result->all, [{"$table2.$key3" => 4}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3758

            
3759
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3760
eval { $dbi->execute("drop table $table1") };
3761
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3762
$dbi->execute($create_table1);
3763
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3764
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3765
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
3766
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-10
3767
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3768
    table => $table1,
3769
    column => [{$table2 => [$key3]}],
cleanup test
Yuki Kimoto authored on 2011-08-10
3770
    join => [
3771
        {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3772
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
3773
            table => [$table1, $table2]
cleanup test
Yuki Kimoto authored on 2011-08-10
3774
        }
3775
    ]
3776
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3777
is_deeply($result->all, [{"$table2.$key3" => 4}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3778

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3779
test 'Model class';
3780
use MyDBI1;
3781
$dbi = MyDBI1->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3782
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3783
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3784
$model = $dbi->model($table1);
3785
$model->insert({$key1 => 'a', $key2 => 'b'});
3786
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3787
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3788
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3789
$model = $dbi->model($table2);
3790
$model->insert({$key1 => 'a'});
3791
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3792
is($dbi->models->{$table1}, $dbi->model($table1));
3793
is($dbi->models->{$table2}, $dbi->model($table2));
test cleanup
Yuki Kimoto authored on 2011-08-10
3794

            
3795
$dbi = MyDBI4->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3796
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3797
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3798
$model = $dbi->model($table1);
3799
$model->insert({$key1 => 'a', $key2 => 'b'});
3800
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3801
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3802
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3803
$model = $dbi->model($table2);
3804
$model->insert({$key1 => 'a'});
3805
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
test cleanup
Yuki Kimoto authored on 2011-08-10
3806

            
3807
$dbi = MyDBI5->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3808
eval { $dbi->execute("drop table $table1") };
3809
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3810
$dbi->execute($create_table1);
3811
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3812
$model = $dbi->model($table2);
3813
$model->insert({$key1 => 'a'});
3814
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3815
$dbi->insert(table => $table1, param => {$key1 => 1});
3816
$model = $dbi->model($table1);
3817
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
test cleanup
Yuki Kimoto authored on 2011-08-10
3818

            
3819
test 'primary_key';
3820
use MyDBI1;
3821
$dbi = MyDBI1->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3822
$model = $dbi->model($table1);
3823
$model->primary_key([$key1, $key2]);
3824
is_deeply($model->primary_key, [$key1, $key2]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3825

            
3826
test 'columns';
3827
use MyDBI1;
3828
$dbi = MyDBI1->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3829
$model = $dbi->model($table1);
3830
$model->columns([$key1, $key2]);
3831
is_deeply($model->columns, [$key1, $key2]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3832

            
3833
test 'setup_model';
3834
use MyDBI1;
3835
$dbi = MyDBI1->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3836
eval { $dbi->execute("drop table $table1") };
3837
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3838

            
3839
$dbi->execute($create_table1);
3840
$dbi->execute($create_table2);
3841
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3842
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3843
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3844

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

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

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