DBIx-Custom / t / common.t /
Newer Older
3855 lines | 126.676kb
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

            
added common test executing ...
Yuki Kimoto authored on 2011-08-07
208
# Drop table
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
209
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
210

            
211
test 'type_rule into';
212
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
213
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
214
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-15
215
$DB::single = 1;
216
$dbi->each_table(sub {
217
    my ($self, $table, $column, $cinfo) = @_;
218

            
219
    $DB::single = 1;
220
    
221
    if (lc $table eq lc $table1) {
222
        1;
223
        
224
    }
225
});
226

            
227

            
test cleanup
Yuki Kimoto authored on 2011-08-10
228
$dbi->type_rule(
229
    into1 => {
230
        $date_typename => sub { '2010-' . $_[0] }
231
    }
232
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
233
$dbi->insert({$key1 => '01-01'}, table => $table1);
234
$result = $dbi->select(table => $table1);
235
like($result->one->{$key1}, qr/^2010-01-01/);
test cleanup
Yuki Kimoto authored on 2011-08-10
236

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

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

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

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

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

            
342

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

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

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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
441
eval{$dbi->type_rule(
442
    into1 => {
443
        $date_typename => 'pp'
444
    }
445
)};
446
like($@, qr/not registered/);
test cleanup
Yuki Kimoto authored on 2011-08-10
447

            
test cleanup
Yuki Kimoto authored on 2011-08-10
448
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
449
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
450
$dbi->execute($create_table1_type);
451
eval {
452
    $dbi->type_rule(
453
        from1 => {
454
            Date => sub { $_[0] * 2 },
455
        }
456
    );
457
};
458
like($@, qr/lower/);
test cleanup
Yuki Kimoto authored on 2011-08-10
459

            
test cleanup
Yuki Kimoto authored on 2011-08-10
460
eval {
461
    $dbi->type_rule(
462
        into1 => {
463
            Date => sub { $_[0] * 2 },
464
        }
465
    );
466
};
467
like($@, qr/lower/);
test cleanup
Yuki Kimoto authored on 2011-08-10
468

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
485
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
486
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
487
$dbi->execute($create_table1_type);
488
$dbi->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/4/; return $v },
491
        $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
492
    },
493
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
494
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
495
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
496
$result->type_rule(
497
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
498
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
499
    }
500
);
501
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
502
like($row->{$key1}, qr/^2010-01-05/);
503
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
test cleanup
Yuki Kimoto authored on 2011-08-10
504

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
515
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
516
$result->type_rule(
517
    from1 => {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
518
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
test cleanup
Yuki Kimoto authored on 2011-08-10
519
    }
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

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

            
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
533
$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
534
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
535
$result->type_rule(
536
    from1 => [$date_datatype => 'five']
537
);
538
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
539
like($row->{$key1}, qr/^2010-01-05/);
540
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
test cleanup
Yuki Kimoto authored on 2011-08-10
541

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
542
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
543
$result->type_rule(
544
    from1 => [$date_datatype => undef]
545
);
546
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
547
like($row->{$key1}, qr/^2010-01-03/);
548
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
test cleanup
Yuki Kimoto authored on 2011-08-10
549

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

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

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

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

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

            
645

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

            
647
# Create table
test cleanup
Yuki Kimoto authored on 2011-08-10
648
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
649
eval { $dbi->execute("drop table $table1") };
added common test executing ...
Yuki Kimoto authored on 2011-08-07
650
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
651
$model = $dbi->create_model(table => $table1);
652
$model->insert({$key1 => 1, $key2 => 2});
653
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]);
added common test executing ...
Yuki Kimoto authored on 2011-08-07
654

            
cleanup test
Yuki Kimoto authored on 2011-08-08
655
test 'DBIx::Custom::Result test';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
656
$dbi->delete_all(table => $table1);
657
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
658
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
659
$source = "select $key1, $key2 from $table1";
cleanup test
Yuki Kimoto authored on 2011-08-08
660
$query = $dbi->create_query($source);
661
$result = $dbi->execute($query);
662

            
663
@rows = ();
664
while (my $row = $result->fetch) {
665
    push @rows, [@$row];
666
}
667
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
668

            
669
$result = $dbi->execute($query);
670
@rows = ();
671
while (my $row = $result->fetch_hash) {
672
    push @rows, {%$row};
673
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
674
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
cleanup test
Yuki Kimoto authored on 2011-08-08
675

            
676
$result = $dbi->execute($query);
677
$rows = $result->fetch_all;
678
is_deeply($rows, [[1, 2], [3, 4]], "fetch_all");
679

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

            
684
test 'Insert query return value';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
685
$source = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
686
$query = $dbi->execute($source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
687
$ret_val = $dbi->execute($query, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-08
688
ok($ret_val);
689

            
690
test 'Direct query';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
691
$dbi->delete_all(table => $table1);
692
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
693
$dbi->execute($insert_source, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
694
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-08
695
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
696
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
697

            
698
test 'Filter basic';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
699
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-08
700
$dbi->register_filter(twice       => sub { $_[0] * 2}, 
701
                    three_times => sub { $_[0] * 3});
702

            
cleanup test
Yuki Kimoto authored on 2011-08-15
703
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
704
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
705
$insert_query->filter({$key1 => 'twice'});
706
$dbi->execute($insert_query, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
707
$result = $dbi->execute("select * from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
708
$rows = $result->filter({$key2 => 'three_times'})->all;
709
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
710

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
803
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
804
$result = $dbi->execute(
805
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
806
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
807
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
cleanup test
Yuki Kimoto authored on 2011-08-08
808
);
809
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
810
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
811

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
812
$dbi->execute("drop table $table1");
cleanup test
Yuki Kimoto authored on 2011-08-08
813
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
814
$dbi->insert(table => $table1, param => {$key1 => '2011-10-14 12:19:18', $key2 => 2});
815
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
816
$result = $dbi->execute(
817
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
818
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
819
);
820

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
825
$dbi->delete_all(table => $table1);
826
$dbi->insert(table => $table1, param => {$key1 => 'a:b c:d', $key2 => 2});
827
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
828
$result = $dbi->execute(
829
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
830
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
831
);
832
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
833
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
834

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
851
$dbi->execute("delete from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
852
$dbi->register_filter(
853
    twice       => sub { $_[0] * 2 },
854
    three_times => sub { $_[0] * 3 }
855
);
856
$dbi->default_bind_filter('twice');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
857
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => 'three_times'});
cleanup test
Yuki Kimoto authored on 2011-08-15
858
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
859
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
860
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-10
861
$dbi->default_bind_filter(undef);
862

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
863
$dbi->execute("drop table $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
864
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
865
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, append => '   ');
866
$rows = $dbi->select(table => $table1)->all;
867
is_deeply($rows, [{$key1 => 1, $key2 => 2}], 'insert append');
cleanup test
Yuki Kimoto authored on 2011-08-10
868

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

            
872
eval{$dbi->insert(table => 'table', param => {';' => 1})};
873
like($@, qr/safety/);
874

            
cleanup test
Yuki Kimoto authored on 2011-08-10
875
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
876
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
877
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
878
$dbi->insert(table => 'table', param => {select => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
879
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
880
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
881
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
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({$key1 => 1, $key2 => 2}, table => $table1);
886
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
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

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

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

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

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

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

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

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
972
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
973
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
974
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
975
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
976
$where->clause(['and', "$key2 = :$key2"]);
977
$where->param({$key2 => 2});
978
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
979
$result = $dbi->select(table => $table1);
980
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
981

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
988
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
989
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
990
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
991
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
992
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
993
$dbi->insert(table => 'table', param => {select => 1});
994
$dbi->update(table => 'table', where => {select => 1}, param => {update => 2});
995
$result = $dbi->execute("select * from ${q}table$p");
996
$rows   = $result->all;
997
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
998

            
999
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
1000
like($@, qr/safety/);
1001

            
1002
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1003
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1004
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
1005
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
1006
$dbi->insert(table => 'table', param => {select => 1});
1007
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
1008
$result = $dbi->execute("select * from ${q}table$p");
1009
$rows   = $result->all;
1010
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
1011

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

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

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

            
1047

            
1048
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1049
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1050
$dbi->execute($create_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});
1053
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1054
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1055
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1056
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1057

            
cleanup test
Yuki Kimoto authored on 2011-08-15
1058
$dbi->execute("delete from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1059
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1060
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1061
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1062
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1063
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1064
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1065
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1066

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1069
$dbi->delete_all(table => $table1);
1070
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1071
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1072
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
1073
$rows = $dbi->select(table => $table1)->all;
1074
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1075

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1090
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1091
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1092
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1093
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1094
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1095
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1096
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1097
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
1098
        {ke1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
1099
    ]
1100
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1101
$result = $dbi->select(table => $table1);
1102
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1103

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1104
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1105
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1106
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1107
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
1108
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1109
$rows   = $result->all;
1110
is_deeply($rows, [], "basic");
1111

            
1112
test 'delete error';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1113
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1114
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1115
eval{$dbi->delete(table => $table1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1116
like($@, qr/"where" must be specified/,
1117
         "where key-value pairs not specified");
1118

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1122
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
1123
$dbi = DBIx::Custom->connect;
1124
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1125
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1126
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
1127
$dbi->insert(table => 'table', param => {select => 1});
1128
$dbi->delete(table => 'table', where => {select => 1});
1129
$result = $dbi->execute("select * from ${q}table$p");
1130
$rows   = $result->all;
1131
is_deeply($rows, [], "reserved word");
1132

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

            
1143

            
1144
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1145
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1146
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1147
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1148
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1149
$rows = $dbi->select(table => $table1)->all;
1150
is_deeply($rows, [{$key1 => 1, $key2 => 2},
1151
                  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
1152

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1167
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1168
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1169
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
test cleanup
Yuki Kimoto authored on 2011-08-10
1170
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1171
    table => [$table1, $table2],
1172
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
1173
    where   => {"$table1.$key2" => 2},
1174
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1175
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1176
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
1177

            
1178
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1179
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1180
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1181
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1182
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1183
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
1184

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

            
1188
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
1189
eval { $dbi->execute("drop table ${q}table$p") };
1190
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1191
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
1192
$dbi->insert(table => 'table', param => {select => 1, update => 2});
1193
$result = $dbi->select(table => 'table', where => {select => 1});
1194
$rows   = $result->all;
1195
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
1196

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

            
1211
test 'filters';
1212
$dbi = DBIx::Custom->new;
1213

            
1214
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
1215
   'あ', "decode_utf8");
1216

            
1217
is($dbi->filters->{encode_utf8}->('あ'),
1218
   encode_utf8('あ'), "encode_utf8");
1219

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1220
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1221
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1222
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1223
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1224
$dbi->begin_work;
1225
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1226
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1227
$dbi->rollback;
1228
$dbi->dbh->{AutoCommit} = 1;
1229

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

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

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

            
1247
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1248
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1249
$dbi->execute($create_table1);
1250
{
1251
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1252
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1253
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1254
    like($@, qr/\.t /, "fail : not verbose");
1255
}
1256
{
1257
    local $Carp::Verbose = 1;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1258
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1259
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1260
}
1261

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

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

            
1270
{
1271
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1272
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1273
    like($@, qr/\Q.t /, "caller spec : not vebose");
1274
}
1275
{
1276
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1277
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1278
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1279
}
1280

            
1281

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1282
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1283
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1284
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1285
$dbi->execute($create_table1);
1286

            
1287
$dbi->begin_work;
1288

            
1289
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1290
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1291
    die "Error";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1292
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1293
};
1294

            
1295
$dbi->rollback if $@;
1296

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

            
1301
$dbi->begin_work;
1302

            
1303
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1304
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1305
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1306
};
1307

            
1308
$dbi->commit unless $@;
1309

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

            
1314
$dbi->dbh->{AutoCommit} = 0;
1315
eval{ $dbi->begin_work };
1316
ok($@, "exception");
1317
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1318

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

            
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
$dbi->{_cached} = {};
1331
$dbi->cache(0);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1332
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1333
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1334

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

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

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

            
1358
{
1359
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1360
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1361
    like($@, qr/\Q.t /, "caller spec : not vebose");
1362
}
1363
{
1364
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1365
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1366
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1367
}
1368

            
1369
test 'method';
1370
$dbi->method(
1371
    one => sub { 1 }
1372
);
1373
$dbi->method(
1374
    two => sub { 2 }
1375
);
1376
$dbi->method({
1377
    twice => sub {
1378
        my $self = shift;
1379
        return $_[0] * 2;
1380
    }
1381
});
1382

            
1383
is($dbi->one, 1, "first");
1384
is($dbi->two, 2, "second");
1385
is($dbi->twice(5), 10 , "second");
1386

            
1387
eval {$dbi->XXXXXX};
1388
ok($@, "not exists");
1389

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

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

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

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

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

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

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

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

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

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

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

            
1522
test 'each_column';
1523
$dbi = DBIx::Custom->connect;
1524
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1525
eval { $dbi->execute("drop table $table1") };
1526
eval { $dbi->execute("drop table $table2") };
1527
eval { $dbi->execute("drop table $table3") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1528
$dbi->execute($create_table1_type);
1529
$dbi->execute($create_table2);
1530

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

            
1557
$infos = [];
1558
$dbi->each_table(sub {
1559
    my ($self, $table, $table_info) = @_;
1560
    
1561
    if ($table =~ /^table\d/) {
1562
         my $info = [$table, $table_info->{TABLE_NAME}];
1563
         push @$infos, $info;
1564
    }
1565
});
1566
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
1567
is_deeply($infos, 
1568
    [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1569
        [$table1, $table1],
1570
        [$table2, $table2],
test cleanup
Yuki Kimoto authored on 2011-08-10
1571
    ]
1572
);
1573

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1588
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1589
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1590
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1591
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1592
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1593

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

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

            
1615
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1616
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1617
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1618
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1619
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1620
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1621
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1622
$row = $result->fetch_first;
1623
is_deeply($row, [6, 12]);
1624

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

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

            
1642
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1643
$dbi->apply_filter($table1,
1644
    $key1 => {end => sub { $_[0] * 3 } },
1645
    $key2 => {end => 'five_times'}
1646
);
1647
$result = $dbi->select(table => $table1);
1648
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1649
$result->filter($key1 => undef);
1650
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1651
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1652
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1653

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

            
1668
test 'empty where select';
1669
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1670
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1671
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1672
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1673
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1674
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1675
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1676

            
1677
test 'select query option';
1678
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1679
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1680
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1681
$query = $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1682
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1683
$query = $dbi->update(table => $table1, where => {$key1 => 1}, param => {$key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1684
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1685
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1686
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1687
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1688
is(ref $query, 'DBIx::Custom::Query');
1689

            
1690
test 'where';
1691
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1692
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1693
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1694
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1695
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1696
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1697
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1698

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

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

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

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

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

            
1740
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1741
             ->clause(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"])
1742
             ->param({$key1 => [0, 3], $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
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}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1749

            
1750
$where = $dbi->where;
1751
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1752
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1753
    where => $where
1754
);
1755
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1756
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1757

            
1758
eval {
1759
$where = $dbi->where
1760
             ->clause(['uuu']);
1761
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1762
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1763
    where => $where
1764
);
1765
};
1766
ok($@);
1767

            
1768
$where = $dbi->where;
1769
is("$where", '');
1770

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

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

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

            
1801
$where = $dbi->where
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1802
             ->clause("$key1 = :$key1")
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1803
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1804
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1805
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1806
    where => $where,
1807
);
1808
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1809
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1810

            
1811
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1812
             ->clause("$key1 = :$key1 $key2 = :$key2")
1813
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1814
eval{$where->to_string};
1815
like($@, qr/one column/);
1816

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

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

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

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

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

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

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

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

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

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

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

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

            
1937
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1938
             ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1939
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1940
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1941
    where => $where,
1942
);
1943
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1944
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1945

            
1946
eval {$dbi->where(ppp => 1) };
1947
like($@, qr/invalid/);
1948

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

            
1960

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

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

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

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

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

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

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

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

            
2037
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2038
$where->clause(['and', ":${key1}{=}"]);
2039
$where->param({$key1 => 7});
test cleanup
Yuki Kimoto authored on 2011-08-10
2040
$where->if(sub { ($_[0] || '') eq 5 });
2041
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2042
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
2043
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2044
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2045

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

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

            
2065
$where = $dbi->where;
2066
$where->param({id => '', author => '', price => ''});
2067
$where->if('length');
2068
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2069
    id => "$table1.id",
2070
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2071
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
test cleanup
Yuki Kimoto authored on 2011-08-10
2072
      {if => sub { $_[0] eq 1 }}]
2073
);
2074
is_deeply($where->param, {});
2075

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

            
2085
$where = $dbi->where;
2086
$where->param({price => 'a'});
2087
$where->if('length');
2088
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2089
    id => ["$table1.id", {if => 'exists'}],
2090
    price => ["$table1.price", sub { '%' . $_[0] }, {if => 'exists'}]
test cleanup
Yuki Kimoto authored on 2011-08-10
2091
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2092
is_deeply($where->param, {"$table1.price" => '%a'});
test cleanup
Yuki Kimoto authored on 2011-08-10
2093

            
2094
$where = $dbi->where;
2095
$where->param({id => [1, 2], author => 'Ken', price => 1900});
2096
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2097
    id => "$table1.id",
2098
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2099
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
2100
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2101
is_deeply($where->param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2102
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
2103

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

            
2115
$where = $dbi->where;
2116
$where->param({id => ['', ''], author => 'Ken', price => 1900});
2117
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2118
    id => ["$table1.id", {if => 'length'}],
2119
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, {if => 'defined'}],
2120
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
2121
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2122
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
2123
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
2124

            
2125
test 'dbi_option default';
2126
$dbi = DBIx::Custom->new;
2127
is_deeply($dbi->dbi_option, {});
2128

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

            
2136
test 'register_tag';
2137
$dbi = DBIx::Custom->connect;
2138
$dbi->register_tag(
2139
    b => sub { 2 }
2140
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2141
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2142

            
2143
test 'table not specify exception';
2144
$dbi = DBIx::Custom->connect;
2145
eval {$dbi->insert};
2146
like($@, qr/table/);
2147
eval {$dbi->update};
2148
like($@, qr/table/);
2149
eval {$dbi->delete};
2150
like($@, qr/table/);
2151
eval {$dbi->select};
2152
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
2153

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2154
test 'more tests';
2155
$dbi = DBIx::Custom->connect;
2156
eval{$dbi->apply_filter('table', 'column', [])};
2157
like($@, qr/apply_filter/);
2158

            
2159
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
2160
like($@, qr/apply_filter/);
2161

            
2162
$dbi->apply_filter(
2163

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

            
2175
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2176
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2177
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2178
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2179
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
2180
$dbi->apply_filter($table1, $key2, {});
2181
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
2182
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2183

            
2184
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2185
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2186
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2187
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2188
like($@, qr/not registered/);
2189
$dbi->method({one => sub { 1 }});
2190
is($dbi->one, 1);
2191

            
2192
eval{DBIx::Custom->connect(dsn => undef)};
2193
like($@, qr/_connect/);
2194

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

            
2207
$dbi->register_filter(one => sub { });
2208
$dbi->default_fetch_filter('one');
2209
ok($dbi->default_fetch_filter);
2210
$dbi->default_bind_filter('one');
2211
ok($dbi->default_bind_filter);
2212
eval{$dbi->default_fetch_filter('no')};
2213
like($@, qr/not registered/);
2214
eval{$dbi->default_bind_filter('no')};
2215
like($@, qr/not registered/);
2216
$dbi->default_bind_filter(undef);
2217
ok(!defined $dbi->default_bind_filter);
2218
$dbi->default_fetch_filter(undef);
2219
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2220
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2221
like($@, qr/Tag not finished/);
2222

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

            
2237
test 'dbi_option';
2238
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2239
ok($dbi->dbh->{PrintError});
2240
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2241
ok($dbi->dbh->{PrintError});
2242

            
2243
test 'DBIx::Custom::Result stash()';
2244
$result = DBIx::Custom::Result->new;
2245
is_deeply($result->stash, {}, 'default');
2246
$result->stash->{foo} = 1;
2247
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2248

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2249
test 'delete_at';
2250
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2251
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2252
$dbi->execute($create_table1_2);
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, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2257
    where => [1, 2],
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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2261
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2262
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2263
    table => $table1,
2264
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2265
    where => 1,
2266
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2267
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2268

            
2269
test 'insert_at';
2270
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2271
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2272
$dbi->execute($create_table1_2);
2273
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2274
    primary_key => [$key1, $key2], 
2275
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2276
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2277
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2278
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2279
is($dbi->select(table => $table1)->one->{$key1}, 1);
2280
is($dbi->select(table => $table1)->one->{$key2}, 2);
2281
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2282

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2283
$dbi->delete_all(table => $table1);
2284
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2285
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2286
    primary_key => $key1, 
2287
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2288
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2289
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2290
);
2291

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

            
2296
eval {
2297
    $dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2298
        table => $table1,
2299
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2300
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2301
        param => {$key1 => 1, $key2 => 2, $key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2302
    );
2303
};
2304
like($@, qr/must be/);
2305

            
2306
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2307
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2308
$dbi->execute($create_table1_2);
2309
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2310
    {$key3 => 3},
2311
    primary_key => [$key1, $key2], 
2312
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2313
    where => [1, 2],
2314
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2315
is($dbi->select(table => $table1)->one->{$key1}, 1);
2316
is($dbi->select(table => $table1)->one->{$key2}, 2);
2317
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2318

            
2319
test 'update_at';
2320
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2321
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2322
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2323
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2324
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2325
    table => $table1,
2326
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2327
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2328
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2329
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2330
is($dbi->select(table => $table1)->one->{$key1}, 1);
2331
is($dbi->select(table => $table1)->one->{$key2}, 2);
2332
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2333

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2334
$dbi->delete_all(table => $table1);
2335
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2336
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2337
    table => $table1,
2338
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2339
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2340
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2341
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2342
is($dbi->select(table => $table1)->one->{$key1}, 1);
2343
is($dbi->select(table => $table1)->one->{$key2}, 2);
2344
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2345

            
2346
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2347
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2348
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2349
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2350
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2351
    {$key3 => 4},
2352
    table => $table1,
2353
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2354
    where => [1, 2]
2355
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2356
is($dbi->select(table => $table1)->one->{$key1}, 1);
2357
is($dbi->select(table => $table1)->one->{$key2}, 2);
2358
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2359

            
2360
test 'select_at';
2361
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2362
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2363
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2364
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2365
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2366
    table => $table1,
2367
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2368
    where => [1, 2]
2369
);
2370
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2371
is($row->{$key1}, 1);
2372
is($row->{$key2}, 2);
2373
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2374

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2387
$dbi->delete_all(table => $table1);
2388
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2389
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2390
    table => $table1,
2391
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2392
    where => [1, 2]
2393
);
2394
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2395
is($row->{$key1}, 1);
2396
is($row->{$key2}, 2);
2397
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2398

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

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

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

            
2427
eval {
2428
    $result = $dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2429
        table => $table1,
2430
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2431
        where => {},
2432
    );
2433
};
2434
like($@, qr/must be/);
2435

            
2436
test 'columns';
2437
use MyDBI1;
2438
$dbi = MyDBI1->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2439
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2440

            
2441

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

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

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

            
2489
test 'model select_at';
2490
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2491
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2492
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2493
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2494
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2495
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2496
is($row->{$key1}, 1);
2497
is($row->{$key2}, 2);
2498
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2499

            
2500

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

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

            
2532
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2533
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2534
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2535
$param = {$key1 => 1, $key2 => 2};
test cleanup
Yuki Kimoto authored on 2011-08-10
2536
$insert_param = $dbi->insert_param($param);
2537
$sql = <<"EOS";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2538
insert into $table1 $insert_param
test cleanup
Yuki Kimoto authored on 2011-08-10
2539
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2540
$dbi->execute($sql, param => $param, table => $table1);
2541
is($dbi->select(table => $table1)->one->{$key1}, 1);
2542
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2543

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

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

            
2566
$result = $model->select_at(
2567
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2568
        $model->mycolumn([$key1]),
2569
        $model->column($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
$result = $model->select_at(
2575
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2576
        $model->mycolumn([$key1]),
2577
        {$table2 => [$key1]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2578
    ]
2579
);
2580
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2581
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2582

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

            
2592
$result = $model->select_at(
2593
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2594
        $model->mycolumn([$key1]),
2595
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2596
    ]
2597
);
2598
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2599
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2600

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2601
test 'merge_param';
2602
$dbi = DBIx::Custom->new;
2603
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2604
    {$key1 => 1, $key2 => 2, $key3 => 3},
2605
    {$key1 => 1, $key2 => 2},
2606
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2607
];
2608
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2609
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2610

            
2611
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2612
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2613
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2614
];
2615
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2616
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
2617

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

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

            
2651
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2652
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2653
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2654
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2655
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2656
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2657
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2658
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2659
        "$key1 = :$key1 and $key2 = :$key2",
2660
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2661
    ]
2662
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2663
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2664

            
2665
test 'delete() string where';
2666
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2667
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2668
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2669
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2670
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2671
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2672
    table => $table1,
2673
    where => "$key1 = :$key1 and $key2 = :$key2",
2674
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2675
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2676
$rows = $dbi->select(table => $table1)->all;
2677
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2678

            
2679
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2680
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2681
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2682
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2683
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2684
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2685
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2686
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2687
        "$key1 = :$key1 and $key2 = :$key2",
2688
         {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2689
    ]
2690
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2691
$rows = $dbi->select(table => $table1)->all;
2692
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2693

            
2694

            
2695
test 'update() string where';
2696
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2697
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2698
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2699
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2700
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2701
    table => $table1,
2702
    param => {$key1 => 5},
2703
    where => "$key1 = :$key1 and $key2 = :$key2",
2704
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2705
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2706
$rows = $dbi->select(table => $table1)->all;
2707
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2708

            
2709
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2710
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2711
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2712
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2713
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2714
    table => $table1,
2715
    param => {$key1 => 5},
cleanup test
Yuki Kimoto authored on 2011-08-10
2716
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2717
        "$key1 = :$key1 and $key2 = :$key2",
2718
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2719
    ]
2720
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2721
$rows = $dbi->select(table => $table1)->all;
2722
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2723

            
2724
test 'insert id and primary_key option';
2725
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2726
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2727
$dbi->execute($create_table1_2);
2728
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2729
    primary_key => [$key1, $key2], 
2730
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2731
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2732
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2733
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2734
is($dbi->select(table => $table1)->one->{$key1}, 1);
2735
is($dbi->select(table => $table1)->one->{$key2}, 2);
2736
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2737

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2738
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2739
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2740
    primary_key => $key1, 
2741
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2742
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2743
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2744
);
2745

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

            
2750
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2751
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2752
$dbi->execute($create_table1_2);
2753
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2754
    {$key3 => 3},
2755
    primary_key => [$key1, $key2], 
2756
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2757
    id => [1, 2],
2758
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2759
is($dbi->select(table => $table1)->one->{$key1}, 1);
2760
is($dbi->select(table => $table1)->one->{$key2}, 2);
2761
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2762

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2763
test 'model insert id and primary_key option';
2764
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2765
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2766
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2767
$dbi->model($table1)->insert(
cleanup test
Yuki Kimoto authored on 2011-08-10
2768
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2769
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2770
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2771
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2772
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2773
is($row->{$key1}, 1);
2774
is($row->{$key2}, 2);
2775
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2776

            
2777
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2778
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2779
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2780
$dbi->model($table1)->insert(
2781
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2782
    id => [1, 2]
2783
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2784
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2785
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2786
is($row->{$key1}, 1);
2787
is($row->{$key2}, 2);
2788
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2789

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2805
$dbi->delete_all(table => $table1);
2806
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2807
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2808
    table => $table1,
2809
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2810
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2811
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2812
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2813
is($dbi->select(table => $table1)->one->{$key1}, 0);
2814
is($dbi->select(table => $table1)->one->{$key2}, 2);
2815
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2816

            
2817
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2818
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2819
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2820
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2821
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2822
    {$key3 => 4},
2823
    table => $table1,
2824
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2825
    id => [1, 2]
2826
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2827
is($dbi->select(table => $table1)->one->{$key1}, 1);
2828
is($dbi->select(table => $table1)->one->{$key2}, 2);
2829
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2830

            
2831

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

            
2847

            
2848
test 'delete and id option';
2849
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2850
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2851
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2852
$dbi->insert(table => $table1, param => {$key1 => 1, $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, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2856
    id => [1, 2],
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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2860
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2861
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2862
    table => $table1,
2863
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2864
    id => 0,
2865
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2866
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2867

            
2868

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

            
2887

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2915
$dbi->delete_all(table => $table1);
2916
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2917
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2918
    table => $table1,
2919
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2920
    id => [1, 2]
2921
);
2922
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2923
is($row->{$key1}, 1);
2924
is($row->{$key2}, 2);
2925
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2926

            
2927

            
2928
test 'model select_at';
2929
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2930
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2931
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2932
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2933
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2934
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2935
is($row->{$key1}, 1);
2936
is($row->{$key2}, 2);
2937
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2938

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

            
2956
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2957
    column => [$model->column($table2 => [$key1, $key3])],
2958
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2959
);
2960
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2961
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2962

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2963
test 'separator';
2964
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2965
eval { $dbi->execute("drop table $table1") };
2966
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2967
$dbi->execute($create_table1);
2968
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2969

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3008
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3009
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3010
$result = $model->select(
3011
    column => [
3012
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3013
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
3014
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3015
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3016
);
3017
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3018
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
3019
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3020

            
3021

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3022
test 'filter_off';
3023
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3024
eval { $dbi->execute("drop table $table1") };
3025
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3026
$dbi->execute($create_table1);
3027
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
3028

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3029
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3030
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
3031
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3032
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
3033
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3034
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
3035
);
3036
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3037
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3038
$model = $dbi->model($table1);
3039
$result = $model->select(column => $key1);
3040
$result->filter($key1 => sub { $_[0] * 2 });
3041
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
3042

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3043
test 'available_datetype';
3044
$dbi = DBIx::Custom->connect;
3045
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
3046

            
3047

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3048
test 'select prefix option';
3049
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3050
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3051
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3052
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3053
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3054
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
3055

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3092
$param = $dbi->map_param(
3093
    {price => 'a'},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3094
    id => ["$table1.id", {if => 'exists'}],
3095
    price => ["$table1.price", sub { '%' . $_[0] }, {if => 'exists'}]
cleanup test
Yuki Kimoto authored on 2011-08-10
3096
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3097
is_deeply($param, {"$table1.price" => '%a'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3098

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

            
3117
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3118
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3119
$result = $dbi->select(table => $table1,
3120
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3121
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3122
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
3123
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
3124
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
3125
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3126

            
3127
test 'tag_parse';
3128
$dbi = DBIx::Custom->connect;
3129
$dbi->tag_parse(0);
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);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3132
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3133
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3134
ok($@);
3135

            
3136
test 'last_sql';
3137
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3138
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3139
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3140
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
3141
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3142

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

            
3146
test 'DBIx::Custom header';
3147
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3148
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3149
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3150
$result = $dbi->execute("select $key1 as h1, $key2 as h2 from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3151
is_deeply($result->header, [qw/h1 h2/]);
3152

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3174
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3175
$result = $dbi->execute(
3176
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3177
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3178
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3179
);
3180
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3181
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3182

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

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

            
3226
test 'result';
3227
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3228
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3229
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3230
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3231
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3232

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3240
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3241
@rows = ();
3242
while (my $row = $result->fetch_hash) {
3243
    push @rows, {%$row};
3244
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3245
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3246

            
3247
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3248
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3249
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3250
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3251
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3252

            
3253
test 'fetch_all';
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
$rows = $result->fetch_all;
3256
is_deeply($rows, [[1, 2], [3, 4]]);
3257

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

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

            
3266
$rows = $result->fetch_all;
3267
is_deeply($rows, [[3, 2], [9, 4]], "array");
3268

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

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

            
3311
for (my $i = 0; $i < @$datas; $i++) {
3312
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3313
    my $dbi = DBIx::Custom->new;
3314
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3315
    my $query = $builder->build_query($data->{source});
3316
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3317
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3318
}
3319

            
cleanup
Yuki Kimoto authored on 2011-08-13
3320
$dbi = DBIx::Custom->new;
3321
$builder = $dbi->query_builder;
3322
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3323
    p => sub {
3324
        my @args = @_;
3325
        
3326
        my $expand    = "? $args[0] $args[1]";
3327
        my $columns = [2];
3328
        return [$expand, $columns];
3329
    }
3330
);
3331

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3342
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3343
    q => 'string'
3344
});
3345

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3349
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3350
   r => sub {} 
3351
});
3352

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3363
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3364
    t => sub {return ["a", []]}
3365
);
3366

            
3367

            
cleanup
Yuki Kimoto authored on 2011-08-13
3368
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3369
    a => sub {
3370
        return ["? ? ?", ['']];
3371
    }
3372
);
3373
eval{$builder->build_query("{a}")};
3374
like($@, qr/\QPlaceholder count/, "placeholder count is invalid");
3375

            
3376

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

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

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

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

            
3392
test 'variouse source';
cleanup test
Yuki Kimoto authored on 2011-08-15
3393
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
test cleanup
Yuki Kimoto authored on 2011-08-10
3394
$query = $builder->build_query($source);
cleanup test
Yuki Kimoto authored on 2011-08-15
3395
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3396

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3397
$source = "abc";
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, 'abc', "basic : 2");
test cleanup
Yuki Kimoto authored on 2011-08-10
3400

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3405
$source = "000";
test cleanup
Yuki Kimoto authored on 2011-08-10
3406
$query = $builder->build_query($source);
cleanup test
Yuki Kimoto authored on 2011-08-15
3407
is($query->sql, '000', "contain 0 value");
test cleanup
Yuki Kimoto authored on 2011-08-10
3408

            
3409
$source = "a {= b} }";
3410
eval{$builder->build_query($source)};
3411
like($@, qr/unexpected "}"/, "error : 1");
3412

            
3413
$source = "a {= {}";
3414
eval{$builder->build_query($source)};
3415
like($@, qr/unexpected "{"/, "error : 2");
3416

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3430
eval {
3431
$dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3432
    table => $table1,
3433
    column => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
3434
    wrap => 'select * from ('
3435
)
3436
};
3437
like($@, qr/array/);
3438

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3456
test 'dbi method from model';
3457
$dbi = MyDBI9->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3458
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3459
$dbi->execute($create_table1);
3460
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3461
$model = $dbi->model($table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3462
eval{$model->execute("select * from $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-10
3463
ok(!$@);
3464

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

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

            
3494
$dbi->separator('-');
3495
$result = $model->select(
3496
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3497
        $model->column($table2, {alias => $table2_alias})
cleanup test
Yuki Kimoto authored on 2011-08-10
3498
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3499
    where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
3500
);
3501
is_deeply($result->one, 
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3502
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-10
3503

            
3504
test 'create_model';
3505
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3506
eval { $dbi->execute("drop table $table1") };
3507
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3508
$dbi->execute($create_table1);
3509
$dbi->execute($create_table2);
3510

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

            
3539
test 'model method';
3540
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3541
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3542
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3543
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
3544
$model = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3545
    table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-10
3546
);
3547
$model->method(foo => sub { shift->select(@_) });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3548
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
3549

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

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

            
3570

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

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

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

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

            
3609
            
3610
eval { $dbi->update_param({";" => 1}) };
3611
like($@, qr/not safety/);
3612

            
3613

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

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

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

            
3654
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3655
    table => $table1,
3656
    where   => {$key1 => 1},
3657
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
3658
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3659
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3660

            
3661
eval {
3662
    $rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3663
        table => $table1,
3664
        column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3665
        where   => {"$table1.$key2" => 2},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3666
        join  => {"$table1.$key1" => "$table2.$key1"}
cleanup test
Yuki Kimoto authored on 2011-08-10
3667
    );
3668
};
3669
like ($@, qr/array/);
3670

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

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

            
3688
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3689
    column => "$table1.$key1 as ${table1}__$key1",
3690
    table => $table1,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3691
    where   => {"$table3.$key4" => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3692
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3693
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
cleanup test
Yuki Kimoto authored on 2011-08-10
3694
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3695
is_deeply($rows, [{"${table1}__$key1" => 1}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3696

            
3697
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3698
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3699
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3700
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3701
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3702
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3703
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-10
3704
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3705
    table => $table1,
3706
    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",
3707
    where   => {"$table1.$key2" => 2},
3708
    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
3709
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3710
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
cleanup test
Yuki Kimoto authored on 2011-08-10
3711
          'quote');
3712

            
3713

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

            
3735
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3736
eval { $dbi->execute("drop table $table1") };
3737
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3738
$dbi->execute($create_table1);
3739
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3740
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3741
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
3742
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-10
3743
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3744
    table => $table1,
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.$key2 = '4' and $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
3747
    ]
3748
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3749
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
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 $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
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
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3759
    table => $table1,
3760
    column => [{$table2 => [$key3]}],
cleanup test
Yuki Kimoto authored on 2011-08-10
3761
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3762
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
cleanup test
Yuki Kimoto authored on 2011-08-10
3763
    ]
3764
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3765
is_deeply($result->all, [{"$table2.$key3" => 4}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3766

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

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

            
3803
$dbi = MyDBI4->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3804
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3805
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3806
$model = $dbi->model($table1);
3807
$model->insert({$key1 => 'a', $key2 => 'b'});
3808
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3809
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3810
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3811
$model = $dbi->model($table2);
3812
$model->insert({$key1 => 'a'});
3813
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
test cleanup
Yuki Kimoto authored on 2011-08-10
3814

            
3815
$dbi = MyDBI5->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3816
eval { $dbi->execute("drop table $table1") };
3817
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3818
$dbi->execute($create_table1);
3819
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3820
$model = $dbi->model($table2);
3821
$model->insert({$key1 => 'a'});
3822
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3823
$dbi->insert(table => $table1, param => {$key1 => 1});
3824
$model = $dbi->model($table1);
3825
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
test cleanup
Yuki Kimoto authored on 2011-08-10
3826

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

            
3834
test 'columns';
3835
use MyDBI1;
3836
$dbi = MyDBI1->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3837
$model = $dbi->model($table1);
3838
$model->columns([$key1, $key2]);
3839
is_deeply($model->columns, [$key1, $key2]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3840

            
3841
test 'setup_model';
3842
use MyDBI1;
3843
$dbi = MyDBI1->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3844
eval { $dbi->execute("drop table $table1") };
3845
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3846

            
3847
$dbi->execute($create_table1);
3848
$dbi->execute($create_table2);
3849
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3850
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3851
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3852

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

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

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