DBIx-Custom / t / common.t /
Newer Older
3842 lines | 126.586kb
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);
215
$dbi->type_rule(
216
    into1 => {
217
        $date_typename => sub { '2010-' . $_[0] }
218
    }
219
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
220
$dbi->insert({$key1 => '01-01'}, table => $table1);
221
$result = $dbi->select(table => $table1);
222
like($result->one->{$key1}, qr/^2010-01-01/);
test cleanup
Yuki Kimoto authored on 2011-08-10
223

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

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

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

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

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

            
329

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

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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
415
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
416
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
417
$dbi->execute($create_table1_type);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
418
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
test cleanup
Yuki Kimoto authored on 2011-08-10
419
$dbi->type_rule(
420
    into1 => {
421
        $date_typename => 'ppp'
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);
426
like($result->one->{$key1}, qr/^2010-01-04/);
test cleanup
Yuki Kimoto authored on 2011-08-10
427

            
test cleanup
Yuki Kimoto authored on 2011-08-10
428
eval{$dbi->type_rule(
429
    into1 => {
430
        $date_typename => 'pp'
431
    }
432
)};
433
like($@, qr/not registered/);
test cleanup
Yuki Kimoto authored on 2011-08-10
434

            
test cleanup
Yuki Kimoto authored on 2011-08-10
435
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
436
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
437
$dbi->execute($create_table1_type);
438
eval {
439
    $dbi->type_rule(
440
        from1 => {
441
            Date => sub { $_[0] * 2 },
442
        }
443
    );
444
};
445
like($@, qr/lower/);
test cleanup
Yuki Kimoto authored on 2011-08-10
446

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

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

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

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

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

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

            
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
520
$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
521
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
522
$result->type_rule(
523
    from1 => [$date_datatype => 'five']
524
);
525
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
526
like($row->{$key1}, qr/^2010-01-05/);
527
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
test cleanup
Yuki Kimoto authored on 2011-08-10
528

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

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

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

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

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

            
632

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

            
634
# Create table
test cleanup
Yuki Kimoto authored on 2011-08-10
635
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
636
eval { $dbi->execute('drop table $table1') };
added common test executing ...
Yuki Kimoto authored on 2011-08-07
637
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
638
$model = $dbi->create_model(table => $table1);
639
$model->insert({$key1 => 1, $key2 => 2});
640
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]);
added common test executing ...
Yuki Kimoto authored on 2011-08-07
641

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

            
650
@rows = ();
651
while (my $row = $result->fetch) {
652
    push @rows, [@$row];
653
}
654
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
655

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

            
663
$result = $dbi->execute($query);
664
$rows = $result->fetch_all;
665
is_deeply($rows, [[1, 2], [3, 4]], "fetch_all");
666

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

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

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

            
685
test 'Filter basic';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
686
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-08
687
$dbi->register_filter(twice       => sub { $_[0] * 2}, 
688
                    three_times => sub { $_[0] * 3});
689

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-08
710
test 'DBIx::Custom::SQLTemplate basic tag';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
711
$dbi->execute('drop table $table1');
cleanup test
Yuki Kimoto authored on 2011-08-08
712
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
713
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
714
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
715

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

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

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

            
734
test 'DIB::Custom::SQLTemplate in tag';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
735
$dbi->execute('drop table $table1');
cleanup test
Yuki Kimoto authored on 2011-08-08
736
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
737
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
738
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
739

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
764
$result = $dbi->execute("select * from $table1 order by $key1;");
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 => 1, $key3 => 1, $key4 => 1, $key5 => 5},
767
                  {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-08
768

            
cleanup test
Yuki Kimoto authored on 2011-08-08
769
test 'Named placeholder';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
770
$dbi->execute('drop table $table1');
cleanup test
Yuki Kimoto authored on 2011-08-08
771
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
772
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
773
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
774

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
799
$dbi->execute('drop table $table1');
cleanup test
Yuki Kimoto authored on 2011-08-08
800
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
801
$dbi->insert(table => $table1, param => {$key1 => '2011-10-14 12:19:18', $key2 => 2});
802
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
803
$result = $dbi->execute(
804
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
805
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
806
);
807

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
812
$dbi->delete_all(table => $table1);
813
$dbi->insert(table => $table1, param => {$key1 => 'a:b c:d', $key2 => 2});
814
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
815
$result = $dbi->execute(
816
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
817
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
818
);
819
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
820
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
821

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
829
test 'insert';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
830
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
831
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
832
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
833
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
834
$result = $dbi->execute("select * from $table1;");
cleanup test
Yuki Kimoto authored on 2011-08-10
835
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
836
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
837

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
850
$dbi->execute('drop table $table1');
cleanup test
Yuki Kimoto authored on 2011-08-10
851
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
852
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, append => '   ');
853
$rows = $dbi->select(table => $table1)->all;
854
is_deeply($rows, [{$key1 => 1, $key2 => 2}], 'insert append');
cleanup test
Yuki Kimoto authored on 2011-08-10
855

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

            
859
eval{$dbi->insert(table => 'table', param => {';' => 1})};
860
like($@, qr/safety/);
861

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
870
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
871
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
872
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
873
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
874
$result = $dbi->execute("select * from $table1;");
cleanup test
Yuki Kimoto authored on 2011-08-10
875
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
876
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
877

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
935
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
936
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
937
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
938
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
939
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
940
$where->param({$key1 => 1, $key2 => 2});
941
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
942
$result = $dbi->select(table => $table1);
943
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
944

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
975
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
976
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
977
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
978
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
979
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
980
$dbi->insert(table => 'table', param => {select => 1});
981
$dbi->update(table => 'table', where => {select => 1}, param => {update => 2});
982
$result = $dbi->execute("select * from ${q}table$p");
983
$rows   = $result->all;
984
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
985

            
986
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
987
like($@, qr/safety/);
988

            
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 => {'table.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

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

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

            
1021
test 'update_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1022
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1023
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1024
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
1025
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
1026
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1027
$dbi->update_all(table => $table1, param => {$key2 => 10}, filter => {$key2 => 'twice'});
1028
$result = $dbi->execute("select * from $table1;");
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 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
1031
                  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
1032
                  "filter");
1033

            
1034

            
1035
test 'delete';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1036
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1037
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1038
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1039
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1040
$dbi->delete(table => $table1, where => {$key1 => 1});
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 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1044

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1091
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1092
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1093
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1094
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
1095
$result = $dbi->execute("select * from $table1;");
test cleanup
Yuki Kimoto authored on 2011-08-10
1096
$rows   = $result->all;
1097
is_deeply($rows, [], "basic");
1098

            
1099
test 'delete error';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1100
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1101
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1102
eval{$dbi->delete(table => $table1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1103
like($@, qr/"where" must be specified/,
1104
         "where key-value pairs not specified");
1105

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

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

            
1120
test 'delete_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1121
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1122
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1123
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1124
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1125
$dbi->delete_all(table => $table1);
1126
$result = $dbi->execute("select * from $table1;");
test cleanup
Yuki Kimoto authored on 2011-08-10
1127
$rows   = $result->all;
1128
is_deeply($rows, [], "basic");
1129

            
1130

            
1131
test 'select';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1132
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1133
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1134
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1135
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1136
$rows = $dbi->select(table => $table1)->all;
1137
is_deeply($rows, [{$key1 => 1, $key2 => 2},
1138
                  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
1139

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

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

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

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

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

            
1165
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1166
    table => [$table1, $table2],
1167
    column => ["$table1.$key1 as ${table1}_$key1', '${table2}.$key1 as ${table2}_$key1", $key2, $key3],
1168
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1169
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1170
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
1171

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

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

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

            
1198
test 'filters';
1199
$dbi = DBIx::Custom->new;
1200

            
1201
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
1202
   'あ', "decode_utf8");
1203

            
1204
is($dbi->filters->{encode_utf8}->('あ'),
1205
   encode_utf8('あ'), "encode_utf8");
1206

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1207
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1208
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1209
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1210
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1211
$dbi->begin_work;
1212
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1213
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1214
$dbi->rollback;
1215
$dbi->dbh->{AutoCommit} = 1;
1216

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

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

            
1221
$dbi = DBIx::Custom->connect;
test cleanup in progress
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});
1227
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1228
$dbi->commit;
1229
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1230
$result = $dbi->select(table => $table1);
1231
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1232
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1233

            
1234
test 'execute';
test cleanup in progress
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);
1237
{
1238
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1239
    eval{$dbi->execute('select * frm $table1')};
1240
    like($@, qr/\Qselect * frm $table1;/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1241
    like($@, qr/\.t /, "fail : not verbose");
1242
}
1243
{
1244
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1245
    eval{$dbi->execute('select * frm $table1')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1246
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1247
}
1248

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

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

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

            
1268

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1269
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1270
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1271
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1272
$dbi->execute($create_table1);
1273

            
1274
$dbi->begin_work;
1275

            
1276
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1277
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1278
    die "Error";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1279
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1280
};
1281

            
1282
$dbi->rollback if $@;
1283

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

            
1288
$dbi->begin_work;
1289

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

            
1295
$dbi->commit unless $@;
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;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1299
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1300

            
1301
$dbi->dbh->{AutoCommit} = 0;
1302
eval{ $dbi->begin_work };
1303
ok($@, "exception");
1304
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1305

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1306
test 'cache';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1307
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1308
$dbi->cache(1);
1309
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1310
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2;";
test cleanup
Yuki Kimoto authored on 2011-08-10
1311
$dbi->execute($source, {}, query => 1);
1312
is_deeply($dbi->{_cached}->{$source}, 
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1313
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?;", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1314

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1315
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1316
$dbi->execute($create_table1);
1317
$dbi->{_cached} = {};
1318
$dbi->cache(0);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1319
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1320
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1321

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

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

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

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

            
1356
test 'method';
1357
$dbi->method(
1358
    one => sub { 1 }
1359
);
1360
$dbi->method(
1361
    two => sub { 2 }
1362
);
1363
$dbi->method({
1364
    twice => sub {
1365
        my $self = shift;
1366
        return $_[0] * 2;
1367
    }
1368
});
1369

            
1370
is($dbi->one, 1, "first");
1371
is($dbi->two, 2, "second");
1372
is($dbi->twice(5), 10 , "second");
1373

            
1374
eval {$dbi->XXXXXX};
1375
ok($@, "not exists");
1376

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

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

            
1410
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1411
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1412
$dbi->execute($create_table1);
1413
$dbi->register_filter(twice => sub { $_[0] * 2 });
1414
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1415
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1416
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1417
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => undef});
1418
$dbi->update(table => $table1, param => {$key1 => 2}, where => {$key2 => 2});
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 => 4, $key2 => 2}, "update");
test cleanup
Yuki Kimoto authored on 2011-08-10
1422

            
1423
$dbi = DBIx::Custom->connect;
test cleanup in progress
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 => 2, $key2 => 2}, filter => {$key1=> undef});
1431
$dbi->delete(table => $table1, where => {$key1 => 1});
1432
$result = $dbi->execute("select * from $table1;");
test cleanup
Yuki Kimoto authored on 2011-08-10
1433
$rows   = $result->all;
1434
is_deeply($rows, [], "delete");
1435

            
1436
$dbi = DBIx::Custom->connect;
test cleanup in progress
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
$result = $dbi->select(table => $table1, where => {$key1 => 1});
1445
$result->filter({$key2 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1446
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1447
is_deeply($rows, [{$key1 => 4, $key2 => 4}], "select");
test cleanup
Yuki Kimoto authored on 2011-08-10
1448

            
1449
$dbi = DBIx::Custom->connect;
test cleanup in progress
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->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2;",
1458
                        param => {$key1 => 1, $key2 => 2},
1459
                        table => [$table1]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1460
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1461
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute");
test cleanup
Yuki Kimoto authored on 2011-08-10
1462

            
1463
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1464
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1465
$dbi->execute($create_table1);
1466
$dbi->register_filter(twice => sub { $_[0] * 2 });
1467
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1468
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1469
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1470
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
1471
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2;",
1472
                        param => {$key1 => 1, $key2 => 2});
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 table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1475

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

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

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

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

            
1509
test 'each_column';
1510
$dbi = DBIx::Custom->connect;
1511
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1512
eval { $dbi->execute('drop table $table1') };
1513
eval { $dbi->execute('drop table $table2') };
1514
eval { $dbi->execute('drop table $table3') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1515
$dbi->execute($create_table1_type);
1516
$dbi->execute($create_table2);
1517

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

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

            
1561
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1562
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1563
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1564
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1565
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1566
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1567

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1575
$dbi = DBIx::Custom->connect;
test cleanup in progress
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

            
1581
test 'end_filter';
1582
$dbi = DBIx::Custom->connect;
test cleanup in progress
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
$result = $dbi->select(table => $table1);
1587
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1588
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1589
$row = $result->fetch_first;
1590
is_deeply($row, [6, 40]);
1591

            
1592
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1593
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1594
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1595
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1596
$result = $dbi->select(table => $table1);
1597
$result->filter([qw/$key1 $key2/] => sub { $_[0] * 2 });
1598
$result->end_filter([[qw/$key1 $key2/] => sub { $_[0] * 3 }]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1599
$row = $result->fetch_first;
1600
is_deeply($row, [6, 12]);
1601

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

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

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

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

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

            
1655
test 'empty where select';
1656
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1657
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1658
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1659
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1660
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1661
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1662
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1663

            
1664
test 'select query option';
1665
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1666
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
1667
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1668
$query = $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1669
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1670
$query = $dbi->update(table => $table1, where => {$key1 => 1}, param => {$key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1671
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1672
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1673
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1674
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1675
is(ref $query, 'DBIx::Custom::Query');
1676

            
1677
test 'where';
1678
$dbi = DBIx::Custom->connect;
test cleanup in progress
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
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1682
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1683
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1684
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1685

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

            
1690
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1691
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1692
    where => $where
1693
);
1694
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1695
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1696

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

            
1707
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1708
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1709
             ->param({$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
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 => $where
1713
);
1714
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1715
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1716

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

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

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

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

            
1755
$where = $dbi->where;
1756
is("$where", '');
1757

            
1758
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1759
             ->clause(['or', ("$key1 = :$key1") x 2])
1760
             ->param({$key1 => [1, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
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
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1766
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1767

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1933
eval {$dbi->where(ppp => 1) };
1934
like($@, qr/invalid/);
1935

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

            
1947

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

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

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

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

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

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

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

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

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

            
2033
$where = $dbi->where;
2034
$where->param({id => 1, author => 'Ken', price => 1900});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2035
$where->map(id => '$table1.id',
2036
    author => ['$table1.author', sub { '%' . $_[0] . '%' }],
2037
    price => ['$table1.price', {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
2038
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2039
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2040
  '$table1.price' => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
2041

            
2042
$where = $dbi->where;
2043
$where->param({id => 0, author => 0, price => 0});
2044
$where->map(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2045
    id => '$table1.id',
2046
    author => ['$table1.author', sub { '%' . $_[0] . '%' }],
2047
    price => ['$table1.price', sub { '%' . $_[0] . '%' },
test cleanup
Yuki Kimoto authored on 2011-08-10
2048
      {if => sub { $_[0] eq 0 }}]
2049
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2050
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
test cleanup
Yuki Kimoto authored on 2011-08-10
2051

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

            
2063
$where = $dbi->where;
2064
$where->param({id => undef, author => undef, price => undef});
2065
$where->if('length');
2066
$where->map(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2067
    id => '$table1.id',
2068
    price => ['$table1.price', {if => 'exists'}]
test cleanup
Yuki Kimoto authored on 2011-08-10
2069
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2070
is_deeply($where->param, {'$table1.price' => undef});
test cleanup
Yuki Kimoto authored on 2011-08-10
2071

            
2072
$where = $dbi->where;
2073
$where->param({price => 'a'});
2074
$where->if('length');
2075
$where->map(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2076
    id => ['$table1.id', {if => 'exists'}],
2077
    price => ['$table1.price', sub { '%' . $_[0] }, {if => 'exists'}]
test cleanup
Yuki Kimoto authored on 2011-08-10
2078
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2079
is_deeply($where->param, {'$table1.price' => '%a'});
test cleanup
Yuki Kimoto authored on 2011-08-10
2080

            
2081
$where = $dbi->where;
2082
$where->param({id => [1, 2], author => 'Ken', price => 1900});
2083
$where->map(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2084
    id => '$table1.id',
2085
    author => ['$table1.author', sub { '%' . $_[0] . '%' }],
2086
    price => ['$table1.price', {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
2087
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2088
is_deeply($where->param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
2089
  '$table1.price' => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
2090

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

            
2102
$where = $dbi->where;
2103
$where->param({id => ['', ''], author => 'Ken', price => 1900});
2104
$where->map(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2105
    id => ['$table1.id', {if => 'length'}],
2106
    author => ['$table1.author', sub { '%' . $_[0] . '%' }, {if => 'defined'}],
2107
    price => ['$table1.price', {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
2108
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2109
is_deeply($where->param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2110
  '$table1.price' => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
2111

            
2112
test 'dbi_option default';
2113
$dbi = DBIx::Custom->new;
2114
is_deeply($dbi->dbi_option, {});
2115

            
2116
test 'register_tag_processor';
2117
$dbi = DBIx::Custom->connect;
2118
$dbi->register_tag_processor(
2119
    a => sub { 1 }
2120
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2121
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2122

            
2123
test 'register_tag';
2124
$dbi = DBIx::Custom->connect;
2125
$dbi->register_tag(
2126
    b => sub { 2 }
2127
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2128
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2129

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2141
test 'more tests';
2142
$dbi = DBIx::Custom->connect;
2143
eval{$dbi->apply_filter('table', 'column', [])};
2144
like($@, qr/apply_filter/);
2145

            
2146
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
2147
like($@, qr/apply_filter/);
2148

            
2149
$dbi->apply_filter(
2150

            
2151
);
2152
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2153
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
2154
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2155
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2156
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
2157
$dbi->apply_filter($table1, $key2, 
test cleanup
Yuki Kimoto authored on 2011-08-10
2158
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2159
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
2160
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2161

            
2162
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2163
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
2164
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2165
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2166
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
2167
$dbi->apply_filter($table1, $key2, {});
2168
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
2169
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2170

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

            
2179
eval{DBIx::Custom->connect(dsn => undef)};
2180
like($@, qr/_connect/);
2181

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

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

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

            
2224
test 'dbi_option';
2225
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2226
ok($dbi->dbh->{PrintError});
2227
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2228
ok($dbi->dbh->{PrintError});
2229

            
2230
test 'DBIx::Custom::Result stash()';
2231
$result = DBIx::Custom::Result->new;
2232
is_deeply($result->stash, {}, 'default');
2233
$result->stash->{foo} = 1;
2234
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2235

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2236
test 'delete_at';
2237
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2238
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
2239
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2240
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2241
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2242
    table => $table1,
2243
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2244
    where => [1, 2],
2245
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2246
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2247

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

            
2256
test 'insert_at';
2257
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2258
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
2259
$dbi->execute($create_table1_2);
2260
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2261
    primary_key => [$key1, $key2], 
2262
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2263
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2264
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2265
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2266
is($dbi->select(table => $table1)->one->{$key1}, 1);
2267
is($dbi->select(table => $table1)->one->{$key2}, 2);
2268
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2269

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2270
$dbi->delete_all(table => $table1);
2271
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2272
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2273
    primary_key => $key1, 
2274
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2275
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2276
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2277
);
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

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

            
2293
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2294
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
2295
$dbi->execute($create_table1_2);
2296
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2297
    {$key3 => 3},
2298
    primary_key => [$key1, $key2], 
2299
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2300
    where => [1, 2],
2301
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2302
is($dbi->select(table => $table1)->one->{$key1}, 1);
2303
is($dbi->select(table => $table1)->one->{$key2}, 2);
2304
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2305

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

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

            
2333
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2334
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
2335
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2336
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2337
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2338
    {$key3 => 4},
2339
    table => $table1,
2340
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2341
    where => [1, 2]
2342
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2343
is($dbi->select(table => $table1)->one->{$key1}, 1);
2344
is($dbi->select(table => $table1)->one->{$key2}, 2);
2345
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2346

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

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

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

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

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

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

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

            
2423
test 'columns';
2424
use MyDBI1;
2425
$dbi = MyDBI1->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2426
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2427

            
2428

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

            
2447
test 'model insert_at';
2448
$dbi = MyDBI6->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2449
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
2450
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2451
$dbi->model($table1)->insert_at(
cleanup test
Yuki Kimoto authored on 2011-08-10
2452
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2453
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2454
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2455
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2456
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2457
is($row->{$key1}, 1);
2458
is($row->{$key2}, 2);
2459
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2460

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

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

            
2487

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

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

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

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

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

            
2553
$result = $model->select_at(
2554
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2555
        $model->mycolumn([$key1]),
2556
        $model->column($table2 => [$key1])
cleanup test
Yuki Kimoto authored on 2011-08-10
2557
    ]
2558
);
2559
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2560
          {$key1 => 1, '$table2.$key1' => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2561
$result = $model->select_at(
2562
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2563
        $model->mycolumn([$key1]),
2564
        {$table2 => [$key1]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2565
    ]
2566
);
2567
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2568
          {$key1 => 1, '$table2.$key1' => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2569

            
2570
$result = $model->select_at(
2571
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2572
        $model->mycolumn([$key1]),
2573
        ["$table2.$key1", as => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2574
    ]
2575
);
2576
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2577
          {$key1 => 1, '$table2.$key1' => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2578

            
2579
$result = $model->select_at(
2580
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2581
        $model->mycolumn([$key1]),
2582
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2583
    ]
2584
);
2585
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2586
          {$key1 => 1, '$table2.$key1' => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2587

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

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

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

            
2625
test 'select() string where';
2626
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2627
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
2628
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2629
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2630
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2631
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2632
    table => $table1,
2633
    where => "$key1 = :$key1 and $key2 = :$key2",
2634
    where_param => {$key1 => 1, $key2 => 2}
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, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2637

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

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

            
2666
$dbi = DBIx::Custom->connect;
test cleanup in progress
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,
cleanup test
Yuki Kimoto authored on 2011-08-10
2673
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2674
        "$key1 = :$key1 and $key2 = :$key2",
2675
         {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2676
    ]
2677
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2678
$rows = $dbi->select(table => $table1)->all;
2679
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2680

            
2681

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

            
2696
$dbi = DBIx::Custom->connect;
test cleanup in progress
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},
cleanup test
Yuki Kimoto authored on 2011-08-10
2703
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2704
        "$key1 = :$key1 and $key2 = :$key2",
2705
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2706
    ]
2707
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2708
$rows = $dbi->select(table => $table1)->all;
2709
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2710

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2725
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2726
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2727
    primary_key => $key1, 
2728
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2729
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2730
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2731
);
2732

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

            
2737
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2738
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
2739
$dbi->execute($create_table1_2);
2740
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2741
    {$key3 => 3},
2742
    primary_key => [$key1, $key2], 
2743
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2744
    id => [1, 2],
2745
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2746
is($dbi->select(table => $table1)->one->{$key1}, 1);
2747
is($dbi->select(table => $table1)->one->{$key2}, 2);
2748
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2749

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

            
2764
$dbi = MyDBI6->connect;
test cleanup in progress
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(
2768
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2769
    id => [1, 2]
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
test 'update and id option';
2778
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2779
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
2780
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2781
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2782
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2783
    table => $table1,
2784
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2785
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2786
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2787
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2788
is($dbi->select(table => $table1)->one->{$key1}, 1);
2789
is($dbi->select(table => $table1)->one->{$key2}, 2);
2790
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2791

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

            
2804
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2805
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
2806
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2807
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2808
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2809
    {$key3 => 4},
2810
    table => $table1,
2811
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2812
    id => [1, 2]
2813
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2814
is($dbi->select(table => $table1)->one->{$key1}, 1);
2815
is($dbi->select(table => $table1)->one->{$key2}, 2);
2816
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2817

            
2818

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

            
2834

            
2835
test 'delete and id option';
2836
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2837
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
2838
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2839
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2840
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2841
    table => $table1,
2842
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2843
    id => [1, 2],
2844
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2845
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2846

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

            
2855

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

            
2874

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

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

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

            
2914

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

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

            
2943
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2944
    column => [$model->column($table2 => [qw/$key1 $key3/])],
2945
    where => {'$table1.$key1' => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2946
);
2947
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2948
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2949

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2950
test 'separator';
2951
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2952
eval { $dbi->execute('drop table $table1') };
2953
eval { $dbi->execute('drop table $table2') };
cleanup test
Yuki Kimoto authored on 2011-08-10
2954
$dbi->execute($create_table1);
2955
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2956

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2982
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2983
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2984
$result = $model->select(
2985
    column => [
2986
        $model->mycolumn,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2987
        {$table2 => [qw/$key1 $key3/]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2988
    ],
test cleanup in progress
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,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3000
        {$table2 => [qw/$key1 $key3/]}
cleanup test
Yuki Kimoto authored on 2011-08-10
3001
    ],
test cleanup in progress
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

            
3008

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3009
test 'filter_off';
3010
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3011
eval { $dbi->execute('drop table $table1') };
3012
eval { $dbi->execute('drop table $table2') };
cleanup test
Yuki Kimoto authored on 2011-08-10
3013
$dbi->execute($create_table1);
3014
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
3015

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3030
test 'available_datetype';
3031
$dbi = DBIx::Custom->connect;
3032
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
3033

            
3034

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3035
test 'select prefix option';
3036
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3037
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
3038
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3039
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3040
$rows = $dbi->select(prefix => '$key1,', column => $key2, table => $table1)->all;
3041
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
3042

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3054
$param = $dbi->map_param(
3055
    {id => 0, author => 0, price => 0},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3056
    id => '$table1.id',
3057
    author => ['$table1.author', sub { '%' . $_[0] . '%' }],
3058
    price => ['$table1.price', sub { '%' . $_[0] . '%' },
cleanup test
Yuki Kimoto authored on 2011-08-10
3059
      {if => sub { $_[0] eq 0 }}]
3060
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3061
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3062

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3063
$param = $dbi->map_param(
3064
    {id => '', author => '', price => ''},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3065
    id => '$table1.id',
3066
    author => ['$table1.author', sub { '%' . $_[0] . '%' }],
3067
    price => ['$table1.price', sub { '%' . $_[0] . '%' },
cleanup test
Yuki Kimoto authored on 2011-08-10
3068
      {if => sub { $_[0] eq 1 }}]
3069
);
3070
is_deeply($param, {});
test cleanup
Yuki Kimoto authored on 2011-08-10
3071

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3072
$param = $dbi->map_param(
3073
    {id => undef, author => undef, price => undef},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3074
    id => '$table1.id',
3075
    price => ['$table1.price', {if => 'exists'}]
cleanup test
Yuki Kimoto authored on 2011-08-10
3076
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3077
is_deeply($param, {'$table1.price' => undef});
test cleanup
Yuki Kimoto authored on 2011-08-10
3078

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3079
$param = $dbi->map_param(
3080
    {price => 'a'},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3081
    id => ['$table1.id', {if => 'exists'}],
3082
    price => ['$table1.price', sub { '%' . $_[0] }, {if => 'exists'}]
cleanup test
Yuki Kimoto authored on 2011-08-10
3083
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3084
is_deeply($param, {'$table1.price' => '%a'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3085

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

            
3104
$order = $dbi->order;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3105
$order->prepend(['$table1-$key1'], [qw/$table1-$key2 desc/]);
3106
$result = $dbi->select(table => $table1,
3107
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
test cleanup
Yuki Kimoto authored on 2011-08-10
3108
  append => "$order");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3109
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
3110
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
3111
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
3112
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3113

            
3114
test 'tag_parse';
3115
$dbi = DBIx::Custom->connect;
3116
$dbi->tag_parse(0);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3117
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
3118
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3119
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3120
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3121
ok($@);
3122

            
3123
test 'last_sql';
3124
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3125
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
3126
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3127
$dbi->execute('select * from $table1');
3128
is($dbi->last_sql, "select * from $table1;");
test cleanup
Yuki Kimoto authored on 2011-08-10
3129

            
3130
eval{$dbi->execute("aaa")};
3131
is($dbi->last_sql, 'aaa;');
3132

            
3133
test 'DBIx::Custom header';
3134
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3135
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
3136
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3137
$result = $dbi->execute("select $key1 as h1, $key2 as h2 from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3138
is_deeply($result->header, [qw/h1 h2/]);
3139

            
3140
test 'Named placeholder :name(operater) syntax';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3141
$dbi->execute('drop table $table1');
test cleanup
Yuki Kimoto authored on 2011-08-10
3142
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3143
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3144
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3145

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3191
$dbi->execute('drop table $table1');
test cleanup
Yuki Kimoto authored on 2011-08-10
3192
$dbi->execute($create_table1_highperformance);
3193
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3194
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3195
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3196
];
3197
{
3198
    my $query;
3199
    my $sth;
3200
    foreach my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3201
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3202
      $sth ||= $query->sth;
3203
      $sth->execute(map { $row->{$_} } sort keys %$row);
3204
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3205
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3206
      [
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
}
3212

            
3213
test 'result';
3214
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3215
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
3216
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3217
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3218
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3219

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

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

            
3234
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3235
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
3236
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3237
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3238
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3239

            
3240
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3241
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3242
$rows = $result->fetch_all;
3243
is_deeply($rows, [[1, 2], [3, 4]]);
3244

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

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

            
3253
$rows = $result->fetch_all;
3254
is_deeply($rows, [[3, 2], [9, 4]], "array");
3255

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3256
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3257
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3258
$result->filter({$key1 => 'three_times'});
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 => 3, $key2 => 2}, {$key1 => 9, $key2 => 4}], "hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
3261

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

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

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

            
3319
$query = $builder->build_query("{p a b}");
3320
is($query->{sql}, "? a b;", "register_tag sql");
3321
is_deeply($query->{columns}, [2], "register_tag columns");
3322

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3329
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3330
    q => 'string'
3331
});
3332

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3336
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3337
   r => sub {} 
3338
});
3339

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3343
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3344
   s => sub { return ["a", ""]} 
3345
});
3346

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

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

            
3354

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

            
3363

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

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

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

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

            
3379
test 'variouse source';
3380
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d;";
3381
$query = $builder->build_query($source);
3382
is($query->sql, 'a b = ? c { } { = ? } = ? d;', "basic : 1");
3383

            
3384
$source = "abc;";
3385
$query = $builder->build_query($source);
3386
is($query->sql, 'abc;', "basic : 2");
3387

            
3388
$source = "{= a}";
3389
$query = $builder->build_query($source);
3390
is($query->sql, 'a = ?;', "only tag");
3391

            
3392
$source = "000;";
3393
$query = $builder->build_query($source);
3394
is($query->sql, '000;', "contain 0 value");
3395

            
3396
$source = "a {= b} }";
3397
eval{$builder->build_query($source)};
3398
like($@, qr/unexpected "}"/, "error : 1");
3399

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3443
test 'dbi method from model';
3444
$dbi = MyDBI9->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3445
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
3446
$dbi->execute($create_table1);
3447
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3448
$model = $dbi->model($table1);
3449
eval{$model->execute('select * from $table1')};
cleanup test
Yuki Kimoto authored on 2011-08-10
3450
ok(!$@);
3451

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

            
3471
$dbi->separator('__');
3472
$result = $model->select(
3473
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3474
        $model->column($table2, {alias => $table2_alias})
cleanup test
Yuki Kimoto authored on 2011-08-10
3475
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3476
    where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
3477
);
3478
is_deeply($result->one, 
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3479
          {"${table2_alias}__$key1" => 1, "{$table2_alias}__$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-10
3480

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

            
3491
test 'create_model';
3492
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3493
eval { $dbi->execute('drop table $table1') };
3494
eval { $dbi->execute('drop table $table2') };
cleanup test
Yuki Kimoto authored on 2011-08-10
3495
$dbi->execute($create_table1);
3496
$dbi->execute($create_table2);
3497

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

            
3526
test 'model method';
3527
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3528
eval { $dbi->execute('drop table $table2') };
cleanup test
Yuki Kimoto authored on 2011-08-10
3529
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3530
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
3531
$model = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3532
    table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-10
3533
);
3534
$model->method(foo => sub { shift->select(@_) });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3535
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
3536

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3537
test 'update_param';
3538
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3539
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
3540
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3541
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3542
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-10
3543

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

            
3557

            
3558
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3559
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
3560
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3561
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3562
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-10
3563

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

            
3577
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3578
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
3579
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3580
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3581
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-10
3582

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

            
3596
            
3597
eval { $dbi->update_param({";" => 1}) };
3598
like($@, qr/not safety/);
3599

            
3600

            
3601
test 'update_param';
3602
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3603
eval { $dbi->execute('drop table $table1') };
cleanup test
Yuki Kimoto authored on 2011-08-10
3604
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3605
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3606
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-10
3607

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

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

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

            
3648
eval {
3649
    $rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3650
        table => $table1,
3651
        column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3652
        where   => {'$table1.$key2' => 2},
3653
        join  => {"$table1.$key1" => "$table2.$key1"}
cleanup test
Yuki Kimoto authored on 2011-08-10
3654
    );
3655
};
3656
like ($@, qr/array/);
3657

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

            
3666
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3667
    column => "$table3.$key4 as ${table3}__$key4",
3668
    table => $table1,
3669
    where   => {'$table1.$key1' => 1},
3670
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3671
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
cleanup test
Yuki Kimoto authored on 2011-08-10
3672
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3673
is_deeply($rows, [{"${table3}__$key4" => 4}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3674

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

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

            
3700

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

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

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

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

            
3790
$dbi = MyDBI4->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3791
eval { $dbi->execute('drop table $table1') };
test cleanup
Yuki Kimoto authored on 2011-08-10
3792
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3793
$model = $dbi->model($table1);
3794
$model->insert({$key1 => 'a', $key2 => 'b'});
3795
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3796
eval { $dbi->execute('drop table $table2') };
test cleanup
Yuki Kimoto authored on 2011-08-10
3797
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3798
$model = $dbi->model($table2);
3799
$model->insert({$key1 => 'a'});
3800
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
test cleanup
Yuki Kimoto authored on 2011-08-10
3801

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

            
3814
test 'primary_key';
3815
use MyDBI1;
3816
$dbi = MyDBI1->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3817
$model = $dbi->model($table1);
3818
$model->primary_key([$key1, $key2]);
3819
is_deeply($model->primary_key, [$key1, $key2]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3820

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

            
3828
test 'setup_model';
3829
use MyDBI1;
3830
$dbi = MyDBI1->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3831
eval { $dbi->execute('drop table $table1') };
3832
eval { $dbi->execute('drop table $table2') };
test cleanup
Yuki Kimoto authored on 2011-08-10
3833

            
3834
$dbi->execute($create_table1);
3835
$dbi->execute($create_table2);
3836
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3837
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3838
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3839

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

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

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