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

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

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

            
14
plan 'no_plan';
15

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

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

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

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

            
85
    use strict;
86
    use warnings;
87

            
88
    use base 'DBIx::Custom';
89

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

            
101
    package MyModel2::Base1;
102

            
103
    use strict;
104
    use warnings;
105

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

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

            
110
    use strict;
111
    use warnings;
112

            
113
    use base 'MyModel2::Base1';
114

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

            
121
    sub list { shift->select; }
122

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

            
125
    use strict;
126
    use warnings;
127

            
128
    use base 'MyModel2::Base1';
129

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

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

            
138
    package MyModel2::TABLE1;
139

            
140
    use strict;
141
    use warnings;
142

            
143
    use base 'MyModel2::Base1';
144

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

            
151
    sub list { shift->select; }
152

            
153
    package MyModel2::TABLE2;
154

            
155
    use strict;
156
    use warnings;
157

            
158
    use base 'MyModel2::Base1';
159

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

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

            
171
    use strict;
172
    use warnings;
173

            
174
    use base 'DBIx::Custom';
175

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

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

            
added test
Yuki Kimoto authored on 2011-08-16
237
# Get user table info
238
$dbi = DBIx::Custom->connect;
239
eval { $dbi->execute("drop table $table1") };
240
eval { $dbi->execute("drop table $table2") };
241
eval { $dbi->execute("drop table $table3") };
242
$dbi->execute($create_table1);
243
$dbi->execute($create_table2);
244
$dbi->execute($create_table3);
245
$user_table_info = $dbi->get_table_info(exclude => $dbi->exclude_table);
246

            
cleanup test
Yuki Kimoto authored on 2011-08-15
247
# Create table
test cleanup
Yuki Kimoto authored on 2011-08-10
248
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
249
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
250
$dbi->execute($create_table1);
251
$model = $dbi->create_model(table => $table1);
252
$model->insert({$key1 => 1, $key2 => 2});
253
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-08-15
254

            
cleanup test
Yuki Kimoto authored on 2011-08-15
255
test 'DBIx::Custom::Result test';
256
$dbi->delete_all(table => $table1);
257
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
258
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
259
$source = "select $key1, $key2 from $table1";
260
$query = $dbi->create_query($source);
261
$result = $dbi->execute($query);
cleanup
Yuki Kimoto authored on 2011-08-15
262

            
cleanup test
Yuki Kimoto authored on 2011-08-15
263
@rows = ();
264
while (my $row = $result->fetch) {
265
    push @rows, [@$row];
266
}
267
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
cleanup
Yuki Kimoto authored on 2011-08-15
268

            
cleanup test
Yuki Kimoto authored on 2011-08-15
269
$result = $dbi->execute($query);
270
@rows = ();
271
while (my $row = $result->fetch_hash) {
272
    push @rows, {%$row};
273
}
274
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
275

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
284
test 'Insert query return value';
285
$source = "insert into $table1 {insert_param $key1 $key2}";
286
$query = $dbi->execute($source, {}, query => 1);
287
$ret_val = $dbi->execute($query, param => {$key1 => 1, $key2 => 2});
288
ok($ret_val);
test cleanup
Yuki Kimoto authored on 2011-08-10
289

            
cleanup test
Yuki Kimoto authored on 2011-08-15
290
test 'Direct query';
291
$dbi->delete_all(table => $table1);
292
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
293
$dbi->execute($insert_source, param => {$key1 => 1, $key2 => 2});
294
$result = $dbi->execute("select * from $table1");
295
$rows = $result->all;
296
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
297

            
298
test 'Filter basic';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
299
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-08
300
$dbi->register_filter(twice       => sub { $_[0] * 2}, 
301
                    three_times => sub { $_[0] * 3});
302

            
cleanup test
Yuki Kimoto authored on 2011-08-15
303
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
304
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
305
$insert_query->filter({$key1 => 'twice'});
306
$dbi->execute($insert_query, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
307
$result = $dbi->execute("select * from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
308
$rows = $result->filter({$key2 => 'three_times'})->all;
309
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
310

            
311
test 'Filter in';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
312
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
313
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
314
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
315
$dbi->execute($insert_query, param => {$key1 => 2, $key2 => 4});
316
$select_source = "select * from $table1 where {in $table1.$key1 2} and {in $table1.$key2 2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
317
$select_query = $dbi->execute($select_source,{}, query => 1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
318
$select_query->filter({"$table1.$key1" => 'twice'});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
319
$result = $dbi->execute($select_query, param => {"$table1.$key1" => [1,5], "$table1.$key2" => [2,4]});
cleanup test
Yuki Kimoto authored on 2011-08-08
320
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
321
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
322

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
403
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
404
$result = $dbi->execute(
405
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
406
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
407
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
cleanup test
Yuki Kimoto authored on 2011-08-08
408
);
409
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
410
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
411

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
412
$dbi->execute("drop table $table1");
cleanup test
Yuki Kimoto authored on 2011-08-08
413
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
414
$dbi->insert(table => $table1, param => {$key1 => '2011-10-14 12:19:18', $key2 => 2});
415
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
416
$result = $dbi->execute(
417
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
418
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
419
);
420

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
425
$dbi->delete_all(table => $table1);
426
$dbi->insert(table => $table1, param => {$key1 => 'a:b c:d', $key2 => 2});
427
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
428
$result = $dbi->execute(
429
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
430
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
431
);
432
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
433
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
434

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
442
test 'insert';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
443
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
444
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
445
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
446
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
447
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
448
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
449
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
450

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
451
$dbi->execute("delete from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
452
$dbi->register_filter(
453
    twice       => sub { $_[0] * 2 },
454
    three_times => sub { $_[0] * 3 }
455
);
456
$dbi->default_bind_filter('twice');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
457
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => 'three_times'});
cleanup test
Yuki Kimoto authored on 2011-08-15
458
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
459
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
460
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-10
461
$dbi->default_bind_filter(undef);
462

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
463
$dbi->execute("drop table $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
464
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
465
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, append => '   ');
466
$rows = $dbi->select(table => $table1)->all;
467
is_deeply($rows, [{$key1 => 1, $key2 => 2}], 'insert append');
cleanup test
Yuki Kimoto authored on 2011-08-10
468

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

            
472
eval{$dbi->insert(table => 'table', param => {';' => 1})};
473
like($@, qr/safety/);
474

            
cleanup test
Yuki Kimoto authored on 2011-08-10
475
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
476
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
477
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
478
$dbi->insert(table => 'table', param => {select => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
479
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
480
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
481
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
cleanup test
Yuki Kimoto authored on 2011-08-10
482

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
483
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
484
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
485
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
486
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
487
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
488
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
489
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
490

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
491
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
492
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
493
$dbi->insert(table => $table1, param => {$key1 => \"'1'", $key2 => 2});
494
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
495
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
496
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
497
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
498

            
test cleanup
Yuki Kimoto authored on 2011-08-10
499
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
500
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
501
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
502
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
503
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
504
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
505
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
506
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
507
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
508
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
509
                  "basic");
510
                  
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
511
$dbi->execute("delete from $table1");
512
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
513
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
514
$dbi->update(table => $table1, param => {$key2 => 12}, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
515
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
516
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
517
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
518
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
519
                  "update key same as search key");
520

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
528
$dbi->execute("delete from $table1");
529
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
530
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
531
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
532
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1},
533
              filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
534
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
535
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
536
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
537
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
538
                  "filter");
539

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
548
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
549
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
550
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
551
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
552
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
553
$where->param({$key1 => 1, $key2 => 2});
554
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
555
$result = $dbi->select(table => $table1);
556
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
557

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
558
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
559
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
560
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
561
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
562
    table => $table1,
563
    param => {$key1 => 3},
test cleanup
Yuki Kimoto authored on 2011-08-10
564
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
565
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
566
        {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
567
    ]
568
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
569
$result = $dbi->select(table => $table1);
570
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
571

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
572
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
573
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
574
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
575
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
576
$where->clause(['and', "$key2 = :$key2"]);
577
$where->param({$key2 => 2});
578
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
579
$result = $dbi->select(table => $table1);
580
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
581

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
588
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
589
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
590
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
591
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
592
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
593
$dbi->insert(table => 'table', param => {select => 1});
594
$dbi->update(table => 'table', where => {select => 1}, param => {update => 2});
595
$result = $dbi->execute("select * from ${q}table$p");
596
$rows   = $result->all;
597
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
598

            
599
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
600
like($@, qr/safety/);
601

            
602
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
603
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
604
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
605
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
606
$dbi->insert(table => 'table', param => {select => 1});
607
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
608
$result = $dbi->execute("select * from ${q}table$p");
609
$rows   = $result->all;
610
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
611

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
612
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
613
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
614
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
615
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
616
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
617
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
618
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
619
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
620
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
621
                  "basic");
622

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
623
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
624
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
625
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
626
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
627
$dbi->update(table => $table1, param => {$key2 => \"'11'"}, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
628
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
629
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
630
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
631
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
632
                  "basic");
633

            
634
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
635
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
636
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
637
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
638
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
639
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
640
$dbi->update_all(table => $table1, param => {$key2 => 10}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
641
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
642
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
643
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
644
                  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
645
                  "filter");
646

            
647

            
648
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
649
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
650
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
651
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
652
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
653
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
654
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
655
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
656
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
657

            
cleanup test
Yuki Kimoto authored on 2011-08-15
658
$dbi->execute("delete from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
659
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
660
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
661
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
662
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
663
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
664
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
665
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
666

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
669
$dbi->delete_all(table => $table1);
670
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
671
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
672
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
673
$rows = $dbi->select(table => $table1)->all;
674
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
675

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
679
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
680
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
681
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
682
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
683
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
684
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
685
$where->param({ke1 => 1, $key2 => 2});
686
$dbi->delete(table => $table1, where => $where);
687
$result = $dbi->select(table => $table1);
688
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
689

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
704
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
705
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
706
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
707
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
708
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
709
$rows   = $result->all;
710
is_deeply($rows, [], "basic");
711

            
712
test 'delete error';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
713
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
714
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
715
eval{$dbi->delete(table => $table1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
716
like($@, qr/"where" must be specified/,
717
         "where key-value pairs not specified");
718

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
722
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
723
$dbi = DBIx::Custom->connect;
724
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
725
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
726
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
727
$dbi->insert(table => 'table', param => {select => 1});
728
$dbi->delete(table => 'table', where => {select => 1});
729
$result = $dbi->execute("select * from ${q}table$p");
730
$rows   = $result->all;
731
is_deeply($rows, [], "reserved word");
732

            
733
test 'delete_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
734
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
735
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
736
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
737
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
738
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
739
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
740
$rows   = $result->all;
741
is_deeply($rows, [], "basic");
742

            
743

            
744
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
745
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
746
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
747
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
748
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
749
$rows = $dbi->select(table => $table1)->all;
750
is_deeply($rows, [{$key1 => 1, $key2 => 2},
751
                  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
752

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
767
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
768
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
769
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
test cleanup
Yuki Kimoto authored on 2011-08-10
770
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
771
    table => [$table1, $table2],
772
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
773
    where   => {"$table1.$key2" => 2},
774
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
775
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
776
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
777

            
778
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
779
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
780
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
781
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
782
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
783
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
784

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

            
788
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
789
eval { $dbi->execute("drop table ${q}table$p") };
790
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
791
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
792
$dbi->insert(table => 'table', param => {select => 1, update => 2});
793
$result = $dbi->select(table => 'table', where => {select => 1});
794
$rows   = $result->all;
795
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
796

            
797
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
798
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
799
$dbi->register_filter(
800
    twice       => sub { $_[0] * 2 },
801
    three_times => sub { $_[0] * 3 }
802
);
803
$dbi->default_fetch_filter('twice');
804
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
805
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
806
$result = $dbi->select(table => $table1);
807
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
808
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
809
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
810

            
811
test 'filters';
812
$dbi = DBIx::Custom->new;
813

            
814
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
815
   'あ', "decode_utf8");
816

            
817
is($dbi->filters->{encode_utf8}->('あ'),
818
   encode_utf8('あ'), "encode_utf8");
819

            
cleanup test
Yuki Kimoto authored on 2011-08-10
820
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
821
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
822
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
823
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
824
$dbi->begin_work;
825
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
826
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
827
$dbi->rollback;
828
$dbi->dbh->{AutoCommit} = 1;
829

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

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

            
834
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
835
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
836
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
837
$dbi->begin_work;
838
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
839
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
840
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
841
$dbi->commit;
842
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
843
$result = $dbi->select(table => $table1);
844
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
845
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
846

            
847
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
848
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
849
$dbi->execute($create_table1);
850
{
851
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
852
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
853
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
854
    like($@, qr/\.t /, "fail : not verbose");
855
}
856
{
857
    local $Carp::Verbose = 1;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
858
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
859
    like($@, qr/Custom.*\.t /s, "fail : verbose");
860
}
861

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

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

            
870
{
871
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
872
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
873
    like($@, qr/\Q.t /, "caller spec : not vebose");
874
}
875
{
876
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
877
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
878
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
879
}
880

            
881

            
cleanup test
Yuki Kimoto authored on 2011-08-10
882
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
883
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
884
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
885
$dbi->execute($create_table1);
886

            
887
$dbi->begin_work;
888

            
889
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
890
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
891
    die "Error";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
892
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
893
};
894

            
895
$dbi->rollback if $@;
896

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

            
901
$dbi->begin_work;
902

            
903
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
904
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
905
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
906
};
907

            
908
$dbi->commit unless $@;
909

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

            
914
$dbi->dbh->{AutoCommit} = 0;
915
eval{ $dbi->begin_work };
916
ok($@, "exception");
917
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
918

            
test cleanup
Yuki Kimoto authored on 2011-08-10
919
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
920
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
921
$dbi->cache(1);
922
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
923
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
924
$dbi->execute($source, {}, query => 1);
925
is_deeply($dbi->{_cached}->{$source}, 
cleanup test
Yuki Kimoto authored on 2011-08-15
926
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
927

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
928
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
929
$dbi->execute($create_table1);
930
$dbi->{_cached} = {};
931
$dbi->cache(0);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
932
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
933
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
934

            
935
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
936
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
937
$dbi->execute($create_table1);
938
{
939
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
940
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
941
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
942
    like($@, qr/\.t /, "fail : not verbose");
943
}
944
{
945
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
946
    eval{$dbi->execute('select * frm $table1')};
test cleanup
Yuki Kimoto authored on 2011-08-10
947
    like($@, qr/Custom.*\.t /s, "fail : verbose");
948
}
949

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

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

            
958
{
959
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
960
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
961
    like($@, qr/\Q.t /, "caller spec : not vebose");
962
}
963
{
964
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
965
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
966
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
967
}
968

            
969
test 'method';
970
$dbi->method(
971
    one => sub { 1 }
972
);
973
$dbi->method(
974
    two => sub { 2 }
975
);
976
$dbi->method({
977
    twice => sub {
978
        my $self = shift;
979
        return $_[0] * 2;
980
    }
981
});
982

            
983
is($dbi->one, 1, "first");
984
is($dbi->two, 2, "second");
985
is($dbi->twice(5), 10 , "second");
986

            
987
eval {$dbi->XXXXXX};
988
ok($@, "not exists");
989

            
990
test 'out filter';
991
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
992
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
993
$dbi->execute($create_table1);
994
$dbi->register_filter(twice => sub { $_[0] * 2 });
995
$dbi->register_filter(three_times => sub { $_[0] * 3});
996
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
997
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
998
              $key2 => {out => 'three_times', in => 'twice'});
999
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1000
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1001
$row   = $result->fetch_hash_first;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1002
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1003
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1004
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1005
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1006

            
1007
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1008
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1009
$dbi->execute($create_table1);
1010
$dbi->register_filter(twice => sub { $_[0] * 2 });
1011
$dbi->register_filter(three_times => sub { $_[0] * 3});
1012
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1013
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1014
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1015
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1016
    $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1017
); 
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1018
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1019
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1020
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1021
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1022

            
1023
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1024
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1025
$dbi->execute($create_table1);
1026
$dbi->register_filter(twice => sub { $_[0] * 2 });
1027
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1028
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1029
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1030
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => undef});
1031
$dbi->update(table => $table1, param => {$key1 => 2}, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1032
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1033
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1034
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
test cleanup
Yuki Kimoto authored on 2011-08-10
1035

            
1036
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1037
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1038
$dbi->execute($create_table1);
1039
$dbi->register_filter(twice => sub { $_[0] * 2 });
1040
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1041
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1042
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1043
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1=> undef});
1044
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1045
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1046
$rows   = $result->all;
1047
is_deeply($rows, [], "delete");
1048

            
1049
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1050
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1051
$dbi->execute($create_table1);
1052
$dbi->register_filter(twice => sub { $_[0] * 2 });
1053
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1054
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1055
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1056
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
1057
$result = $dbi->select(table => $table1, where => {$key1 => 1});
1058
$result->filter({$key2 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1059
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1060
is_deeply($rows, [{$key1 => 4, $key2 => 4}], "select");
test cleanup
Yuki Kimoto authored on 2011-08-10
1061

            
1062
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1063
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1064
$dbi->execute($create_table1);
1065
$dbi->register_filter(twice => sub { $_[0] * 2 });
1066
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1067
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1068
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1069
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1070
$result = $dbi->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1071
                        param => {$key1 => 1, $key2 => 2},
1072
                        table => [$table1]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1073
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1074
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute");
test cleanup
Yuki Kimoto authored on 2011-08-10
1075

            
1076
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
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);
1079
$dbi->register_filter(twice => sub { $_[0] * 2 });
1080
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1081
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1082
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1083
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1084
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1085
                        param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1086
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1087
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1088

            
1089
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1090
eval { $dbi->execute("drop table $table1") };
1091
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1092
$dbi->execute($create_table1);
1093
$dbi->execute($create_table2);
1094
$dbi->register_filter(twice => sub { $_[0] * 2 });
1095
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1096
$dbi->apply_filter(
cleanup test
Yuki Kimoto authored on 2011-08-15
1097
    $table1, $key2 => {out => 'twice', in => 'twice'}
1098
);
1099
$dbi->apply_filter(
1100
    $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1101
);
cleanup test
Yuki Kimoto authored on 2011-08-15
1102
$dbi->insert(table => $table1, param => {$key1 => 5, $key2 => 2}, filter => {$key2 => undef});
1103
$dbi->insert(table => $table2, param => {$key1 => 5, $key3 => 6}, filter => {$key3 => undef});
1104
$result = $dbi->select(
1105
     table => [$table1, $table2],
1106
     column => [$key2, $key3],
1107
     where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1108

            
1109
$result->filter({$key2 => 'twice'});
1110
$rows   = $result->all;
1111
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1112

            
1113
$result = $dbi->select(
1114
     table => [$table1, $table2],
1115
     column => [$key2, $key3],
1116
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1117

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

            
1122
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1123
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1124
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1125
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1126
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1127
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1128

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1129
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1130
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1131
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1132
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1133
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1134
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1135

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1136
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1137
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1138
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1139
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1140
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1141

            
1142
test 'end_filter';
1143
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1144
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1145
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1146
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1147
$result = $dbi->select(table => $table1);
1148
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1149
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1150
$row = $result->fetch_first;
1151
is_deeply($row, [6, 40]);
1152

            
1153
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1154
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1155
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1156
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1157
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1158
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1159
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1160
$row = $result->fetch_first;
1161
is_deeply($row, [6, 12]);
1162

            
1163
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1164
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1165
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1166
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1167
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1168
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1169
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1170
$row = $result->fetch_first;
1171
is_deeply($row, [6, 12]);
1172

            
1173
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1174
$result = $dbi->select(table => $table1);
1175
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1176
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1177
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1178
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1179

            
1180
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1181
$dbi->apply_filter($table1,
1182
    $key1 => {end => sub { $_[0] * 3 } },
1183
    $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1184
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1185
$result = $dbi->select(table => $table1);
1186
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1187
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1188
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1189

            
1190
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1191
$dbi->apply_filter($table1,
1192
    $key1 => {end => sub { $_[0] * 3 } },
1193
    $key2 => {end => 'five_times'}
1194
);
1195
$result = $dbi->select(table => $table1);
1196
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1197
$result->filter($key1 => undef);
1198
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1199
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1200
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1201

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1202
test 'remove_end_filter and remove_filter';
1203
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1204
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1205
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1206
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1207
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1208
$row = $result
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1209
       ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1210
       ->remove_filter
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1211
       ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1212
       ->remove_end_filter
1213
       ->fetch_first;
1214
is_deeply($row, [1, 2]);
1215

            
1216
test 'empty where select';
1217
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1218
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1219
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1220
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1221
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1222
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1223
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1224

            
1225
test 'select query option';
1226
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1227
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1228
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1229
$query = $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1230
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1231
$query = $dbi->update(table => $table1, where => {$key1 => 1}, param => {$key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1232
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1233
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1234
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1235
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1236
is(ref $query, 'DBIx::Custom::Query');
1237

            
1238
test 'where';
1239
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1240
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1241
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1242
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1243
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1244
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1245
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1246

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

            
1251
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1252
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1253
    where => $where
1254
);
1255
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1256
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1257

            
1258
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1259
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1260
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1261
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
1262
        {$key1 => 1}
test cleanup
Yuki Kimoto authored on 2011-08-10
1263
    ]
1264
);
1265
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1266
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1267

            
1268
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1269
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1270
             ->param({$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1271
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1272
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1273
    where => $where
1274
);
1275
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1276
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1277

            
1278
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1279
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
test cleanup
Yuki Kimoto authored on 2011-08-10
1280
             ->param({});
1281
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1282
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1283
    where => $where,
1284
);
1285
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1286
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1287

            
1288
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1289
             ->clause(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"])
1290
             ->param({$key1 => [0, 3], $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1291
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1292
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1293
    where => $where,
1294
); 
1295
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1296
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1297

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

            
1306
eval {
1307
$where = $dbi->where
1308
             ->clause(['uuu']);
1309
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1310
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1311
    where => $where
1312
);
1313
};
1314
ok($@);
1315

            
1316
$where = $dbi->where;
1317
is("$where", '');
1318

            
1319
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1320
             ->clause(['or', ("$key1 = :$key1") x 2])
1321
             ->param({$key1 => [1, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1322
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1323
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1324
    where => $where,
1325
);
1326
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1327
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1328

            
1329
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1330
             ->clause(['or', ("$key1 = :$key1") x 2])
1331
             ->param({$key1 => [1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1332
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1333
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1334
    where => $where,
1335
);
1336
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1337
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1338

            
1339
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1340
             ->clause(['or', ("$key1 = :$key1") x 2])
1341
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1342
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1343
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1344
    where => $where,
1345
);
1346
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1347
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1348

            
1349
$where = $dbi->where
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1350
             ->clause("$key1 = :$key1")
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1351
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1352
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1353
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1354
    where => $where,
1355
);
1356
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1357
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1358

            
1359
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1360
             ->clause("$key1 = :$key1 $key2 = :$key2")
1361
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1362
eval{$where->to_string};
1363
like($@, qr/one column/);
1364

            
1365
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1366
             ->clause(['or', ("$key1 = :$key1") x 3])
1367
             ->param({$key1 => [$dbi->not_exists, 1, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1368
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1369
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1370
    where => $where,
1371
);
1372
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1373
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1374

            
1375
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1376
             ->clause(['or', ("$key1 = :$key1") x 3])
1377
             ->param({$key1 => [1, $dbi->not_exists, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1378
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1379
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1380
    where => $where,
1381
);
1382
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1383
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1384

            
1385
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1386
             ->clause(['or', ("$key1 = :$key1") x 3])
1387
             ->param({$key1 => [1, 3, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1388
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1389
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1390
    where => $where,
1391
);
1392
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1393
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1394

            
1395
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1396
             ->clause(['or', ("$key1 = :$key1") x 3])
1397
             ->param({$key1 => [1, $dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1398
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1399
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1400
    where => $where,
1401
);
1402
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1403
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1404

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

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

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

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

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

            
1455
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1456
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1457
             ->param({$key1 => [$dbi->not_exists, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1458
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1459
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1460
    where => $where,
1461
);
1462
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1463
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1464

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

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

            
1485
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1486
             ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1487
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1488
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1489
    where => $where,
1490
);
1491
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1492
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1493

            
1494
eval {$dbi->where(ppp => 1) };
1495
like($@, qr/invalid/);
1496

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

            
1508

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

            
1520
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1521
$where->clause(['and', ":${key1}{=}"]);
1522
$where->param({$key1 => undef});
1523
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1524
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1525
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1526

            
1527
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1528
$where->clause(['and', ":${key1}{=}"]);
1529
$where->param({$key1 => undef});
test cleanup
Yuki Kimoto authored on 2011-08-10
1530
$where->if('defined');
1531
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1532
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1533
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1534
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1535

            
1536
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1537
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1538
$where->param({$key1 => [undef, undef]});
1539
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1540
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1541
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1542
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1543
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1544
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1545

            
1546
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1547
$where->clause(['and', ":${key1}{=}"]);
1548
$where->param({$key1 => [undef, undef]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1549
$where->if('defined');
1550
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1551
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1552
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1553
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
1554
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1555
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1556
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1557

            
1558
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1559
$where->clause(['and', ":${key1}{=}"]);
1560
$where->param({$key1 => 0});
test cleanup
Yuki Kimoto authored on 2011-08-10
1561
$where->if('length');
1562
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1563
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1564
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1565
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1566

            
1567
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1568
$where->clause(['and', ":${key1}{=}"]);
1569
$where->param({$key1 => ''});
test cleanup
Yuki Kimoto authored on 2011-08-10
1570
$where->if('length');
1571
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1572
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1573
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1574
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1575

            
1576
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1577
$where->clause(['and', ":${key1}{=}"]);
1578
$where->param({$key1 => 5});
test cleanup
Yuki Kimoto authored on 2011-08-10
1579
$where->if(sub { ($_[0] || '') eq 5 });
1580
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1581
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1582
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1583
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1584

            
1585
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1586
$where->clause(['and', ":${key1}{=}"]);
1587
$where->param({$key1 => 7});
test cleanup
Yuki Kimoto authored on 2011-08-10
1588
$where->if(sub { ($_[0] || '') eq 5 });
1589
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1590
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1591
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1592
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1593

            
1594
$where = $dbi->where;
1595
$where->param({id => 1, author => 'Ken', price => 1900});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1596
$where->map(id => "$table1.id",
1597
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
1598
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1599
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1600
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1601
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
1602

            
1603
$where = $dbi->where;
1604
$where->param({id => 0, author => 0, price => 0});
1605
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1606
    id => "$table1.id",
1607
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
1608
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
test cleanup
Yuki Kimoto authored on 2011-08-10
1609
      {if => sub { $_[0] eq 0 }}]
1610
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1611
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1612

            
1613
$where = $dbi->where;
1614
$where->param({id => '', author => '', price => ''});
1615
$where->if('length');
1616
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1617
    id => "$table1.id",
1618
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
1619
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
test cleanup
Yuki Kimoto authored on 2011-08-10
1620
      {if => sub { $_[0] eq 1 }}]
1621
);
1622
is_deeply($where->param, {});
1623

            
1624
$where = $dbi->where;
1625
$where->param({id => undef, author => undef, price => undef});
1626
$where->if('length');
1627
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1628
    id => "$table1.id",
1629
    price => ["$table1.price", {if => 'exists'}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1630
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1631
is_deeply($where->param, {"$table1.price" => undef});
test cleanup
Yuki Kimoto authored on 2011-08-10
1632

            
1633
$where = $dbi->where;
1634
$where->param({price => 'a'});
1635
$where->if('length');
1636
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1637
    id => ["$table1.id", {if => 'exists'}],
1638
    price => ["$table1.price", sub { '%' . $_[0] }, {if => 'exists'}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1639
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1640
is_deeply($where->param, {"$table1.price" => '%a'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1641

            
1642
$where = $dbi->where;
1643
$where->param({id => [1, 2], author => 'Ken', price => 1900});
1644
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1645
    id => "$table1.id",
1646
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
1647
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1648
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1649
is_deeply($where->param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1650
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
1651

            
1652
$where = $dbi->where;
1653
$where->if('length');
1654
$where->param({id => ['', ''], author => 'Ken', price => 1900});
1655
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1656
    id => "$table1.id",
1657
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
1658
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1659
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1660
is_deeply($where->param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1661
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
1662

            
1663
$where = $dbi->where;
1664
$where->param({id => ['', ''], author => 'Ken', price => 1900});
1665
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1666
    id => ["$table1.id", {if => 'length'}],
1667
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, {if => 'defined'}],
1668
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1669
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1670
is_deeply($where->param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1671
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
1672

            
1673
test 'register_tag_processor';
1674
$dbi = DBIx::Custom->connect;
1675
$dbi->register_tag_processor(
1676
    a => sub { 1 }
1677
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1678
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1679

            
1680
test 'register_tag';
1681
$dbi = DBIx::Custom->connect;
1682
$dbi->register_tag(
1683
    b => sub { 2 }
1684
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1685
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1686

            
1687
test 'table not specify exception';
1688
$dbi = DBIx::Custom->connect;
1689
eval {$dbi->insert};
1690
like($@, qr/table/);
1691
eval {$dbi->update};
1692
like($@, qr/table/);
1693
eval {$dbi->delete};
1694
like($@, qr/table/);
1695
eval {$dbi->select};
1696
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1697

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1698
test 'more tests';
1699
$dbi = DBIx::Custom->connect;
1700
eval{$dbi->apply_filter('table', 'column', [])};
1701
like($@, qr/apply_filter/);
1702

            
1703
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1704
like($@, qr/apply_filter/);
1705

            
1706
$dbi->apply_filter(
1707

            
1708
);
1709
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1710
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1711
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1712
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1713
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1714
$dbi->apply_filter($table1, $key2, 
test cleanup
Yuki Kimoto authored on 2011-08-10
1715
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1716
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
1717
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1718

            
1719
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1720
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1721
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1722
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1723
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1724
$dbi->apply_filter($table1, $key2, {});
1725
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1726
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1727

            
1728
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1729
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1730
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1731
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1732
like($@, qr/not registered/);
1733
$dbi->method({one => sub { 1 }});
1734
is($dbi->one, 1);
1735

            
1736
eval{DBIx::Custom->connect(dsn => undef)};
1737
like($@, qr/_connect/);
1738

            
1739
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1740
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1741
$dbi->execute($create_table1);
1742
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1743
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1744
             filter => {$key1 => 'twice'});
1745
$row = $dbi->select(table => $table1)->one;
1746
is_deeply($row, {$key1 => 2, $key2 => 2});
1747
eval {$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1748
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
1749
like($@, qr//);
1750

            
1751
$dbi->register_filter(one => sub { });
1752
$dbi->default_fetch_filter('one');
1753
ok($dbi->default_fetch_filter);
1754
$dbi->default_bind_filter('one');
1755
ok($dbi->default_bind_filter);
1756
eval{$dbi->default_fetch_filter('no')};
1757
like($@, qr/not registered/);
1758
eval{$dbi->default_bind_filter('no')};
1759
like($@, qr/not registered/);
1760
$dbi->default_bind_filter(undef);
1761
ok(!defined $dbi->default_bind_filter);
1762
$dbi->default_fetch_filter(undef);
1763
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1764
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1765
like($@, qr/Tag not finished/);
1766

            
1767
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1768
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1769
$dbi->execute($create_table1);
1770
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1771
$result = $dbi->select(table => $table1);
1772
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1773
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1774
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1775
like($@, qr/not registered/);
1776
$result->default_filter(undef);
1777
ok(!defined $result->default_filter);
1778
$result->default_filter('one');
1779
is($result->default_filter->(), 1);
1780

            
1781
test 'dbi_option';
1782
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
1783
ok($dbi->dbh->{PrintError});
1784
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
1785
ok($dbi->dbh->{PrintError});
1786

            
1787
test 'DBIx::Custom::Result stash()';
1788
$result = DBIx::Custom::Result->new;
1789
is_deeply($result->stash, {}, 'default');
1790
$result->stash->{foo} = 1;
1791
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
1792

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1793
test 'delete_at';
1794
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1795
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1796
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1797
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1798
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1799
    table => $table1,
1800
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1801
    where => [1, 2],
1802
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1803
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1804

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1805
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1806
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1807
    table => $table1,
1808
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1809
    where => 1,
1810
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1811
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1812

            
1813
test 'insert_at';
1814
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1815
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1816
$dbi->execute($create_table1_2);
1817
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1818
    primary_key => [$key1, $key2], 
1819
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1820
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1821
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1822
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1823
is($dbi->select(table => $table1)->one->{$key1}, 1);
1824
is($dbi->select(table => $table1)->one->{$key2}, 2);
1825
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1826

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1827
$dbi->delete_all(table => $table1);
1828
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1829
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1830
    primary_key => $key1, 
1831
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1832
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1833
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1834
);
1835

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

            
1840
eval {
1841
    $dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1842
        table => $table1,
1843
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1844
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1845
        param => {$key1 => 1, $key2 => 2, $key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
1846
    );
1847
};
1848
like($@, qr/must be/);
1849

            
1850
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1851
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1852
$dbi->execute($create_table1_2);
1853
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1854
    {$key3 => 3},
1855
    primary_key => [$key1, $key2], 
1856
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1857
    where => [1, 2],
1858
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1859
is($dbi->select(table => $table1)->one->{$key1}, 1);
1860
is($dbi->select(table => $table1)->one->{$key2}, 2);
1861
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1862

            
1863
test 'update_at';
1864
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1865
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1866
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1867
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1868
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1869
    table => $table1,
1870
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1871
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1872
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
1873
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1874
is($dbi->select(table => $table1)->one->{$key1}, 1);
1875
is($dbi->select(table => $table1)->one->{$key2}, 2);
1876
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1877

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1878
$dbi->delete_all(table => $table1);
1879
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1880
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1881
    table => $table1,
1882
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1883
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1884
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
1885
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1886
is($dbi->select(table => $table1)->one->{$key1}, 1);
1887
is($dbi->select(table => $table1)->one->{$key2}, 2);
1888
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1889

            
1890
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1891
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1892
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1893
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1894
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1895
    {$key3 => 4},
1896
    table => $table1,
1897
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1898
    where => [1, 2]
1899
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1900
is($dbi->select(table => $table1)->one->{$key1}, 1);
1901
is($dbi->select(table => $table1)->one->{$key2}, 2);
1902
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1903

            
1904
test 'select_at';
1905
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1906
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1907
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1908
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1909
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1910
    table => $table1,
1911
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1912
    where => [1, 2]
1913
);
1914
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1915
is($row->{$key1}, 1);
1916
is($row->{$key2}, 2);
1917
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1918

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1919
$dbi->delete_all(table => $table1);
1920
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1921
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1922
    table => $table1,
1923
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1924
    where => 1,
1925
);
1926
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1927
is($row->{$key1}, 1);
1928
is($row->{$key2}, 2);
1929
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1930

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1931
$dbi->delete_all(table => $table1);
1932
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1933
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1934
    table => $table1,
1935
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1936
    where => [1, 2]
1937
);
1938
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1939
is($row->{$key1}, 1);
1940
is($row->{$key2}, 2);
1941
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1942

            
1943
eval {
1944
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1945
        table => $table1,
1946
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1947
        where => {},
1948
    );
1949
};
1950
like($@, qr/must be/);
1951

            
1952
eval {
1953
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1954
        table => $table1,
1955
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1956
        where => [1],
1957
    );
1958
};
1959
like($@, qr/same/);
1960

            
1961
eval {
1962
    $result = $dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1963
        table => $table1,
1964
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1965
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1966
        param => {$key1 => 1, $key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-10
1967
    );
1968
};
1969
like($@, qr/must be/);
1970

            
1971
eval {
1972
    $result = $dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1973
        table => $table1,
1974
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1975
        where => {},
1976
    );
1977
};
1978
like($@, qr/must be/);
1979

            
1980
test 'model delete_at';
1981
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1982
eval { $dbi->execute("drop table $table1") };
1983
eval { $dbi->execute("drop table $table2") };
1984
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1985
$dbi->execute($create_table1_2);
1986
$dbi->execute($create_table2_2);
1987
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1988
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1989
$dbi->model($table1)->delete_at(where => [1, 2]);
1990
is_deeply($dbi->select(table => $table1)->all, []);
1991
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1992
$dbi->model($table1)->delete_at(where => [1, 2]);
1993
is_deeply($dbi->select(table => $table1)->all, []);
1994
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1995
$dbi->model($table3)->delete_at(where => [1, 2]);
1996
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1997

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

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

            
2027
test 'model select_at';
2028
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2029
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2030
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2031
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2032
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2033
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2034
is($row->{$key1}, 1);
2035
is($row->{$key2}, 2);
2036
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2037

            
2038

            
2039
test 'mycolumn and column';
2040
$dbi = MyDBI7->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2041
eval { $dbi->execute("drop table $table1") };
2042
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2043
$dbi->execute($create_table1);
2044
$dbi->execute($create_table2);
2045
$dbi->separator('__');
2046
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2047
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2048
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2049
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2050
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2051
    column => [$model->mycolumn, $model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2052
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2053
);
2054
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2055
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2056

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2057
test 'insert_param';
2058
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2059
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2060
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2061
$param = {$key1 => 1, $key2 => 2};
test cleanup
Yuki Kimoto authored on 2011-08-10
2062
$insert_param = $dbi->insert_param($param);
2063
$sql = <<"EOS";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2064
insert into $table1 $insert_param
test cleanup
Yuki Kimoto authored on 2011-08-10
2065
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2066
$dbi->execute($sql, param => $param, table => $table1);
2067
is($dbi->select(table => $table1)->one->{$key1}, 1);
2068
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2069

            
2070
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2071
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2072
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2073
$param = {$key1 => 1, $key2 => 2};
test cleanup
Yuki Kimoto authored on 2011-08-10
2074
$insert_param = $dbi->insert_param($param);
2075
$sql = <<"EOS";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2076
insert into $table1 $insert_param
test cleanup
Yuki Kimoto authored on 2011-08-10
2077
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2078
$dbi->execute($sql, param => $param, table => $table1);
2079
is($dbi->select(table => $table1)->one->{$key1}, 1);
2080
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2081

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2085
test 'mycolumn';
2086
$dbi = MyDBI8->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2087
eval { $dbi->execute("drop table $table1") };
2088
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2089
$dbi->execute($create_table1);
2090
$dbi->execute($create_table2);
2091
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2092
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2093
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2094
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2095
$result = $model->select_at(
2096
    column => [
2097
        $model->mycolumn,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2098
        $model->column($table2)
cleanup test
Yuki Kimoto authored on 2011-08-10
2099
    ]
2100
);
2101
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2102
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2103

            
2104
$result = $model->select_at(
2105
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2106
        $model->mycolumn([$key1]),
2107
        $model->column($table2 => [$key1])
cleanup test
Yuki Kimoto authored on 2011-08-10
2108
    ]
2109
);
2110
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2111
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2112
$result = $model->select_at(
2113
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2114
        $model->mycolumn([$key1]),
2115
        {$table2 => [$key1]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2116
    ]
2117
);
2118
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2119
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2120

            
2121
$result = $model->select_at(
2122
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2123
        $model->mycolumn([$key1]),
2124
        ["$table2.$key1", as => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2125
    ]
2126
);
2127
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2128
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2129

            
2130
$result = $model->select_at(
2131
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2132
        $model->mycolumn([$key1]),
2133
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2134
    ]
2135
);
2136
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2137
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2138

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2139
test 'merge_param';
2140
$dbi = DBIx::Custom->new;
2141
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2142
    {$key1 => 1, $key2 => 2, $key3 => 3},
2143
    {$key1 => 1, $key2 => 2},
2144
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2145
];
2146
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2147
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2148

            
2149
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2150
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2151
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2152
];
2153
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2154
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
2155

            
2156
test 'select() param option';
2157
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2158
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2159
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2160
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2161
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2162
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2163
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2164
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
2165
$dbi->insert(table => $table2, param => {$key1 => 2, $key3 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-10
2166
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2167
    table => $table1,
2168
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2169
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2170
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
test cleanup
Yuki Kimoto authored on 2011-08-15
2171
              " $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2172
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2173
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2174
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2175

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

            
2189
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2190
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2191
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2192
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2193
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2194
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2195
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2196
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2197
        "$key1 = :$key1 and $key2 = :$key2",
2198
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2199
    ]
2200
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2201
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2202

            
2203
test 'delete() string where';
2204
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2205
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2206
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2207
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2208
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2209
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2210
    table => $table1,
2211
    where => "$key1 = :$key1 and $key2 = :$key2",
2212
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2213
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2214
$rows = $dbi->select(table => $table1)->all;
2215
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2216

            
2217
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2218
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2219
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2220
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2221
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2222
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2223
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2224
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2225
        "$key1 = :$key1 and $key2 = :$key2",
2226
         {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2227
    ]
2228
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2229
$rows = $dbi->select(table => $table1)->all;
2230
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2231

            
2232

            
2233
test 'update() string where';
2234
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2235
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2236
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2237
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2238
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2239
    table => $table1,
2240
    param => {$key1 => 5},
2241
    where => "$key1 = :$key1 and $key2 = :$key2",
2242
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2243
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2244
$rows = $dbi->select(table => $table1)->all;
2245
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2246

            
2247
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2248
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2249
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2250
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2251
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2252
    table => $table1,
2253
    param => {$key1 => 5},
cleanup test
Yuki Kimoto authored on 2011-08-10
2254
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2255
        "$key1 = :$key1 and $key2 = :$key2",
2256
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2257
    ]
2258
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2259
$rows = $dbi->select(table => $table1)->all;
2260
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2261

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

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

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

            
2288
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2289
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2290
$dbi->execute($create_table1_2);
2291
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2292
    {$key3 => 3},
2293
    primary_key => [$key1, $key2], 
2294
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2295
    id => [1, 2],
2296
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2297
is($dbi->select(table => $table1)->one->{$key1}, 1);
2298
is($dbi->select(table => $table1)->one->{$key2}, 2);
2299
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2300

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2301
test 'model insert id and primary_key option';
2302
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2303
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2304
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2305
$dbi->model($table1)->insert(
cleanup test
Yuki Kimoto authored on 2011-08-10
2306
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2307
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2308
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2309
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2310
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2311
is($row->{$key1}, 1);
2312
is($row->{$key2}, 2);
2313
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2314

            
2315
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2316
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2317
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2318
$dbi->model($table1)->insert(
2319
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2320
    id => [1, 2]
2321
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2322
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2323
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2324
is($row->{$key1}, 1);
2325
is($row->{$key2}, 2);
2326
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2327

            
2328
test 'update and id option';
2329
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2330
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2331
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2332
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2333
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2334
    table => $table1,
2335
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2336
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2337
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2338
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2339
is($dbi->select(table => $table1)->one->{$key1}, 1);
2340
is($dbi->select(table => $table1)->one->{$key2}, 2);
2341
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2342

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2343
$dbi->delete_all(table => $table1);
2344
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2345
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2346
    table => $table1,
2347
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2348
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2349
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2350
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2351
is($dbi->select(table => $table1)->one->{$key1}, 0);
2352
is($dbi->select(table => $table1)->one->{$key2}, 2);
2353
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2354

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

            
2369

            
2370
test 'model update and id option';
2371
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2372
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2373
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2374
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2375
$dbi->model($table1)->update(
cleanup test
Yuki Kimoto authored on 2011-08-10
2376
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2377
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2378
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2379
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2380
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2381
is($row->{$key1}, 1);
2382
is($row->{$key2}, 2);
2383
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2384

            
2385

            
2386
test 'delete and id option';
2387
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2388
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2389
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2390
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2391
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2392
    table => $table1,
2393
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2394
    id => [1, 2],
2395
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2396
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2397

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2398
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2399
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2400
    table => $table1,
2401
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2402
    id => 0,
2403
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2404
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2405

            
2406

            
2407
test 'model delete and id option';
2408
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2409
eval { $dbi->execute("drop table $table1") };
2410
eval { $dbi->execute("drop table $table2") };
2411
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2412
$dbi->execute($create_table1_2);
2413
$dbi->execute($create_table2_2);
2414
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2415
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2416
$dbi->model($table1)->delete(id => [1, 2]);
2417
is_deeply($dbi->select(table => $table1)->all, []);
2418
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2419
$dbi->model($table1)->delete(id => [1, 2]);
2420
is_deeply($dbi->select(table => $table1)->all, []);
2421
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2422
$dbi->model($table3)->delete(id => [1, 2]);
2423
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2424

            
2425

            
2426
test 'select and id option';
2427
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2428
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2429
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2430
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2431
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2432
    table => $table1,
2433
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2434
    id => [1, 2]
2435
);
2436
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2437
is($row->{$key1}, 1);
2438
is($row->{$key2}, 2);
2439
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2440

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2441
$dbi->delete_all(table => $table1);
2442
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2443
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2444
    table => $table1,
2445
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2446
    id => 0,
2447
);
2448
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2449
is($row->{$key1}, 0);
2450
is($row->{$key2}, 2);
2451
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2452

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2453
$dbi->delete_all(table => $table1);
2454
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2455
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2456
    table => $table1,
2457
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2458
    id => [1, 2]
2459
);
2460
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2461
is($row->{$key1}, 1);
2462
is($row->{$key2}, 2);
2463
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2464

            
2465

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

            
2477
test 'column separator is default .';
2478
$dbi = MyDBI7->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2479
eval { $dbi->execute("drop table $table1") };
2480
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2481
$dbi->execute($create_table1);
2482
$dbi->execute($create_table2);
2483
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2484
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2485
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2486
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2487
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2488
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2489
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2490
);
2491
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2492
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2493

            
2494
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2495
    column => [$model->column($table2 => [$key1, $key3])],
2496
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2497
);
2498
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2499
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2500

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2501
test 'separator';
2502
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2503
eval { $dbi->execute("drop table $table1") };
2504
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2505
$dbi->execute($create_table1);
2506
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2507

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2508
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2509
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2510
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2511
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2512
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2513
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2514
);
2515
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2516
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2517
);
2518
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2519
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2520
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2521
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2522
$result = $model->select(
2523
    column => [
2524
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2525
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2526
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2527
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2528
);
2529
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2530
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2531
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2532

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2533
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2534
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2535
$result = $model->select(
2536
    column => [
2537
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2538
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2539
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2540
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2541
);
2542
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2543
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
2544
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2545

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2546
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2547
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2548
$result = $model->select(
2549
    column => [
2550
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2551
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2552
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2553
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2554
);
2555
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2556
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2557
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2558

            
2559

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2560
test 'filter_off';
2561
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2562
eval { $dbi->execute("drop table $table1") };
2563
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2564
$dbi->execute($create_table1);
2565
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2566

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2567
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2568
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2569
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2570
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2571
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2572
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2573
);
2574
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2575
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2576
$model = $dbi->model($table1);
2577
$result = $model->select(column => $key1);
2578
$result->filter($key1 => sub { $_[0] * 2 });
2579
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2580

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2581
test 'available_datetype';
2582
$dbi = DBIx::Custom->connect;
2583
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2584

            
2585

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2586
test 'select prefix option';
2587
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2588
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2589
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2590
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2591
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2592
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2593

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2594
test 'map_param';
2595
$dbi = DBIx::Custom->connect;
2596
$param = $dbi->map_param(
2597
    {id => 1, author => 'Ken', price => 1900},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2598
    id => "$table1.id",
2599
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2600
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
cleanup test
Yuki Kimoto authored on 2011-08-10
2601
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2602
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2603
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
2604

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2605
$param = $dbi->map_param(
2606
    {id => 0, author => 0, price => 0},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2607
    id => "$table1.id",
2608
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2609
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
cleanup test
Yuki Kimoto authored on 2011-08-10
2610
      {if => sub { $_[0] eq 0 }}]
2611
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2612
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
test cleanup
Yuki Kimoto authored on 2011-08-10
2613

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2614
$param = $dbi->map_param(
2615
    {id => '', author => '', price => ''},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2616
    id => "$table1.id",
2617
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2618
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
cleanup test
Yuki Kimoto authored on 2011-08-10
2619
      {if => sub { $_[0] eq 1 }}]
2620
);
2621
is_deeply($param, {});
test cleanup
Yuki Kimoto authored on 2011-08-10
2622

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2623
$param = $dbi->map_param(
2624
    {id => undef, author => undef, price => undef},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2625
    id => "$table1.id",
2626
    price => ["$table1.price", {if => 'exists'}]
cleanup test
Yuki Kimoto authored on 2011-08-10
2627
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2628
is_deeply($param, {"$table1.price" => undef});
test cleanup
Yuki Kimoto authored on 2011-08-10
2629

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2630
$param = $dbi->map_param(
2631
    {price => 'a'},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2632
    id => ["$table1.id", {if => 'exists'}],
2633
    price => ["$table1.price", sub { '%' . $_[0] }, {if => 'exists'}]
cleanup test
Yuki Kimoto authored on 2011-08-10
2634
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2635
is_deeply($param, {"$table1.price" => '%a'});
test cleanup
Yuki Kimoto authored on 2011-08-10
2636

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2637
test 'order';
2638
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2639
eval { $dbi->execute("drop table $table1") };
test cleanup
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({$key1 => 1, $key2 => 1}, table => $table1);
2642
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
2643
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
2644
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2645
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2646
$order->prepend($key1, "$key2 desc");
2647
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2648
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
2649
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2650
$order->prepend("$key1 desc");
2651
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2652
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
2653
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2654

            
2655
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2656
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2657
$result = $dbi->select(table => $table1,
2658
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2659
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2660
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
2661
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
2662
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
2663
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2664

            
2665
test 'tag_parse';
2666
$dbi = DBIx::Custom->connect;
2667
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2668
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2669
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2670
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2671
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2672
ok($@);
2673

            
2674
test 'last_sql';
2675
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2676
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2677
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2678
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
2679
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2680

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2712
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
2713
$result = $dbi->execute(
2714
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2715
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2716
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
2717
);
2718
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2719
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2720

            
2721
test 'high perfomance way';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2722
$dbi->execute("drop table $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2723
$dbi->execute($create_table1_highperformance);
2724
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2725
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2726
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2727
];
2728
{
2729
    my $query;
2730
    foreach my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2731
      $query ||= $dbi->insert($row, table => $table1, query => 1);
2732
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
2733
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2734
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2735
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2736
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2737
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2738
      ]
2739
    );
2740
}
2741

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2742
$dbi->execute("drop table $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2743
$dbi->execute($create_table1_highperformance);
2744
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2745
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2746
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2747
];
2748
{
2749
    my $query;
2750
    my $sth;
2751
    foreach my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2752
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2753
      $sth ||= $query->sth;
2754
      $sth->execute(map { $row->{$_} } sort keys %$row);
2755
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2756
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2757
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2758
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2759
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2760
      ]
2761
    );
2762
}
2763

            
2764
test 'result';
2765
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2766
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2767
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2768
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2769
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2770

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2771
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2772
@rows = ();
2773
while (my $row = $result->fetch) {
2774
    push @rows, [@$row];
2775
}
2776
is_deeply(\@rows, [[1, 2], [3, 4]]);
2777

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2778
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2779
@rows = ();
2780
while (my $row = $result->fetch_hash) {
2781
    push @rows, {%$row};
2782
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2783
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2784

            
2785
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2786
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2787
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2788
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2789
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2790

            
2791
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2792
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2793
$rows = $result->fetch_all;
2794
is_deeply($rows, [[1, 2], [3, 4]]);
2795

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

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

            
2804
$rows = $result->fetch_all;
2805
is_deeply($rows, [[3, 2], [9, 4]], "array");
2806

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

            
2813
test "query_builder";
2814
$datas = [
2815
    # Basic tests
2816
    {   name            => 'placeholder basic',
2817
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
2818
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
2819
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
2820
    },
2821
    {
2822
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
2823
        source            => "{in k1 3}",
2824
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
2825
        columns_expected   => [qw/k1 k1 k1/]
2826
    },
2827
    
2828
    # Table name
2829
    {
2830
        name            => 'placeholder with table name',
2831
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
2832
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
2833
        columns_expected  => [qw/a.k1 a.k2/]
2834
    },
2835
    {   
2836
        name            => 'placeholder in with table name',
2837
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
2838
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
2839
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
2840
    },
2841
    {
2842
        name            => 'not contain tag',
2843
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
2844
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
2845
        columns_expected  => [],
2846
    }
2847
];
2848

            
2849
for (my $i = 0; $i < @$datas; $i++) {
2850
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
2851
    my $dbi = DBIx::Custom->new;
2852
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
2853
    my $query = $builder->build_query($data->{source});
2854
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
2855
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
2856
}
2857

            
cleanup
Yuki Kimoto authored on 2011-08-13
2858
$dbi = DBIx::Custom->new;
2859
$builder = $dbi->query_builder;
2860
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
2861
    p => sub {
2862
        my @args = @_;
2863
        
2864
        my $expand    = "? $args[0] $args[1]";
2865
        my $columns = [2];
2866
        return [$expand, $columns];
2867
    }
2868
);
2869

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
2880
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
2881
    q => 'string'
2882
});
2883

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
2887
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
2888
   r => sub {} 
2889
});
2890

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
2894
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
2895
   s => sub { return ["a", ""]} 
2896
});
2897

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
2901
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
2902
    t => sub {return ["a", []]}
2903
);
2904

            
2905

            
cleanup
Yuki Kimoto authored on 2011-08-13
2906
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
2907
    a => sub {
2908
        return ["? ? ?", ['']];
2909
    }
2910
);
2911
eval{$builder->build_query("{a}")};
2912
like($@, qr/\QPlaceholder count/, "placeholder count is invalid");
2913

            
2914

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

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

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

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

            
2930
test 'variouse source';
2931
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
2932
$query = $builder->build_query($source);
2933
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
2934

            
2935
$source = "abc";
2936
$query = $builder->build_query($source);
2937
is($query->sql, 'abc', "basic : 2");
2938

            
2939
$source = "{= a}";
2940
$query = $builder->build_query($source);
2941
is($query->sql, 'a = ?', "only tag");
2942

            
2943
$source = "000";
2944
$query = $builder->build_query($source);
2945
is($query->sql, '000', "contain 0 value");
2946

            
2947
$source = "a {= b} }";
2948
eval{$builder->build_query($source)};
2949
like($@, qr/unexpected "}"/, "error : 1");
2950

            
2951
$source = "a {= {}";
2952
eval{$builder->build_query($source)};
2953
like($@, qr/unexpected "{"/, "error : 2");
2954

            
2955
test 'select() wrap option';
2956
$dbi = DBIx::Custom->connect;
2957
eval { $dbi->execute("drop table $table1") };
2958
$dbi->execute($create_table1);
2959
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2960
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
2961
$rows = $dbi->select(
2962
    table => $table1,
2963
    column => $key1,
test cleanup
Yuki Kimoto authored on 2011-08-15
2964
    wrap => ["select * from (", ") t where $key1 = 1"]
cleanup test
Yuki Kimoto authored on 2011-08-15
2965
)->all;
2966
is_deeply($rows, [{$key1 => 1}]);
2967

            
2968
eval {
2969
$dbi->select(
2970
    table => $table1,
2971
    column => $key1,
2972
    wrap => 'select * from ('
2973
)
2974
};
2975
like($@, qr/array/);
2976

            
2977
test 'select() sqlfilter option';
2978
$dbi = DBIx::Custom->connect;
2979
eval { $dbi->execute("drop table $table1") };
2980
$dbi->execute($create_table1);
2981
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2982
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
2983
$rows = $dbi->select(
2984
    table => $table1,
2985
    column => $key1,
2986
    sqlfilter => sub {
2987
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
2988
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
2989
        return $sql;
2990
    }
2991
)->all;
2992
is_deeply($rows, [{$key1 => 1}]);
2993

            
2994
test 'dbi method from model';
2995
$dbi = MyDBI9->connect;
2996
eval { $dbi->execute("drop table $table1") };
2997
$dbi->execute($create_table1);
2998
$dbi->setup_model;
2999
$model = $dbi->model($table1);
3000
eval{$model->execute("select * from $table1")};
3001
ok(!$@);
3002

            
3003
test 'column table option';
3004
$dbi = MyDBI9->connect;
3005
eval { $dbi->execute("drop table $table1") };
3006
$dbi->execute($create_table1);
3007
eval { $dbi->execute("drop table $table2") };
3008
$dbi->execute($create_table2);
3009
$dbi->setup_model;
3010
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3011
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3012
$model = $dbi->model($table1);
3013
$result = $model->select(
3014
    column => [
3015
        $model->column($table2, {alias => $table2_alias})
3016
    ],
3017
    where => {"$table2_alias.$key3" => 4}
3018
);
3019
is_deeply($result->one, 
3020
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3021

            
3022
$dbi->separator('__');
3023
$result = $model->select(
3024
    column => [
3025
        $model->column($table2, {alias => $table2_alias})
3026
    ],
3027
    where => {"$table2_alias.$key3" => 4}
3028
);
3029
is_deeply($result->one, 
3030
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3031

            
3032
$dbi->separator('-');
3033
$result = $model->select(
3034
    column => [
3035
        $model->column($table2, {alias => $table2_alias})
3036
    ],
3037
    where => {"$table2_alias.$key3" => 4}
3038
);
3039
is_deeply($result->one, 
3040
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3041

            
3042
test 'create_model';
3043
$dbi = DBIx::Custom->connect;
3044
eval { $dbi->execute("drop table $table1") };
3045
eval { $dbi->execute("drop table $table2") };
3046
$dbi->execute($create_table1);
3047
$dbi->execute($create_table2);
3048

            
3049
$dbi->create_model(
3050
    table => $table1,
3051
    join => [
3052
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3053
    ],
3054
    primary_key => [$key1]
3055
);
3056
$model2 = $dbi->create_model(
3057
    table => $table2
3058
);
3059
$dbi->create_model(
3060
    table => $table3,
3061
    filter => [
3062
        $key1 => {in => sub { uc $_[0] }}
3063
    ]
3064
);
3065
$dbi->setup_model;
3066
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3067
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3068
$model = $dbi->model($table1);
3069
$result = $model->select(
3070
    column => [$model->mycolumn, $model->column($table2)],
3071
    where => {"$table1.$key1" => 1}
3072
);
3073
is_deeply($result->one,
3074
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3075
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3076

            
3077
test 'model method';
3078
$dbi = DBIx::Custom->connect;
3079
eval { $dbi->execute("drop table $table2") };
3080
$dbi->execute($create_table2);
3081
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3082
$model = $dbi->create_model(
3083
    table => $table2
3084
);
3085
$model->method(foo => sub { shift->select(@_) });
3086
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
3087

            
3088
test 'update_param';
3089
$dbi = DBIx::Custom->connect;
3090
eval { $dbi->execute("drop table $table1") };
3091
$dbi->execute($create_table1_2);
3092
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3093
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3094

            
3095
$param = {$key2 => 11};
3096
$update_param = $dbi->update_param($param);
3097
$sql = <<"EOS";
3098
update $table1 $update_param
3099
where $key1 = 1
3100
EOS
3101
$dbi->execute($sql, param => $param);
3102
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3103
$rows   = $result->all;
3104
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3105
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3106
                  "basic");
3107

            
3108

            
3109
$dbi = DBIx::Custom->connect;
3110
eval { $dbi->execute("drop table $table1") };
3111
$dbi->execute($create_table1_2);
3112
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3113
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3114

            
3115
$param = {$key2 => 11, $key3 => 33};
3116
$update_param = $dbi->update_param($param);
3117
$sql = <<"EOS";
3118
update $table1 $update_param
3119
where $key1 = 1
3120
EOS
3121
$dbi->execute($sql, param => $param);
3122
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3123
$rows   = $result->all;
3124
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3125
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3126
                  "basic");
3127

            
3128
$dbi = DBIx::Custom->connect;
3129
eval { $dbi->execute("drop table $table1") };
3130
$dbi->execute($create_table1_2);
3131
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3132
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3133

            
3134
$param = {$key2 => 11, $key3 => 33};
3135
$update_param = $dbi->update_param($param, {no_set => 1});
3136
$sql = <<"EOS";
3137
update $table1 set $update_param
3138
where $key1 = 1
3139
EOS
3140
$dbi->execute($sql, param => $param);
3141
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3142
$rows   = $result->all;
3143
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3144
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3145
                  "update param no_set");
3146

            
3147
            
3148
eval { $dbi->update_param({";" => 1}) };
3149
like($@, qr/not safety/);
3150

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3152
test 'update_param';
3153
$dbi = DBIx::Custom->connect;
3154
eval { $dbi->execute("drop table $table1") };
3155
$dbi->execute($create_table1_2);
3156
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3157
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3158

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3159
$param = {$key2 => 11};
3160
$update_param = $dbi->assign_param($param);
3161
$sql = <<"EOS";
3162
update $table1 set $update_param
3163
where $key1 = 1
3164
EOS
3165
$dbi->execute($sql, param => $param, table => $table1);
3166
$result = $dbi->execute("select * from $table1 order by $key1");
3167
$rows   = $result->all;
3168
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3169
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3170
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3171

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3172
test 'Model class';
3173
$dbi = MyDBI1->connect;
3174
eval { $dbi->execute("drop table $table1") };
3175
$dbi->execute($create_table1);
3176
$model = $dbi->model($table1);
3177
$model->insert({$key1 => 'a', $key2 => 'b'});
3178
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3179
eval { $dbi->execute("drop table $table2") };
3180
$dbi->execute($create_table2);
3181
$model = $dbi->model($table2);
3182
$model->insert({$key1 => 'a'});
3183
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3184
is($dbi->models->{$table1}, $dbi->model($table1));
3185
is($dbi->models->{$table2}, $dbi->model($table2));
3186

            
3187
$dbi = MyDBI4->connect;
3188
eval { $dbi->execute("drop table $table1") };
3189
$dbi->execute($create_table1);
3190
$model = $dbi->model($table1);
3191
$model->insert({$key1 => 'a', $key2 => 'b'});
3192
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3193
eval { $dbi->execute("drop table $table2") };
3194
$dbi->execute($create_table2);
3195
$model = $dbi->model($table2);
3196
$model->insert({$key1 => 'a'});
3197
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3198

            
3199
$dbi = MyDBI5->connect;
3200
eval { $dbi->execute("drop table $table1") };
3201
eval { $dbi->execute("drop table $table2") };
3202
$dbi->execute($create_table1);
3203
$dbi->execute($create_table2);
3204
$model = $dbi->model($table2);
3205
$model->insert({$key1 => 'a'});
3206
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3207
$dbi->insert(table => $table1, param => {$key1 => 1});
3208
$model = $dbi->model($table1);
3209
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3210

            
3211
test 'primary_key';
3212
$dbi = MyDBI1->connect;
3213
$model = $dbi->model($table1);
3214
$model->primary_key([$key1, $key2]);
3215
is_deeply($model->primary_key, [$key1, $key2]);
3216

            
3217
test 'columns';
3218
$dbi = MyDBI1->connect;
3219
$model = $dbi->model($table1);
3220
$model->columns([$key1, $key2]);
3221
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3222

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3223
test 'setup_model';
3224
$dbi = MyDBI1->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3225
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3226
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3227

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3228
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3229
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3230
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3231
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3232
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3233

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3234
test 'each_column';
3235
$dbi = DBIx::Custom->connect;
3236
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3237
eval { $dbi->execute("drop table $table1") };
3238
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3239
eval { $dbi->execute("drop table $table3") };
3240
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3241
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3242

            
3243
$infos = [];
3244
$dbi->each_column(sub {
3245
    my ($self, $table, $column, $cinfo) = @_;
3246
    
3247
    if ($table =~ /^table\d/i) {
3248
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3249
         push @$infos, $info;
3250
    }
3251
});
3252
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3253
is_deeply($infos, 
3254
    [
3255
        [$table1, $key1, $key1],
3256
        [$table1, $key2, $key2],
3257
        [$table2, $key1, $key1],
3258
        [$table2, $key3, $key3]
3259
    ]
3260
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3261
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3262
test 'each_table';
3263
$dbi = DBIx::Custom->connect;
3264
eval { $dbi->execute("drop table $table1") };
3265
eval { $dbi->execute("drop table $table2") };
3266
$dbi->execute($create_table2);
3267
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3268

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3269
$infos = [];
3270
$dbi->each_table(sub {
3271
    my ($self, $table, $table_info) = @_;
3272
    
3273
    if ($table =~ /^table\d/i) {
3274
         my $info = [$table, $table_info->{TABLE_NAME}];
3275
         push @$infos, $info;
3276
    }
3277
});
3278
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3279
is_deeply($infos, 
3280
    [
3281
        [$table1, $table1],
3282
        [$table2, $table2],
3283
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3284
);
3285

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3286
test 'type_rule into';
3287
eval { $dbi->execute("drop table $table1") };
3288
$dbi->execute($create_table1_type);
3289
$dbi = DBIx::Custom->connect;
3290
eval { $dbi->execute("drop table $table1") };
3291
$dbi->execute($create_table1_type);
3292

            
3293
$dbi->type_rule(
3294
    into1 => {
3295
        $date_typename => sub { '2010-' . $_[0] }
3296
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3297
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3298
$dbi->insert({$key1 => '01-01'}, table => $table1);
3299
$result = $dbi->select(table => $table1);
3300
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3301

            
3302
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3303
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3304
$dbi->execute($create_table1_type);
3305
$dbi->type_rule(
3306
    into1 => [
3307
         [$date_typename, $datetime_typename] => sub {
3308
            my $value = shift;
3309
            $value =~ s/02/03/g;
3310
            return $value;
3311
         }
3312
    ]
3313
);
3314
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3315
$result = $dbi->select(table => $table1);
3316
$row = $result->one;
3317
like($row->{$key1}, qr/^2010-01-03/);
3318
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3319

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3320
$dbi = DBIx::Custom->connect;
3321
eval { $dbi->execute("drop table $table1") };
3322
$dbi->execute($create_table1_type);
3323
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3324
$dbi->type_rule(
3325
    into1 => [
3326
        [$date_typename, $datetime_typename] => sub {
3327
            my $value = shift;
3328
            $value =~ s/02/03/g;
3329
            return $value;
3330
        }
3331
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3332
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3333
$result = $dbi->execute(
3334
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3335
    param => {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
3336
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3337
$row = $result->one;
3338
like($row->{$key1}, qr/^2010-01-03/);
3339
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3340

            
3341
$dbi = DBIx::Custom->connect;
3342
eval { $dbi->execute("drop table $table1") };
3343
$dbi->execute($create_table1_type);
3344
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3345
$dbi->type_rule(
3346
    into1 => [
3347
        [$date_typename, $datetime_typename] => sub {
3348
            my $value = shift;
3349
            $value =~ s/02/03/g;
3350
            return $value;
3351
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3352
    ]
3353
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3354
$result = $dbi->execute(
3355
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3356
    param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
3357
    table => $table1
3358
);
3359
$row = $result->one;
3360
like($row->{$key1}, qr/^2010-01-03/);
3361
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3362

            
3363
$dbi = DBIx::Custom->connect;
3364
eval { $dbi->execute("drop table $table1") };
3365
$dbi->execute($create_table1_type);
3366
$dbi->register_filter(convert => sub {
3367
    my $value = shift || '';
3368
    $value =~ s/02/03/;
3369
    return $value;
3370
});
3371
$dbi->type_rule(
3372
    from1 => {
3373
        $date_datatype => 'convert',
3374
    },
3375
    into1 => {
3376
        $date_typename => 'convert',
3377
    }
3378
);
3379
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3380
$result = $dbi->select(table => $table1);
3381
like($result->fetch->[0], qr/^2010-03-03/);
3382

            
3383
test 'type_rule and filter order';
3384
$dbi = DBIx::Custom->connect;
3385
eval { $dbi->execute("drop table $table1") };
3386
$dbi->execute($create_table1_type);
3387
$dbi->type_rule(
3388
    into1 => {
3389
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3390
    },
3391
    into2 => {
3392
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3393
    },
3394
    from1 => {
3395
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3396
    },
3397
    from2 => {
3398
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
3399
    }
3400
);
3401
$dbi->insert({$key1 => '2010-01-03'}, 
3402
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
3403
$result = $dbi->select(table => $table1);
3404
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3405
like($result->fetch_first->[0], qr/^2010-01-09/);
3406

            
3407

            
3408
$dbi = DBIx::Custom->connect;
3409
eval { $dbi->execute("drop table $table1") };
3410
$dbi->execute($create_table1_type);
3411
$dbi->type_rule(
3412
    from1 => {
3413
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3414
    },
3415
    from2 => {
3416
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3417
    },
3418
);
3419
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3420
$result = $dbi->select(table => $table1);
3421
$result->type_rule(
3422
    from1 => {
3423
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3424
    },
3425
    from2 => {
3426
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3427
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3428
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3429
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3430
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3431

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3432
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
3433
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
3434
eval { $dbi->execute("drop table $table1") };
3435
$dbi->execute($create_table1_type);
3436
$dbi->type_rule(
3437
    from1 => {
3438
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3439
    },
3440
    into1 => {
3441
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3442
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3443
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3444
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3445
$result = $dbi->select(table => $table1, type_rule_off => 1);
3446
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3447

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3448
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3449
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3450
$dbi->execute($create_table1_type);
3451
$dbi->type_rule(
3452
    from1 => {
3453
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3454
    },
3455
    into1 => {
3456
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3457
    }
3458
);
3459
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3460
$result = $dbi->select(table => $table1, type_rule_off => 1);
3461
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3462

            
3463
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3464
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3465
$dbi->execute($create_table1_type);
3466
$dbi->type_rule(
3467
    from1 => {
3468
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3469
    },
3470
    into1 => {
3471
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3472
    }
3473
);
3474
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3475
$result = $dbi->select(table => $table1);
3476
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3477

            
3478
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3479
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3480
$dbi->execute($create_table1_type);
3481
$dbi->type_rule(
3482
    from1 => {
3483
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3484
    },
3485
    into1 => {
3486
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3487
    }
3488
);
3489
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3490
$result = $dbi->select(table => $table1);
3491
like($result->fetch->[0], qr/2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3492

            
3493
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3494
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3495
$dbi->execute($create_table1_type);
3496
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
3497
$dbi->type_rule(
3498
    into1 => {
3499
        $date_typename => 'ppp'
3500
    }
3501
);
3502
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3503
$result = $dbi->select(table => $table1);
3504
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3505

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3506
eval{$dbi->type_rule(
3507
    into1 => {
3508
        $date_typename => 'pp'
3509
    }
3510
)};
3511
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3512

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3513
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3514
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3515
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3516
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3517
    $dbi->type_rule(
3518
        from1 => {
3519
            Date => sub { $_[0] * 2 },
3520
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3521
    );
3522
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3523
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3524

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3525
eval {
3526
    $dbi->type_rule(
3527
        into1 => {
3528
            Date => sub { $_[0] * 2 },
3529
        }
3530
    );
3531
};
3532
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3533

            
3534
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3535
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3536
$dbi->execute($create_table1_type);
3537
$dbi->type_rule(
3538
    from1 => {
3539
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3540
    },
3541
    into1 => {
3542
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3543
    }
3544
);
3545
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3546
$result = $dbi->select(table => $table1);
3547
$result->type_rule_off;
3548
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3549

            
3550
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3551
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3552
$dbi->execute($create_table1_type);
3553
$dbi->type_rule(
3554
    from1 => {
3555
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3556
        $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3557
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3558
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3559
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3560
$result = $dbi->select(table => $table1);
3561
$result->type_rule(
3562
    from1 => {
3563
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3564
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3565
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3566
$row = $result->one;
3567
like($row->{$key1}, qr/^2010-01-05/);
3568
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3569

            
3570
$result = $dbi->select(table => $table1);
3571
$result->type_rule(
3572
    from1 => {
3573
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3574
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3575
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3576
$row = $result->one;
3577
like($row->{$key1}, qr/2010-01-05/);
3578
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3579

            
3580
$result = $dbi->select(table => $table1);
3581
$result->type_rule(
3582
    from1 => {
3583
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3584
    }
3585
);
3586
$row = $result->one;
3587
like($row->{$key1}, qr/2010-01-05/);
3588
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3589

            
3590
$result = $dbi->select(table => $table1);
3591
$result->type_rule(
3592
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
3593
);
3594
$row = $result->one;
3595
like($row->{$key1}, qr/2010-01-05/);
3596
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3597

            
3598
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
3599
$result = $dbi->select(table => $table1);
3600
$result->type_rule(
3601
    from1 => [$date_datatype => 'five']
3602
);
3603
$row = $result->one;
3604
like($row->{$key1}, qr/^2010-01-05/);
3605
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3606

            
3607
$result = $dbi->select(table => $table1);
3608
$result->type_rule(
3609
    from1 => [$date_datatype => undef]
3610
);
3611
$row = $result->one;
3612
like($row->{$key1}, qr/^2010-01-03/);
3613
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3614

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3641
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3642
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3643
$dbi->execute($create_table1_type);
3644
$dbi->type_rule(
3645
    into1 => {
3646
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3647
    },
3648
    into2 => {
3649
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3650
    },
3651
    from1 => {
3652
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3653
    },
3654
    from2 => {
3655
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
3656
    }
3657
);
3658
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3659
$result = $dbi->select(table => $table1);
3660
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/);
3661
$result = $dbi->select(table => $table1);
3662
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3663

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3664
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3665
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3666
$dbi->execute($create_table1_type);
3667
$dbi->type_rule(
3668
    into1 => {
3669
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3670
    },
3671
    into2 => {
3672
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3673
    },
3674
    from1 => {
3675
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
3676
    },
3677
    from2 => {
3678
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3679
    }
3680
);
3681
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
3682
$result = $dbi->select(table => $table1);
3683
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/);
3684
$result = $dbi->select(table => $table1);
3685
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3686

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3687
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3688
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3689
$dbi->execute($create_table1_type);
3690
$dbi->type_rule(
3691
    into1 => {
3692
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3693
    },
3694
    into2 => {
3695
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3696
    },
3697
    from1 => {
3698
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3699
    },
3700
    from2 => {
3701
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
3702
    }
3703
);
3704
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
3705
$result = $dbi->select(table => $table1);
3706
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
3707
$result = $dbi->select(table => $table1);
3708
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3709

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
3710
test 'join';
3711
$dbi = DBIx::Custom->connect;
3712
eval { $dbi->execute("drop table $table1") };
3713
$dbi->execute($create_table1);
3714
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3715
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
3716
eval { $dbi->execute("drop table $table2") };
3717
$dbi->execute($create_table2);
3718
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3719
eval { $dbi->execute("drop table $table3") };
3720
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
3721
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
3722
$rows = $dbi->select(
3723
    table => $table1,
3724
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3725
    where   => {"$table1.$key2" => 2},
3726
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
3727
)->all;
3728
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
3729

            
3730
$rows = $dbi->select(
3731
    table => $table1,
3732
    where   => {$key1 => 1},
3733
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
3734
)->all;
3735
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
3736

            
3737
eval {
3738
    $rows = $dbi->select(
3739
        table => $table1,
3740
        column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3741
        where   => {"$table1.$key2" => 2},
3742
        join  => {"$table1.$key1" => "$table2.$key1"}
3743
    );
3744
};
3745
like ($@, qr/array/);
3746

            
3747
$rows = $dbi->select(
3748
    table => $table1,
3749
    where   => {$key1 => 1},
3750
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3751
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
3752
)->all;
3753
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
3754

            
3755
$rows = $dbi->select(
3756
    column => "$table3.$key4 as ${table3}__$key4",
3757
    table => $table1,
3758
    where   => {"$table1.$key1" => 1},
3759
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3760
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
3761
)->all;
3762
is_deeply($rows, [{"${table3}__$key4" => 4}]);
3763

            
3764
$rows = $dbi->select(
3765
    column => "$table1.$key1 as ${table1}__$key1",
3766
    table => $table1,
3767
    where   => {"$table3.$key4" => 4},
3768
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3769
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
3770
)->all;
3771
is_deeply($rows, [{"${table1}__$key1" => 1}]);
3772

            
3773
$dbi = DBIx::Custom->connect;
3774
eval { $dbi->execute("drop table $table1") };
3775
$dbi->execute($create_table1);
3776
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3777
eval { $dbi->execute("drop table $table2") };
3778
$dbi->execute($create_table2);
3779
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3780
$rows = $dbi->select(
3781
    table => $table1,
3782
    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",
3783
    where   => {"$table1.$key2" => 2},
3784
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
3785
)->all;
3786
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
3787
          'quote');
3788

            
3789

            
3790
$dbi = DBIx::Custom->connect;
3791
eval { $dbi->execute("drop table $table1") };
3792
$dbi->execute($create_table1);
3793
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3794
$sql = <<"EOS";
3795
left outer join (
3796
  select * from $table1 t1
3797
  where t1.$key2 = (
3798
    select max(t2.$key2) from $table1 t2
3799
    where t1.$key1 = t2.$key1
3800
  )
3801
) $table3 on $table1.$key1 = $table3.$key1
3802
EOS
3803
$join = [$sql];
3804
$rows = $dbi->select(
3805
    table => $table1,
3806
    column => "$table3.$key1 as ${table3}__$key1",
3807
    join  => $join
3808
)->all;
3809
is_deeply($rows, [{"${table3}__$key1" => 1}]);
3810

            
3811
$dbi = DBIx::Custom->connect;
3812
eval { $dbi->execute("drop table $table1") };
3813
eval { $dbi->execute("drop table $table2") };
3814
$dbi->execute($create_table1);
3815
$dbi->execute($create_table2);
3816
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3817
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
3818
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3819
$result = $dbi->select(
3820
    table => $table1,
3821
    join => [
3822
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
3823
    ]
3824
);
3825
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
3826
$result = $dbi->select(
3827
    table => $table1,
3828
    column => [{$table2 => [$key3]}],
3829
    join => [
3830
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
3831
    ]
3832
);
3833
is_deeply($result->all, [{"$table2.$key3" => 4}]);
3834
$result = $dbi->select(
3835
    table => $table1,
3836
    column => [{$table2 => [$key3]}],
3837
    join => [
3838
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
3839
    ]
3840
);
3841
is_deeply($result->all, [{"$table2.$key3" => 4}]);
3842

            
3843
$dbi = DBIx::Custom->connect;
3844
eval { $dbi->execute("drop table $table1") };
3845
eval { $dbi->execute("drop table $table2") };
3846
$dbi->execute($create_table1);
3847
$dbi->execute($create_table2);
3848
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3849
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
3850
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3851
$result = $dbi->select(
3852
    table => $table1,
3853
    column => [{$table2 => [$key3]}],
3854
    join => [
3855
        {
3856
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
3857
            table => [$table1, $table2]
3858
        }
3859
    ]
3860
);
3861
is_deeply($result->all, [{"$table2.$key3" => 4}]);
3862

            
3863
test 'columns';
3864
$dbi = MyDBI1->connect;
3865
$model = $dbi->model($table1);
3866

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

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