DBIx-Custom / t / common.t /
Newer Older
3924 lines | 129.025kb
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;
cleanup test
Yuki Kimoto authored on 2011-08-16
2041
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2042
eval { $dbi->execute("drop table $table1") };
2043
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2044
$dbi->execute($create_table1);
2045
$dbi->execute($create_table2);
2046
$dbi->separator('__');
cleanup test
Yuki Kimoto authored on 2011-08-16
2047
$DB::single = 1;
cleanup test
Yuki Kimoto authored on 2011-08-10
2048
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2049
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2050
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2051
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2052
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2053
    column => [$model->mycolumn, $model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2054
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2055
);
2056
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2057
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2058

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2235

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

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

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

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

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

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

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

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

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

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

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

            
2372

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

            
2388

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

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

            
2409

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

            
2428

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

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

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

            
2468

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2505
test 'separator';
2506
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2507
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2508
eval { $dbi->execute("drop table $table1") };
2509
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2510
$dbi->execute($create_table1);
2511
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2512

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

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

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

            
2564

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2565
test 'filter_off';
2566
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2567
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2568
eval { $dbi->execute("drop table $table1") };
2569
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2570
$dbi->execute($create_table1);
2571
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2572

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2587
test 'available_datetype';
2588
$dbi = DBIx::Custom->connect;
2589
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2590

            
2591

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2620
$param = $dbi->map_param(
2621
    {id => '', author => '', price => ''},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2622
    id => "$table1.id",
2623
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2624
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
cleanup test
Yuki Kimoto authored on 2011-08-10
2625
      {if => sub { $_[0] eq 1 }}]
2626
);
2627
is_deeply($param, {});
test cleanup
Yuki Kimoto authored on 2011-08-10
2628

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2636
$param = $dbi->map_param(
2637
    {price => 'a'},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2638
    id => ["$table1.id", {if => 'exists'}],
2639
    price => ["$table1.price", sub { '%' . $_[0] }, {if => 'exists'}]
cleanup test
Yuki Kimoto authored on 2011-08-10
2640
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2641
is_deeply($param, {"$table1.price" => '%a'});
test cleanup
Yuki Kimoto authored on 2011-08-10
2642

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

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

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

            
2680
test 'last_sql';
2681
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2682
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2683
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2684
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
2685
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2686

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2784
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2785
@rows = ();
2786
while (my $row = $result->fetch_hash) {
2787
    push @rows, {%$row};
2788
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2789
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2790

            
2791
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2792
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2793
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2794
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2795
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2796

            
2797
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2798
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2799
$rows = $result->fetch_all;
2800
is_deeply($rows, [[1, 2], [3, 4]]);
2801

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

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

            
2810
$rows = $result->fetch_all;
2811
is_deeply($rows, [[3, 2], [9, 4]], "array");
2812

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
2886
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
2887
    q => 'string'
2888
});
2889

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
2893
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
2894
   r => sub {} 
2895
});
2896

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
2907
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
2908
    t => sub {return ["a", []]}
2909
);
2910

            
2911

            
cleanup
Yuki Kimoto authored on 2011-08-13
2912
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
2913
    a => sub {
2914
        return ["? ? ?", ['']];
2915
    }
2916
);
2917
eval{$builder->build_query("{a}")};
2918
like($@, qr/\QPlaceholder count/, "placeholder count is invalid");
2919

            
2920

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

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

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

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

            
2936
test 'variouse source';
2937
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
2938
$query = $builder->build_query($source);
2939
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
2940

            
2941
$source = "abc";
2942
$query = $builder->build_query($source);
2943
is($query->sql, 'abc', "basic : 2");
2944

            
2945
$source = "{= a}";
2946
$query = $builder->build_query($source);
2947
is($query->sql, 'a = ?', "only tag");
2948

            
2949
$source = "000";
2950
$query = $builder->build_query($source);
2951
is($query->sql, '000', "contain 0 value");
2952

            
2953
$source = "a {= b} }";
2954
eval{$builder->build_query($source)};
2955
like($@, qr/unexpected "}"/, "error : 1");
2956

            
2957
$source = "a {= {}";
2958
eval{$builder->build_query($source)};
2959
like($@, qr/unexpected "{"/, "error : 2");
2960

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

            
2974
eval {
2975
$dbi->select(
2976
    table => $table1,
2977
    column => $key1,
2978
    wrap => 'select * from ('
2979
)
2980
};
2981
like($@, qr/array/);
2982

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

            
3001
test 'dbi method from model';
3002
$dbi = MyDBI9->connect;
3003
eval { $dbi->execute("drop table $table1") };
3004
$dbi->execute($create_table1);
3005
$dbi->setup_model;
3006
$model = $dbi->model($table1);
3007
eval{$model->execute("select * from $table1")};
3008
ok(!$@);
3009

            
3010
test 'column table option';
3011
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3012
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3013
eval { $dbi->execute("drop table $table1") };
3014
$dbi->execute($create_table1);
3015
eval { $dbi->execute("drop table $table2") };
3016
$dbi->execute($create_table2);
3017
$dbi->setup_model;
3018
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3019
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3020
$model = $dbi->model($table1);
3021
$result = $model->select(
3022
    column => [
3023
        $model->column($table2, {alias => $table2_alias})
3024
    ],
3025
    where => {"$table2_alias.$key3" => 4}
3026
);
3027
is_deeply($result->one, 
3028
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3029

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

            
3040
$dbi->separator('-');
3041
$result = $model->select(
3042
    column => [
3043
        $model->column($table2, {alias => $table2_alias})
3044
    ],
3045
    where => {"$table2_alias.$key3" => 4}
3046
);
3047
is_deeply($result->one, 
3048
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3049

            
3050
test 'create_model';
3051
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3052
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3053
eval { $dbi->execute("drop table $table1") };
3054
eval { $dbi->execute("drop table $table2") };
3055
$dbi->execute($create_table1);
3056
$dbi->execute($create_table2);
3057

            
3058
$dbi->create_model(
3059
    table => $table1,
3060
    join => [
3061
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3062
    ],
3063
    primary_key => [$key1]
3064
);
3065
$model2 = $dbi->create_model(
3066
    table => $table2
3067
);
3068
$dbi->create_model(
3069
    table => $table3,
3070
    filter => [
3071
        $key1 => {in => sub { uc $_[0] }}
3072
    ]
3073
);
3074
$dbi->setup_model;
3075
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3076
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3077
$model = $dbi->model($table1);
3078
$result = $model->select(
3079
    column => [$model->mycolumn, $model->column($table2)],
3080
    where => {"$table1.$key1" => 1}
3081
);
3082
is_deeply($result->one,
3083
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3084
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3085

            
3086
test 'model method';
3087
$dbi = DBIx::Custom->connect;
3088
eval { $dbi->execute("drop table $table2") };
3089
$dbi->execute($create_table2);
3090
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3091
$model = $dbi->create_model(
3092
    table => $table2
3093
);
3094
$model->method(foo => sub { shift->select(@_) });
3095
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
3096

            
3097
test 'update_param';
3098
$dbi = DBIx::Custom->connect;
3099
eval { $dbi->execute("drop table $table1") };
3100
$dbi->execute($create_table1_2);
3101
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3102
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3103

            
3104
$param = {$key2 => 11};
3105
$update_param = $dbi->update_param($param);
3106
$sql = <<"EOS";
3107
update $table1 $update_param
3108
where $key1 = 1
3109
EOS
3110
$dbi->execute($sql, param => $param);
3111
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3112
$rows   = $result->all;
3113
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3114
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3115
                  "basic");
3116

            
3117

            
3118
$dbi = DBIx::Custom->connect;
3119
eval { $dbi->execute("drop table $table1") };
3120
$dbi->execute($create_table1_2);
3121
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3122
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3123

            
3124
$param = {$key2 => 11, $key3 => 33};
3125
$update_param = $dbi->update_param($param);
3126
$sql = <<"EOS";
3127
update $table1 $update_param
3128
where $key1 = 1
3129
EOS
3130
$dbi->execute($sql, param => $param);
3131
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3132
$rows   = $result->all;
3133
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3134
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3135
                  "basic");
3136

            
3137
$dbi = DBIx::Custom->connect;
3138
eval { $dbi->execute("drop table $table1") };
3139
$dbi->execute($create_table1_2);
3140
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3141
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3142

            
3143
$param = {$key2 => 11, $key3 => 33};
3144
$update_param = $dbi->update_param($param, {no_set => 1});
3145
$sql = <<"EOS";
3146
update $table1 set $update_param
3147
where $key1 = 1
3148
EOS
3149
$dbi->execute($sql, param => $param);
3150
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3151
$rows   = $result->all;
3152
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3153
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3154
                  "update param no_set");
3155

            
3156
            
3157
eval { $dbi->update_param({";" => 1}) };
3158
like($@, qr/not safety/);
3159

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3161
test 'update_param';
3162
$dbi = DBIx::Custom->connect;
3163
eval { $dbi->execute("drop table $table1") };
3164
$dbi->execute($create_table1_2);
3165
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3166
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3167

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3168
$param = {$key2 => 11};
3169
$update_param = $dbi->assign_param($param);
3170
$sql = <<"EOS";
3171
update $table1 set $update_param
3172
where $key1 = 1
3173
EOS
3174
$dbi->execute($sql, param => $param, table => $table1);
3175
$result = $dbi->execute("select * from $table1 order by $key1");
3176
$rows   = $result->all;
3177
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3178
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3179
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3180

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3181
test 'Model class';
3182
$dbi = MyDBI1->connect;
3183
eval { $dbi->execute("drop table $table1") };
3184
$dbi->execute($create_table1);
3185
$model = $dbi->model($table1);
3186
$model->insert({$key1 => 'a', $key2 => 'b'});
3187
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3188
eval { $dbi->execute("drop table $table2") };
3189
$dbi->execute($create_table2);
3190
$model = $dbi->model($table2);
3191
$model->insert({$key1 => 'a'});
3192
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3193
is($dbi->models->{$table1}, $dbi->model($table1));
3194
is($dbi->models->{$table2}, $dbi->model($table2));
3195

            
3196
$dbi = MyDBI4->connect;
3197
eval { $dbi->execute("drop table $table1") };
3198
$dbi->execute($create_table1);
3199
$model = $dbi->model($table1);
3200
$model->insert({$key1 => 'a', $key2 => 'b'});
3201
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3202
eval { $dbi->execute("drop table $table2") };
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}], 'basic');
3207

            
3208
$dbi = MyDBI5->connect;
3209
eval { $dbi->execute("drop table $table1") };
3210
eval { $dbi->execute("drop table $table2") };
3211
$dbi->execute($create_table1);
3212
$dbi->execute($create_table2);
3213
$model = $dbi->model($table2);
3214
$model->insert({$key1 => 'a'});
3215
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3216
$dbi->insert(table => $table1, param => {$key1 => 1});
3217
$model = $dbi->model($table1);
3218
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3219

            
3220
test 'primary_key';
3221
$dbi = MyDBI1->connect;
3222
$model = $dbi->model($table1);
3223
$model->primary_key([$key1, $key2]);
3224
is_deeply($model->primary_key, [$key1, $key2]);
3225

            
3226
test 'columns';
3227
$dbi = MyDBI1->connect;
3228
$model = $dbi->model($table1);
3229
$model->columns([$key1, $key2]);
3230
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3231

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3232
test 'setup_model';
3233
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3234
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3235
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3236
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3237

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3238
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3239
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3240
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3241
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3242
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3243

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3244
test 'each_column';
3245
$dbi = DBIx::Custom->connect;
3246
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3247
eval { $dbi->execute("drop table $table1") };
3248
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3249
eval { $dbi->execute("drop table $table3") };
3250
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3251
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3252

            
3253
$infos = [];
3254
$dbi->each_column(sub {
3255
    my ($self, $table, $column, $cinfo) = @_;
3256
    
3257
    if ($table =~ /^table\d/i) {
3258
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3259
         push @$infos, $info;
3260
    }
3261
});
3262
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3263
is_deeply($infos, 
3264
    [
3265
        [$table1, $key1, $key1],
3266
        [$table1, $key2, $key2],
3267
        [$table2, $key1, $key1],
3268
        [$table2, $key3, $key3]
3269
    ]
3270
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3271
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3272

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3273
test 'each_table';
3274
$dbi = DBIx::Custom->connect;
3275
eval { $dbi->execute("drop table $table1") };
3276
eval { $dbi->execute("drop table $table2") };
3277
$dbi->execute($create_table2);
3278
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3279

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3280
$infos = [];
3281
$dbi->each_table(sub {
3282
    my ($self, $table, $table_info) = @_;
3283
    
3284
    if ($table =~ /^table\d/i) {
3285
         my $info = [$table, $table_info->{TABLE_NAME}];
3286
         push @$infos, $info;
3287
    }
3288
});
3289
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3290
is_deeply($infos, 
3291
    [
3292
        [$table1, $table1],
3293
        [$table2, $table2],
3294
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3295
);
3296

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3297
$dbi = DBIx::Custom->connect;
3298
eval { $dbi->execute("drop table $table1") };
3299
eval { $dbi->execute("drop table $table2") };
3300
$dbi->execute($create_table2);
3301
$dbi->execute($create_table1_type);
3302

            
3303
$infos = [];
3304
$dbi->user_table_info($user_table_info);
3305
$dbi->each_table(sub {
3306
    my ($self, $table, $table_info) = @_;
3307
    
3308
    if ($table =~ /^table\d/i) {
3309
         my $info = [$table, $table_info->{TABLE_NAME}];
3310
         push @$infos, $info;
3311
    }
3312
});
3313
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3314
is_deeply($infos, 
3315
    [
3316
        [$table1, $table1],
3317
        [$table2, $table2],
3318
        [$table3, $table3],
3319
    ]
3320
);
3321

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3322
test 'type_rule into';
3323
eval { $dbi->execute("drop table $table1") };
3324
$dbi->execute($create_table1_type);
3325
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3326
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3327
eval { $dbi->execute("drop table $table1") };
3328
$dbi->execute($create_table1_type);
3329

            
3330
$dbi->type_rule(
3331
    into1 => {
3332
        $date_typename => sub { '2010-' . $_[0] }
3333
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3334
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3335
$dbi->insert({$key1 => '01-01'}, table => $table1);
3336
$result = $dbi->select(table => $table1);
3337
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3338

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3358
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3359
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3360
eval { $dbi->execute("drop table $table1") };
3361
$dbi->execute($create_table1_type);
3362
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3363
$dbi->type_rule(
3364
    into1 => [
3365
        [$date_typename, $datetime_typename] => sub {
3366
            my $value = shift;
3367
            $value =~ s/02/03/g;
3368
            return $value;
3369
        }
3370
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3371
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3372
$result = $dbi->execute(
3373
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3374
    param => {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
3375
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3376
$row = $result->one;
3377
like($row->{$key1}, qr/^2010-01-03/);
3378
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3379

            
3380
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3381
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3382
eval { $dbi->execute("drop table $table1") };
3383
$dbi->execute($create_table1_type);
3384
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3385
$dbi->type_rule(
3386
    into1 => [
3387
        [$date_typename, $datetime_typename] => sub {
3388
            my $value = shift;
3389
            $value =~ s/02/03/g;
3390
            return $value;
3391
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3392
    ]
3393
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3394
$result = $dbi->execute(
3395
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3396
    param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
3397
    table => $table1
3398
);
3399
$row = $result->one;
3400
like($row->{$key1}, qr/^2010-01-03/);
3401
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3402

            
3403
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3404
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3405
eval { $dbi->execute("drop table $table1") };
3406
$dbi->execute($create_table1_type);
3407
$dbi->register_filter(convert => sub {
3408
    my $value = shift || '';
3409
    $value =~ s/02/03/;
3410
    return $value;
3411
});
3412
$dbi->type_rule(
3413
    from1 => {
3414
        $date_datatype => 'convert',
3415
    },
3416
    into1 => {
3417
        $date_typename => 'convert',
3418
    }
3419
);
3420
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3421
$result = $dbi->select(table => $table1);
3422
like($result->fetch->[0], qr/^2010-03-03/);
3423

            
3424
test 'type_rule and filter order';
3425
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3426
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3427
eval { $dbi->execute("drop table $table1") };
3428
$dbi->execute($create_table1_type);
3429
$dbi->type_rule(
3430
    into1 => {
3431
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3432
    },
3433
    into2 => {
3434
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3435
    },
3436
    from1 => {
3437
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3438
    },
3439
    from2 => {
3440
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
3441
    }
3442
);
3443
$dbi->insert({$key1 => '2010-01-03'}, 
3444
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
3445
$result = $dbi->select(table => $table1);
3446
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3447
like($result->fetch_first->[0], qr/^2010-01-09/);
3448

            
3449

            
3450
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3451
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3452
eval { $dbi->execute("drop table $table1") };
3453
$dbi->execute($create_table1_type);
3454
$dbi->type_rule(
3455
    from1 => {
3456
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3457
    },
3458
    from2 => {
3459
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3460
    },
3461
);
3462
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3463
$result = $dbi->select(table => $table1);
3464
$result->type_rule(
3465
    from1 => {
3466
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3467
    },
3468
    from2 => {
3469
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3470
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3471
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3472
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3473
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3474

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3492
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3493
$dbi->user_table_info($user_table_info);
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->type_rule(
3497
    from1 => {
3498
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3499
    },
3500
    into1 => {
3501
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3502
    }
3503
);
3504
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3505
$result = $dbi->select(table => $table1, type_rule_off => 1);
3506
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3507

            
3508
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3509
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3510
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3511
$dbi->execute($create_table1_type);
3512
$dbi->type_rule(
3513
    from1 => {
3514
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3515
    },
3516
    into1 => {
3517
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3518
    }
3519
);
3520
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3521
$result = $dbi->select(table => $table1);
3522
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3523

            
3524
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3525
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3526
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3527
$dbi->execute($create_table1_type);
3528
$dbi->type_rule(
3529
    from1 => {
3530
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3531
    },
3532
    into1 => {
3533
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3534
    }
3535
);
3536
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3537
$result = $dbi->select(table => $table1);
3538
like($result->fetch->[0], qr/2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3539

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3554
eval{$dbi->type_rule(
3555
    into1 => {
3556
        $date_typename => 'pp'
3557
    }
3558
)};
3559
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3560

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3561
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3562
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3563
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3564
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3565
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3566
    $dbi->type_rule(
3567
        from1 => {
3568
            Date => sub { $_[0] * 2 },
3569
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3570
    );
3571
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3572
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3573

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3574
eval {
3575
    $dbi->type_rule(
3576
        into1 => {
3577
            Date => sub { $_[0] * 2 },
3578
        }
3579
    );
3580
};
3581
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3582

            
3583
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3584
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3585
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3586
$dbi->execute($create_table1_type);
3587
$dbi->type_rule(
3588
    from1 => {
3589
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3590
    },
3591
    into1 => {
3592
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3593
    }
3594
);
3595
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3596
$result = $dbi->select(table => $table1);
3597
$result->type_rule_off;
3598
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3599

            
3600
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3601
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3602
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3603
$dbi->execute($create_table1_type);
3604
$dbi->type_rule(
3605
    from1 => {
3606
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3607
        $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3608
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3609
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3610
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3611
$result = $dbi->select(table => $table1);
3612
$result->type_rule(
3613
    from1 => {
3614
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3615
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3616
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3617
$row = $result->one;
3618
like($row->{$key1}, qr/^2010-01-05/);
3619
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3620

            
3621
$result = $dbi->select(table => $table1);
3622
$result->type_rule(
3623
    from1 => {
3624
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3625
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3626
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3627
$row = $result->one;
3628
like($row->{$key1}, qr/2010-01-05/);
3629
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3630

            
3631
$result = $dbi->select(table => $table1);
3632
$result->type_rule(
3633
    from1 => {
3634
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3635
    }
3636
);
3637
$row = $result->one;
3638
like($row->{$key1}, qr/2010-01-05/);
3639
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3640

            
3641
$result = $dbi->select(table => $table1);
3642
$result->type_rule(
3643
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
3644
);
3645
$row = $result->one;
3646
like($row->{$key1}, qr/2010-01-05/);
3647
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3648

            
3649
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
3650
$result = $dbi->select(table => $table1);
3651
$result->type_rule(
3652
    from1 => [$date_datatype => 'five']
3653
);
3654
$row = $result->one;
3655
like($row->{$key1}, qr/^2010-01-05/);
3656
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3657

            
3658
$result = $dbi->select(table => $table1);
3659
$result->type_rule(
3660
    from1 => [$date_datatype => undef]
3661
);
3662
$row = $result->one;
3663
like($row->{$key1}, qr/^2010-01-03/);
3664
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3665

            
3666
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3667
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3668
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3669
$dbi->execute($create_table1_type);
3670
$dbi->type_rule(
3671
    from1 => {
3672
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3673
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3674
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3675
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3676
$result = $dbi->select(table => $table1);
3677
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3678
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3679

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3680
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3681
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3682
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3683
$dbi->execute($create_table1_type);
3684
$dbi->type_rule(
3685
    from1 => {
3686
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3687
    },
3688
);
3689
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3690
$result = $dbi->select(table => $table1);
3691
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3692
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3693

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3718
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3719
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3720
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3721
$dbi->execute($create_table1_type);
3722
$dbi->type_rule(
3723
    into1 => {
3724
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3725
    },
3726
    into2 => {
3727
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3728
    },
3729
    from1 => {
3730
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
3731
    },
3732
    from2 => {
3733
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3734
    }
3735
);
3736
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
3737
$result = $dbi->select(table => $table1);
3738
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/);
3739
$result = $dbi->select(table => $table1);
3740
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3741

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3742
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3743
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3744
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3745
$dbi->execute($create_table1_type);
3746
$dbi->type_rule(
3747
    into1 => {
3748
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3749
    },
3750
    into2 => {
3751
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3752
    },
3753
    from1 => {
3754
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3755
    },
3756
    from2 => {
3757
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
3758
    }
3759
);
3760
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
3761
$result = $dbi->select(table => $table1);
3762
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
3763
$result = $dbi->select(table => $table1);
3764
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3765

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
3766
test 'join';
3767
$dbi = DBIx::Custom->connect;
3768
eval { $dbi->execute("drop table $table1") };
3769
$dbi->execute($create_table1);
3770
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3771
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
3772
eval { $dbi->execute("drop table $table2") };
3773
$dbi->execute($create_table2);
3774
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3775
eval { $dbi->execute("drop table $table3") };
3776
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
3777
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
3778
$rows = $dbi->select(
3779
    table => $table1,
3780
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3781
    where   => {"$table1.$key2" => 2},
3782
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
3783
)->all;
3784
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
3785

            
3786
$rows = $dbi->select(
3787
    table => $table1,
3788
    where   => {$key1 => 1},
3789
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
3790
)->all;
3791
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
3792

            
3793
eval {
3794
    $rows = $dbi->select(
3795
        table => $table1,
3796
        column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3797
        where   => {"$table1.$key2" => 2},
3798
        join  => {"$table1.$key1" => "$table2.$key1"}
3799
    );
3800
};
3801
like ($@, qr/array/);
3802

            
3803
$rows = $dbi->select(
3804
    table => $table1,
3805
    where   => {$key1 => 1},
3806
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3807
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
3808
)->all;
3809
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
3810

            
3811
$rows = $dbi->select(
3812
    column => "$table3.$key4 as ${table3}__$key4",
3813
    table => $table1,
3814
    where   => {"$table1.$key1" => 1},
3815
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3816
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
3817
)->all;
3818
is_deeply($rows, [{"${table3}__$key4" => 4}]);
3819

            
3820
$rows = $dbi->select(
3821
    column => "$table1.$key1 as ${table1}__$key1",
3822
    table => $table1,
3823
    where   => {"$table3.$key4" => 4},
3824
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3825
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
3826
)->all;
3827
is_deeply($rows, [{"${table1}__$key1" => 1}]);
3828

            
3829
$dbi = DBIx::Custom->connect;
3830
eval { $dbi->execute("drop table $table1") };
3831
$dbi->execute($create_table1);
3832
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3833
eval { $dbi->execute("drop table $table2") };
3834
$dbi->execute($create_table2);
3835
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3836
$rows = $dbi->select(
3837
    table => $table1,
3838
    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",
3839
    where   => {"$table1.$key2" => 2},
3840
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
3841
)->all;
3842
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
3843
          'quote');
3844

            
3845

            
3846
$dbi = DBIx::Custom->connect;
3847
eval { $dbi->execute("drop table $table1") };
3848
$dbi->execute($create_table1);
3849
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3850
$sql = <<"EOS";
3851
left outer join (
3852
  select * from $table1 t1
3853
  where t1.$key2 = (
3854
    select max(t2.$key2) from $table1 t2
3855
    where t1.$key1 = t2.$key1
3856
  )
3857
) $table3 on $table1.$key1 = $table3.$key1
3858
EOS
3859
$join = [$sql];
3860
$rows = $dbi->select(
3861
    table => $table1,
3862
    column => "$table3.$key1 as ${table3}__$key1",
3863
    join  => $join
3864
)->all;
3865
is_deeply($rows, [{"${table3}__$key1" => 1}]);
3866

            
3867
$dbi = DBIx::Custom->connect;
3868
eval { $dbi->execute("drop table $table1") };
3869
eval { $dbi->execute("drop table $table2") };
3870
$dbi->execute($create_table1);
3871
$dbi->execute($create_table2);
3872
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3873
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
3874
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3875
$result = $dbi->select(
3876
    table => $table1,
3877
    join => [
3878
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
3879
    ]
3880
);
3881
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
3882
$result = $dbi->select(
3883
    table => $table1,
3884
    column => [{$table2 => [$key3]}],
3885
    join => [
3886
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
3887
    ]
3888
);
3889
is_deeply($result->all, [{"$table2.$key3" => 4}]);
3890
$result = $dbi->select(
3891
    table => $table1,
3892
    column => [{$table2 => [$key3]}],
3893
    join => [
3894
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
3895
    ]
3896
);
3897
is_deeply($result->all, [{"$table2.$key3" => 4}]);
3898

            
3899
$dbi = DBIx::Custom->connect;
3900
eval { $dbi->execute("drop table $table1") };
3901
eval { $dbi->execute("drop table $table2") };
3902
$dbi->execute($create_table1);
3903
$dbi->execute($create_table2);
3904
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3905
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
3906
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3907
$result = $dbi->select(
3908
    table => $table1,
3909
    column => [{$table2 => [$key3]}],
3910
    join => [
3911
        {
3912
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
3913
            table => [$table1, $table2]
3914
        }
3915
    ]
3916
);
3917
is_deeply($result->all, [{"$table2.$key3" => 4}]);
3918

            
3919
test 'columns';
3920
$dbi = MyDBI1->connect;
3921
$model = $dbi->model($table1);
3922

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

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