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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
16
#$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
finished oracle test
Yuki Kimoto authored on 2011-08-15
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
Yuki Kimoto authored on 2011-08-16
80
my $user_column_info;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
81
my $values_clause;
82
my $assign_clause;
cleanup test
Yuki Kimoto authored on 2011-08-15
83

            
test cleanup
Yuki Kimoto authored on 2011-08-15
84
require MyDBI1;
test cleanup
Yuki Kimoto authored on 2011-08-10
85
{
86
    package MyDBI4;
87

            
88
    use strict;
89
    use warnings;
90

            
91
    use base 'DBIx::Custom';
92

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

            
104
    package MyModel2::Base1;
105

            
106
    use strict;
107
    use warnings;
108

            
109
    use base 'DBIx::Custom::Model';
110

            
test cleanup
Yuki Kimoto authored on 2011-08-10
111
    package MyModel2::table1;
test cleanup
Yuki Kimoto authored on 2011-08-10
112

            
113
    use strict;
114
    use warnings;
115

            
116
    use base 'MyModel2::Base1';
117

            
118
    sub insert {
119
        my ($self, $param) = @_;
120
        
121
        return $self->SUPER::insert(param => $param);
122
    }
123

            
124
    sub list { shift->select; }
125

            
test cleanup
Yuki Kimoto authored on 2011-08-10
126
    package MyModel2::table2;
test cleanup
Yuki Kimoto authored on 2011-08-10
127

            
128
    use strict;
129
    use warnings;
130

            
131
    use base 'MyModel2::Base1';
132

            
133
    sub insert {
134
        my ($self, $param) = @_;
135
        
136
        return $self->SUPER::insert(param => $param);
137
    }
138

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

            
141
    package MyModel2::TABLE1;
142

            
143
    use strict;
144
    use warnings;
145

            
146
    use base 'MyModel2::Base1';
147

            
148
    sub insert {
149
        my ($self, $param) = @_;
150
        
151
        return $self->SUPER::insert(param => $param);
152
    }
153

            
154
    sub list { shift->select; }
155

            
156
    package MyModel2::TABLE2;
157

            
158
    use strict;
159
    use warnings;
160

            
161
    use base 'MyModel2::Base1';
162

            
163
    sub insert {
164
        my ($self, $param) = @_;
165
        
166
        return $self->SUPER::insert(param => $param);
167
    }
168

            
169
    sub list { shift->select; }
test cleanup
Yuki Kimoto authored on 2011-08-10
170
}
171
{
172
     package MyDBI5;
173

            
174
    use strict;
175
    use warnings;
176

            
177
    use base 'DBIx::Custom';
178

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
475
eval{$dbi->insert(table => 'table', param => {';' => 1})};
476
like($@, qr/safety/);
477

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-09-02
502
eval { $dbi->execute("drop table $table1") };
503
$dbi->execute($create_table1);
504
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
505
  wrap => {$key1 => sub { "$_[0] - 1" }});
506
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
507
$result = $dbi->execute("select * from $table1");
508
$rows   = $result->all;
509
is_deeply($rows, [{$key1 => 0, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
510

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
511
eval { $dbi->execute("drop table $table1") };
512
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
513
$dbi->insert_timestamp(
514
    $key1 => '5'
515
);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
516
$dbi->insert(table => $table1, param => {$key2 => 2}, timestamp => 1);
517
$result = $dbi->execute("select * from $table1");
518
$rows   = $result->all;
519
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
520

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
521
eval { $dbi->execute("drop table $table1") };
522
$dbi->execute($create_table1);
523
$dbi->insert_timestamp(
524
    [$key1, $key2] => sub { 5 }
525
);
526
$dbi->insert(table => $table1, timestamp => 1);
527
$result = $dbi->execute("select * from $table1");
528
$rows   = $result->all;
529
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
530

            
531
eval { $dbi->execute("drop table $table1") };
532
$dbi->execute($create_table1);
533
$dbi->insert_timestamp(
534
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
535
);
536
$dbi->insert(table => $table1, timestamp => 1);
537
$result = $dbi->execute("select * from $table1");
538
$rows   = $result->all;
539
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
540

            
test cleanup
Yuki Kimoto authored on 2011-08-10
541
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
542
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
543
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
544
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
545
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
546
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
547
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
548
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
549
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
550
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
551
                  "basic");
552
                  
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
553
$dbi->execute("delete from $table1");
554
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
555
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
556
$dbi->update(table => $table1, param => {$key2 => 12}, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
557
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
558
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
559
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
560
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
561
                  "update key same as search key");
562

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
570
$dbi->execute("delete from $table1");
571
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
572
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
573
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
574
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1},
575
              filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
576
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
577
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
578
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
579
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
580
                  "filter");
581

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
590
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
591
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
592
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
593
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
594
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
595
$where->param({$key1 => 1, $key2 => 2});
596
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
597
$result = $dbi->select(table => $table1);
598
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
599

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
600
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
601
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
602
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
603
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
604
    table => $table1,
605
    param => {$key1 => 3},
test cleanup
Yuki Kimoto authored on 2011-08-10
606
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
607
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
608
        {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
609
    ]
610
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
611
$result = $dbi->select(table => $table1);
612
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
613

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
614
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
615
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
616
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
617
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
618
$where->clause(['and', "$key2 = :$key2"]);
619
$where->param({$key2 => 2});
620
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
621
$result = $dbi->select(table => $table1);
622
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
623

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
630
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
631
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
632
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
633
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
634
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
635
$dbi->insert(table => 'table', param => {select => 1});
636
$dbi->update(table => 'table', where => {select => 1}, param => {update => 2});
637
$result = $dbi->execute("select * from ${q}table$p");
638
$rows   = $result->all;
639
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
640

            
641
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
642
like($@, qr/safety/);
643

            
644
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
645
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
646
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
647
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
648
$dbi->insert(table => 'table', param => {select => 1});
649
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
650
$result = $dbi->execute("select * from ${q}table$p");
651
$rows   = $result->all;
652
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
653

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
654
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
655
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
656
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
657
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
658
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
659
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
660
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
661
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
662
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
663
                  "basic");
664

            
updated pod
Yuki Kimoto authored on 2011-09-02
665
eval { $dbi->execute("drop table $table1") };
666
$dbi->execute($create_table1_2);
667
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
668
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
669
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1},
670
wrap => {$key2 => sub { "$_[0] - 1" }});
671
$result = $dbi->execute("select * from $table1 order by $key1");
672
$rows   = $result->all;
673
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5},
674
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
675
                  "basic");
676

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
677
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
678
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
679
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
680
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
681
$dbi->update(table => $table1, param => {$key2 => \"'11'"}, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
682
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
683
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
684
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
685
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
686
                  "basic");
687

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
688
eval { $dbi->execute("drop table $table1") };
689
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
690
$dbi->update_timestamp(
691
    $key1 => '5'
692
);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
693
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
694
$dbi->update(table => $table1, timestamp => 1, where => {$key2 => 2});
695
$result = $dbi->execute("select * from $table1");
696
$rows   = $result->all;
697
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
698

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
699
eval { $dbi->execute("drop table $table1") };
700
$dbi->execute($create_table1);
701
$dbi->update_timestamp(
702
    [$key1, $key2] => sub { '5' }
703
);
704
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
705
$dbi->update_all(table => $table1, timestamp => 1);
706
$result = $dbi->execute("select * from $table1");
707
$rows   = $result->all;
708
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
709

            
710
eval { $dbi->execute("drop table $table1") };
711
$dbi->execute($create_table1);
712
$dbi->update_timestamp(
713
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
714
);
715
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
716
$dbi->update_all(table => $table1, timestamp => 1);
717
$result = $dbi->execute("select * from $table1");
718
$rows   = $result->all;
719
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
720

            
test cleanup
Yuki Kimoto authored on 2011-08-10
721
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
722
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
723
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
724
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
725
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
726
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
727
$dbi->update_all(table => $table1, param => {$key2 => 10}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
728
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
729
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
730
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
731
                  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
732
                  "filter");
733

            
734

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
745
$dbi->execute("delete from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
746
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
747
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
748
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
749
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
750
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
751
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
752
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
753

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
756
$dbi->delete_all(table => $table1);
757
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
758
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
759
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
760
$rows = $dbi->select(table => $table1)->all;
761
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
762

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
766
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
767
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
768
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
769
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
770
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
771
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
772
$where->param({ke1 => 1, $key2 => 2});
773
$dbi->delete(table => $table1, where => $where);
774
$result = $dbi->select(table => $table1);
775
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
776

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
777
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
778
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
779
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
780
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
781
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
782
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
783
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
784
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
785
        {ke1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
786
    ]
787
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
788
$result = $dbi->select(table => $table1);
789
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
790

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
791
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
792
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
793
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
794
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
795
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
796
$rows   = $result->all;
797
is_deeply($rows, [], "basic");
798

            
799
test 'delete error';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
800
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
801
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
802
eval{$dbi->delete(table => $table1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
803
like($@, qr/"where" must be specified/,
804
         "where key-value pairs not specified");
805

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
809
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
810
$dbi = DBIx::Custom->connect;
811
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
812
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
813
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
814
$dbi->insert(table => 'table', param => {select => 1});
815
$dbi->delete(table => 'table', where => {select => 1});
816
$result = $dbi->execute("select * from ${q}table$p");
817
$rows   = $result->all;
818
is_deeply($rows, [], "reserved word");
819

            
820
test 'delete_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
821
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
822
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
823
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
824
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
825
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
826
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
827
$rows   = $result->all;
828
is_deeply($rows, [], "basic");
829

            
830

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
854
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
855
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
856
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
test cleanup
Yuki Kimoto authored on 2011-08-10
857
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
858
    table => [$table1, $table2],
859
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
860
    where   => {"$table1.$key2" => 2},
861
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
862
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
863
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
864

            
865
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
866
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
867
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
868
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
869
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
870
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
871

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

            
875
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
876
eval { $dbi->execute("drop table ${q}table$p") };
877
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
878
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
879
$dbi->insert(table => 'table', param => {select => 1, update => 2});
880
$result = $dbi->select(table => 'table', where => {select => 1});
881
$rows   = $result->all;
882
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
883

            
884
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
885
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
886
$dbi->register_filter(
887
    twice       => sub { $_[0] * 2 },
888
    three_times => sub { $_[0] * 3 }
889
);
890
$dbi->default_fetch_filter('twice');
891
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
892
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
893
$result = $dbi->select(table => $table1);
894
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
895
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
896
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
897

            
898
test 'filters';
899
$dbi = DBIx::Custom->new;
900

            
901
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
902
   'あ', "decode_utf8");
903

            
904
is($dbi->filters->{encode_utf8}->('あ'),
905
   encode_utf8('あ'), "encode_utf8");
906

            
cleanup test
Yuki Kimoto authored on 2011-08-10
907
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
908
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
909
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
910
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
911
$dbi->begin_work;
912
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
913
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
914
$dbi->rollback;
915
$dbi->dbh->{AutoCommit} = 1;
916

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

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

            
921
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
922
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
923
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
924
$dbi->begin_work;
925
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
926
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
927
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
928
$dbi->commit;
929
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
930
$result = $dbi->select(table => $table1);
931
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
932
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
933

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

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

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

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

            
968

            
cleanup test
Yuki Kimoto authored on 2011-08-10
969
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
970
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
971
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
972
$dbi->execute($create_table1);
973

            
974
$dbi->begin_work;
975

            
976
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
977
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
978
    die "Error";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
979
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
980
};
981

            
982
$dbi->rollback if $@;
983

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

            
988
$dbi->begin_work;
989

            
990
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
991
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
992
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
993
};
994

            
995
$dbi->commit unless $@;
996

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

            
1001
$dbi->dbh->{AutoCommit} = 0;
1002
eval{ $dbi->begin_work };
1003
ok($@, "exception");
1004
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1005

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1006
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1007
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1008
$dbi->cache(1);
1009
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1010
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1011
$dbi->execute($source, {}, query => 1);
1012
is_deeply($dbi->{_cached}->{$source}, 
cleanup test
Yuki Kimoto authored on 2011-08-15
1013
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1014

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1015
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1016
$dbi->execute($create_table1);
1017
$dbi->{_cached} = {};
1018
$dbi->cache(0);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1019
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1020
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1021

            
1022
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1023
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1024
$dbi->execute($create_table1);
1025
{
1026
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1027
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1028
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1029
    like($@, qr/\.t /, "fail : not verbose");
1030
}
1031
{
1032
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1033
    eval{$dbi->execute('select * frm $table1')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1034
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1035
}
1036

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

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

            
1045
{
1046
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1047
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1048
    like($@, qr/\Q.t /, "caller spec : not vebose");
1049
}
1050
{
1051
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1052
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1053
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1054
}
1055

            
1056
test 'method';
1057
$dbi->method(
1058
    one => sub { 1 }
1059
);
1060
$dbi->method(
1061
    two => sub { 2 }
1062
);
1063
$dbi->method({
1064
    twice => sub {
1065
        my $self = shift;
1066
        return $_[0] * 2;
1067
    }
1068
});
1069

            
1070
is($dbi->one, 1, "first");
1071
is($dbi->two, 2, "second");
1072
is($dbi->twice(5), 10 , "second");
1073

            
1074
eval {$dbi->XXXXXX};
1075
ok($@, "not exists");
1076

            
1077
test 'out filter';
1078
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1079
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1080
$dbi->execute($create_table1);
1081
$dbi->register_filter(twice => sub { $_[0] * 2 });
1082
$dbi->register_filter(three_times => sub { $_[0] * 3});
1083
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1084
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1085
              $key2 => {out => 'three_times', in => 'twice'});
1086
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1087
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1088
$row   = $result->fetch_hash_first;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1089
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1090
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1091
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1092
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1093

            
1094
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1095
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1096
$dbi->execute($create_table1);
1097
$dbi->register_filter(twice => sub { $_[0] * 2 });
1098
$dbi->register_filter(three_times => sub { $_[0] * 3});
1099
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1100
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1101
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1102
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1103
    $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1104
); 
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1105
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1106
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1107
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1108
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1109

            
1110
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1111
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1112
$dbi->execute($create_table1);
1113
$dbi->register_filter(twice => sub { $_[0] * 2 });
1114
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1115
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1116
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1117
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => undef});
1118
$dbi->update(table => $table1, param => {$key1 => 2}, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1119
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1120
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1121
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
test cleanup
Yuki Kimoto authored on 2011-08-10
1122

            
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);
1126
$dbi->register_filter(twice => sub { $_[0] * 2 });
1127
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1128
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1129
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1130
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1=> undef});
1131
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1132
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1133
$rows   = $result->all;
1134
is_deeply($rows, [], "delete");
1135

            
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);
1139
$dbi->register_filter(twice => sub { $_[0] * 2 });
1140
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1141
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1142
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1143
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
1144
$result = $dbi->select(table => $table1, where => {$key1 => 1});
1145
$result->filter({$key2 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1146
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1147
is_deeply($rows, [{$key1 => 4, $key2 => 4}], "select");
test cleanup
Yuki Kimoto authored on 2011-08-10
1148

            
1149
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1150
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1151
$dbi->execute($create_table1);
1152
$dbi->register_filter(twice => sub { $_[0] * 2 });
1153
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1154
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1155
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1156
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1157
$result = $dbi->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1158
                        param => {$key1 => 1, $key2 => 2},
1159
                        table => [$table1]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1160
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1161
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute");
test cleanup
Yuki Kimoto authored on 2011-08-10
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);
1166
$dbi->register_filter(twice => sub { $_[0] * 2 });
1167
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1168
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1169
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1170
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1171
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1172
                        param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1173
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1174
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1175

            
1176
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1177
eval { $dbi->execute("drop table $table1") };
1178
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1179
$dbi->execute($create_table1);
1180
$dbi->execute($create_table2);
1181
$dbi->register_filter(twice => sub { $_[0] * 2 });
1182
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1183
$dbi->apply_filter(
cleanup test
Yuki Kimoto authored on 2011-08-15
1184
    $table1, $key2 => {out => 'twice', in => 'twice'}
1185
);
1186
$dbi->apply_filter(
1187
    $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1188
);
cleanup test
Yuki Kimoto authored on 2011-08-15
1189
$dbi->insert(table => $table1, param => {$key1 => 5, $key2 => 2}, filter => {$key2 => undef});
1190
$dbi->insert(table => $table2, param => {$key1 => 5, $key3 => 6}, filter => {$key3 => undef});
1191
$result = $dbi->select(
1192
     table => [$table1, $table2],
1193
     column => [$key2, $key3],
1194
     where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1195

            
1196
$result->filter({$key2 => 'twice'});
1197
$rows   = $result->all;
1198
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1199

            
1200
$result = $dbi->select(
1201
     table => [$table1, $table2],
1202
     column => [$key2, $key3],
1203
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1204

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

            
1209
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1210
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1211
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1212
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1213
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1214
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1215

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1216
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1217
$dbi->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
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1222

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1223
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1224
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1225
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1226
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1227
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1228

            
1229
test 'end_filter';
1230
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1231
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1232
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1233
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1234
$result = $dbi->select(table => $table1);
1235
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1236
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1237
$row = $result->fetch_first;
1238
is_deeply($row, [6, 40]);
1239

            
1240
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1241
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1242
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1243
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1244
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1245
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1246
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1247
$row = $result->fetch_first;
1248
is_deeply($row, [6, 12]);
1249

            
1250
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1251
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1252
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1253
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1254
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1255
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1256
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1257
$row = $result->fetch_first;
1258
is_deeply($row, [6, 12]);
1259

            
1260
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1261
$result = $dbi->select(table => $table1);
1262
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1263
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1264
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1265
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1266

            
1267
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1268
$dbi->apply_filter($table1,
1269
    $key1 => {end => sub { $_[0] * 3 } },
1270
    $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1271
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1272
$result = $dbi->select(table => $table1);
1273
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1274
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1275
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1276

            
1277
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1278
$dbi->apply_filter($table1,
1279
    $key1 => {end => sub { $_[0] * 3 } },
1280
    $key2 => {end => 'five_times'}
1281
);
1282
$result = $dbi->select(table => $table1);
1283
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1284
$result->filter($key1 => undef);
1285
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1286
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1287
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1288

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1289
test 'remove_end_filter and remove_filter';
1290
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1291
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1292
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1293
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1294
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1295
$row = $result
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1296
       ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1297
       ->remove_filter
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1298
       ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1299
       ->remove_end_filter
1300
       ->fetch_first;
1301
is_deeply($row, [1, 2]);
1302

            
1303
test 'empty where select';
1304
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1305
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1306
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1307
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1308
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1309
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1310
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1311

            
1312
test 'select query option';
1313
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1314
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1315
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1316
$query = $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1317
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1318
$query = $dbi->update(table => $table1, where => {$key1 => 1}, param => {$key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1319
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1320
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1321
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1322
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1323
is(ref $query, 'DBIx::Custom::Query');
1324

            
1325
test 'where';
1326
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1327
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1328
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1329
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1330
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1331
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1332
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1333

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

            
1338
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1339
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1340
    where => $where
1341
);
1342
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1343
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1344

            
1345
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1346
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1347
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1348
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
1349
        {$key1 => 1}
test cleanup
Yuki Kimoto authored on 2011-08-10
1350
    ]
1351
);
1352
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1353
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1354

            
1355
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1356
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1357
             ->param({$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1358
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1359
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1360
    where => $where
1361
);
1362
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1363
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1364

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

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

            
1393
eval {
1394
$where = $dbi->where
1395
             ->clause(['uuu']);
1396
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1397
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1398
    where => $where
1399
);
1400
};
1401
ok($@);
1402

            
1403
$where = $dbi->where;
1404
is("$where", '');
1405

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

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

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

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

            
1446
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1447
             ->clause("$key1 = :$key1 $key2 = :$key2")
1448
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1449
eval{$where->to_string};
1450
like($@, qr/one column/);
1451

            
1452
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1453
             ->clause(['or', ("$key1 = :$key1") x 3])
1454
             ->param({$key1 => [$dbi->not_exists, 1, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1455
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1456
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1457
    where => $where,
1458
);
1459
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1460
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1461

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

            
1472
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1473
             ->clause(['or', ("$key1 = :$key1") x 3])
1474
             ->param({$key1 => [1, 3, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1475
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1476
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1477
    where => $where,
1478
);
1479
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1480
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1481

            
1482
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1483
             ->clause(['or', ("$key1 = :$key1") x 3])
1484
             ->param({$key1 => [1, $dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1485
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1486
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1487
    where => $where,
1488
);
1489
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1490
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1491

            
1492
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1493
             ->clause(['or', ("$key1 = :$key1") x 3])
1494
             ->param({$key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1495
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1496
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1497
    where => $where,
1498
);
1499
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1500
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1501

            
1502
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1503
             ->clause(['or', ("$key1 = :$key1") x 3])
1504
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1505
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1506
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1507
    where => $where,
1508
);
1509
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1510
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1511

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

            
1522
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1523
             ->clause(['or', ("$key1 = :$key1") x 3])
1524
             ->param({$key1 => []});
test cleanup
Yuki Kimoto authored on 2011-08-10
1525
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1526
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1527
    where => $where,
1528
);
1529
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1530
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1531

            
1532
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1533
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1534
             ->param({$key1 => [2, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1535
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1536
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1537
    where => $where,
1538
);
1539
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1540
is_deeply($row, [{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1541

            
1542
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1543
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1544
             ->param({$key1 => [$dbi->not_exists, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1545
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1546
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1547
    where => $where,
1548
);
1549
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1550
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1551

            
1552
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1553
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1554
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1555
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1556
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1557
    where => $where,
1558
);
1559
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1560
is_deeply($row, [{$key1 => 1, $key2 => 2},{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1561

            
1562
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1563
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1564
             ->param({$key1 => [0, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1565
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1566
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1567
    where => $where,
1568
);
1569
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1570
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1571

            
1572
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1573
             ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1574
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1575
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1576
    where => $where,
1577
);
1578
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1579
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1580

            
1581
eval {$dbi->where(ppp => 1) };
1582
like($@, qr/invalid/);
1583

            
1584
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1585
    clause => ['and', ['or'], ['and', "$key1 = :$key1", "$key2 = :$key2"]],
1586
    param => {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
1587
);
1588
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1589
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1590
    where => $where,
1591
);
1592
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1593
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1594

            
1595

            
1596
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1597
    clause => ['and', ['or'], ['or', ":$key1", ":$key2"]],
test cleanup
Yuki Kimoto authored on 2011-08-10
1598
    param => {}
1599
);
1600
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1601
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1602
    where => $where,
1603
);
1604
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1605
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1606

            
1607
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1608
$where->clause(['and', ":${key1}{=}"]);
1609
$where->param({$key1 => undef});
1610
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1611
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1612
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1613

            
1614
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1615
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1616
$where->param({$key1 => [undef, undef]});
1617
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1618
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1619
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1620
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1621
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1622
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1623

            
1624
test 'register_tag_processor';
1625
$dbi = DBIx::Custom->connect;
1626
$dbi->register_tag_processor(
1627
    a => sub { 1 }
1628
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1629
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1630

            
1631
test 'register_tag';
1632
$dbi = DBIx::Custom->connect;
1633
$dbi->register_tag(
1634
    b => sub { 2 }
1635
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1636
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1637

            
1638
test 'table not specify exception';
1639
$dbi = DBIx::Custom->connect;
1640
eval {$dbi->insert};
1641
like($@, qr/table/);
1642
eval {$dbi->update};
1643
like($@, qr/table/);
1644
eval {$dbi->delete};
1645
like($@, qr/table/);
1646
eval {$dbi->select};
1647
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1648

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1649
test 'more tests';
1650
$dbi = DBIx::Custom->connect;
1651
eval{$dbi->apply_filter('table', 'column', [])};
1652
like($@, qr/apply_filter/);
1653

            
1654
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1655
like($@, qr/apply_filter/);
1656

            
1657
$dbi->apply_filter(
1658

            
1659
);
1660
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1661
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1662
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1663
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1664
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1665
$dbi->apply_filter($table1, $key2, 
test cleanup
Yuki Kimoto authored on 2011-08-10
1666
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1667
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
1668
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1669

            
1670
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1671
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1672
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1673
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1674
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1675
$dbi->apply_filter($table1, $key2, {});
1676
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1677
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1678

            
1679
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1680
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1681
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1682
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1683
like($@, qr/not registered/);
1684
$dbi->method({one => sub { 1 }});
1685
is($dbi->one, 1);
1686

            
1687
eval{DBIx::Custom->connect(dsn => undef)};
1688
like($@, qr/_connect/);
1689

            
1690
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1691
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1692
$dbi->execute($create_table1);
1693
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1694
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1695
             filter => {$key1 => 'twice'});
1696
$row = $dbi->select(table => $table1)->one;
1697
is_deeply($row, {$key1 => 2, $key2 => 2});
1698
eval {$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1699
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
1700
like($@, qr//);
1701

            
1702
$dbi->register_filter(one => sub { });
1703
$dbi->default_fetch_filter('one');
1704
ok($dbi->default_fetch_filter);
1705
$dbi->default_bind_filter('one');
1706
ok($dbi->default_bind_filter);
1707
eval{$dbi->default_fetch_filter('no')};
1708
like($@, qr/not registered/);
1709
eval{$dbi->default_bind_filter('no')};
1710
like($@, qr/not registered/);
1711
$dbi->default_bind_filter(undef);
1712
ok(!defined $dbi->default_bind_filter);
1713
$dbi->default_fetch_filter(undef);
1714
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1715
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1716
like($@, qr/Tag not finished/);
1717

            
1718
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1719
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1720
$dbi->execute($create_table1);
1721
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1722
$result = $dbi->select(table => $table1);
1723
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1724
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1725
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1726
like($@, qr/not registered/);
1727
$result->default_filter(undef);
1728
ok(!defined $result->default_filter);
1729
$result->default_filter('one');
1730
is($result->default_filter->(), 1);
1731

            
1732
test 'dbi_option';
1733
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
1734
ok($dbi->dbh->{PrintError});
1735
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
1736
ok($dbi->dbh->{PrintError});
1737

            
1738
test 'DBIx::Custom::Result stash()';
1739
$result = DBIx::Custom::Result->new;
1740
is_deeply($result->stash, {}, 'default');
1741
$result->stash->{foo} = 1;
1742
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
1743

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1744
test 'delete_at';
1745
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1746
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1747
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1748
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1749
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1750
    table => $table1,
1751
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1752
    where => [1, 2],
1753
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1754
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1755

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1756
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1757
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1758
    table => $table1,
1759
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1760
    where => 1,
1761
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1762
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1763

            
1764
test 'insert_at';
1765
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1766
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1767
$dbi->execute($create_table1_2);
1768
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1769
    primary_key => [$key1, $key2], 
1770
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1771
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1772
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1773
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1774
is($dbi->select(table => $table1)->one->{$key1}, 1);
1775
is($dbi->select(table => $table1)->one->{$key2}, 2);
1776
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1777

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1778
$dbi->delete_all(table => $table1);
1779
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1780
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1781
    primary_key => $key1, 
1782
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1783
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1784
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1785
);
1786

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

            
1791
eval {
1792
    $dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1793
        table => $table1,
1794
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1795
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1796
        param => {$key1 => 1, $key2 => 2, $key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
1797
    );
1798
};
1799
like($@, qr/must be/);
1800

            
1801
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1802
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1803
$dbi->execute($create_table1_2);
1804
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1805
    {$key3 => 3},
1806
    primary_key => [$key1, $key2], 
1807
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1808
    where => [1, 2],
1809
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1810
is($dbi->select(table => $table1)->one->{$key1}, 1);
1811
is($dbi->select(table => $table1)->one->{$key2}, 2);
1812
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1813

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1829
$dbi->delete_all(table => $table1);
1830
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1831
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1832
    table => $table1,
1833
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1834
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1835
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
1836
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1837
is($dbi->select(table => $table1)->one->{$key1}, 1);
1838
is($dbi->select(table => $table1)->one->{$key2}, 2);
1839
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1840

            
1841
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1842
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1843
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1844
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1845
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1846
    {$key3 => 4},
1847
    table => $table1,
1848
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1849
    where => [1, 2]
1850
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1851
is($dbi->select(table => $table1)->one->{$key1}, 1);
1852
is($dbi->select(table => $table1)->one->{$key2}, 2);
1853
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1854

            
1855
test 'select_at';
1856
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1857
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1858
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1859
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1860
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1861
    table => $table1,
1862
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1863
    where => [1, 2]
1864
);
1865
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1866
is($row->{$key1}, 1);
1867
is($row->{$key2}, 2);
1868
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1869

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1870
$dbi->delete_all(table => $table1);
1871
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1872
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1873
    table => $table1,
1874
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1875
    where => 1,
1876
);
1877
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1878
is($row->{$key1}, 1);
1879
is($row->{$key2}, 2);
1880
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1881

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1882
$dbi->delete_all(table => $table1);
1883
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1884
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1885
    table => $table1,
1886
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1887
    where => [1, 2]
1888
);
1889
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1890
is($row->{$key1}, 1);
1891
is($row->{$key2}, 2);
1892
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1893

            
1894
eval {
1895
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1896
        table => $table1,
1897
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1898
        where => {},
1899
    );
1900
};
1901
like($@, qr/must be/);
1902

            
1903
eval {
1904
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1905
        table => $table1,
1906
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1907
        where => [1],
1908
    );
1909
};
1910
like($@, qr/same/);
1911

            
1912
eval {
1913
    $result = $dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1914
        table => $table1,
1915
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1916
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1917
        param => {$key1 => 1, $key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-10
1918
    );
1919
};
1920
like($@, qr/must be/);
1921

            
1922
eval {
1923
    $result = $dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1924
        table => $table1,
1925
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1926
        where => {},
1927
    );
1928
};
1929
like($@, qr/must be/);
1930

            
1931
test 'model delete_at';
1932
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1933
eval { $dbi->execute("drop table $table1") };
1934
eval { $dbi->execute("drop table $table2") };
1935
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1936
$dbi->execute($create_table1_2);
1937
$dbi->execute($create_table2_2);
1938
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1939
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1940
$dbi->model($table1)->delete_at(where => [1, 2]);
1941
is_deeply($dbi->select(table => $table1)->all, []);
1942
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1943
$dbi->model($table1)->delete_at(where => [1, 2]);
1944
is_deeply($dbi->select(table => $table1)->all, []);
1945
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1946
$dbi->model($table3)->delete_at(where => [1, 2]);
1947
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1948

            
1949
test 'model insert_at';
1950
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1951
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1952
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1953
$dbi->model($table1)->insert_at(
cleanup test
Yuki Kimoto authored on 2011-08-10
1954
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1955
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1956
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1957
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
1958
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1959
is($row->{$key1}, 1);
1960
is($row->{$key2}, 2);
1961
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1962

            
1963
test 'model update_at';
1964
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1965
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1966
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1967
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1968
$dbi->model($table1)->update_at(
cleanup test
Yuki Kimoto authored on 2011-08-10
1969
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1970
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
1971
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1972
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
1973
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1974
is($row->{$key1}, 1);
1975
is($row->{$key2}, 2);
1976
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1977

            
1978
test 'model select_at';
1979
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1980
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1981
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1982
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1983
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
1984
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1985
is($row->{$key1}, 1);
1986
is($row->{$key2}, 2);
1987
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1988

            
1989

            
1990
test 'mycolumn and column';
1991
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
1992
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1993
eval { $dbi->execute("drop table $table1") };
1994
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1995
$dbi->execute($create_table1);
1996
$dbi->execute($create_table2);
1997
$dbi->separator('__');
1998
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1999
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2000
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2001
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2002
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2003
    column => [$model->mycolumn, $model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2004
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2005
);
2006
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2007
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2008

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2009
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2010
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2011
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2012
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2013
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2014
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2015
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2016
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2017
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2018
$dbi->execute($sql, param => $param, table => $table1);
2019
is($dbi->select(table => $table1)->one->{$key1}, 1);
2020
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2021

            
2022
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2023
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2024
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2025
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2026
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2027
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2028
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2029
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2030
$dbi->execute($sql, param => $param, table => $table1);
2031
is($dbi->select(table => $table1)->one->{$key1}, 1);
2032
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2033

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2034
eval { $dbi->values_clause({";" => 1}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
2035
like($@, qr/not safety/);
test cleanup
Yuki Kimoto authored on 2011-08-10
2036

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

            
2057
$result = $model->select_at(
2058
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2059
        $model->mycolumn([$key1]),
2060
        $model->column($table2 => [$key1])
cleanup test
Yuki Kimoto authored on 2011-08-10
2061
    ]
2062
);
2063
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2064
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2065
$result = $model->select_at(
2066
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2067
        $model->mycolumn([$key1]),
2068
        {$table2 => [$key1]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2069
    ]
2070
);
2071
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2072
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2073

            
2074
$result = $model->select_at(
2075
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2076
        $model->mycolumn([$key1]),
2077
        ["$table2.$key1", as => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2078
    ]
2079
);
2080
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2081
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2082

            
2083
$result = $model->select_at(
2084
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2085
        $model->mycolumn([$key1]),
2086
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2087
    ]
2088
);
2089
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2090
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2091

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2092
test 'merge_param';
2093
$dbi = DBIx::Custom->new;
2094
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2095
    {$key1 => 1, $key2 => 2, $key3 => 3},
2096
    {$key1 => 1, $key2 => 2},
2097
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2098
];
2099
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2100
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2101

            
2102
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2103
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2104
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2105
];
2106
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2107
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
2108

            
2109
test 'select() param option';
2110
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2111
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2112
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2113
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2114
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2115
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2116
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2117
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
2118
$dbi->insert(table => $table2, param => {$key1 => 2, $key3 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-10
2119
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2120
    table => $table1,
2121
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2122
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2123
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
test cleanup
Yuki Kimoto authored on 2011-08-15
2124
              " $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2125
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2126
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2127
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2128

            
2129
test 'select() string where';
2130
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2131
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2132
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2133
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2134
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2135
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2136
    table => $table1,
2137
    where => "$key1 = :$key1 and $key2 = :$key2",
2138
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2139
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2140
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2141

            
2142
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2143
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2144
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2145
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2146
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2147
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2148
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2149
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2150
        "$key1 = :$key1 and $key2 = :$key2",
2151
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2152
    ]
2153
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2154
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2155

            
2156
test 'delete() string where';
2157
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2158
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2159
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2160
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2161
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2162
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2163
    table => $table1,
2164
    where => "$key1 = :$key1 and $key2 = :$key2",
2165
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2166
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2167
$rows = $dbi->select(table => $table1)->all;
2168
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2169

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

            
2185

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

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

            
2215
test 'insert id and primary_key option';
2216
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2217
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2218
$dbi->execute($create_table1_2);
2219
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2220
    primary_key => [$key1, $key2], 
2221
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2222
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2223
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2224
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2225
is($dbi->select(table => $table1)->one->{$key1}, 1);
2226
is($dbi->select(table => $table1)->one->{$key2}, 2);
2227
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2228

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2229
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2230
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2231
    primary_key => $key1, 
2232
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2233
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2234
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2235
);
2236

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2254
test 'model insert id and primary_key option';
2255
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2256
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2257
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2258
$dbi->model($table1)->insert(
cleanup test
Yuki Kimoto authored on 2011-08-10
2259
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2260
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2261
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2262
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2263
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2264
is($row->{$key1}, 1);
2265
is($row->{$key2}, 2);
2266
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2267

            
2268
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2269
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2270
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2271
$dbi->model($table1)->insert(
2272
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2273
    id => [1, 2]
2274
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2275
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2276
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2277
is($row->{$key1}, 1);
2278
is($row->{$key2}, 2);
2279
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2280

            
2281
test 'update and id option';
2282
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2283
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2284
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2285
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2286
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2287
    table => $table1,
2288
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2289
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2290
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2291
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2292
is($dbi->select(table => $table1)->one->{$key1}, 1);
2293
is($dbi->select(table => $table1)->one->{$key2}, 2);
2294
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2295

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2296
$dbi->delete_all(table => $table1);
2297
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2298
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2299
    table => $table1,
2300
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2301
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2302
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2303
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2304
is($dbi->select(table => $table1)->one->{$key1}, 0);
2305
is($dbi->select(table => $table1)->one->{$key2}, 2);
2306
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2307

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

            
2322

            
2323
test 'model update and id option';
2324
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2325
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2326
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2327
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2328
$dbi->model($table1)->update(
cleanup test
Yuki Kimoto authored on 2011-08-10
2329
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2330
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2331
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2332
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2333
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2334
is($row->{$key1}, 1);
2335
is($row->{$key2}, 2);
2336
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2337

            
2338

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2351
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2352
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2353
    table => $table1,
2354
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2355
    id => 0,
2356
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2357
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2358

            
2359

            
2360
test 'model delete and id option';
2361
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2362
eval { $dbi->execute("drop table $table1") };
2363
eval { $dbi->execute("drop table $table2") };
2364
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2365
$dbi->execute($create_table1_2);
2366
$dbi->execute($create_table2_2);
2367
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2368
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2369
$dbi->model($table1)->delete(id => [1, 2]);
2370
is_deeply($dbi->select(table => $table1)->all, []);
2371
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2372
$dbi->model($table1)->delete(id => [1, 2]);
2373
is_deeply($dbi->select(table => $table1)->all, []);
2374
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2375
$dbi->model($table3)->delete(id => [1, 2]);
2376
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2377

            
2378

            
2379
test 'select and id option';
2380
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2381
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2382
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2383
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2384
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2385
    table => $table1,
2386
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2387
    id => [1, 2]
2388
);
2389
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2390
is($row->{$key1}, 1);
2391
is($row->{$key2}, 2);
2392
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2393

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2394
$dbi->delete_all(table => $table1);
2395
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2396
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2397
    table => $table1,
2398
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2399
    id => 0,
2400
);
2401
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2402
is($row->{$key1}, 0);
2403
is($row->{$key2}, 2);
2404
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2405

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2406
$dbi->delete_all(table => $table1);
2407
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2408
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2409
    table => $table1,
2410
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2411
    id => [1, 2]
2412
);
2413
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2414
is($row->{$key1}, 1);
2415
is($row->{$key2}, 2);
2416
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2417

            
2418

            
2419
test 'model select_at';
2420
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2421
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2422
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2423
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2424
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2425
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2426
is($row->{$key1}, 1);
2427
is($row->{$key2}, 2);
2428
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2429

            
2430
test 'column separator is default .';
2431
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2432
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2433
eval { $dbi->execute("drop table $table1") };
2434
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2435
$dbi->execute($create_table1);
2436
$dbi->execute($create_table2);
2437
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2438
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2439
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2440
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2441
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2442
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2443
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2444
);
2445
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2446
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2447

            
2448
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2449
    column => [$model->column($table2 => [$key1, $key3])],
2450
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2451
);
2452
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2453
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2454

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2455
test 'separator';
2456
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2457
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2458
eval { $dbi->execute("drop table $table1") };
2459
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2460
$dbi->execute($create_table1);
2461
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2462

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2463
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2464
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2465
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2466
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2467
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2468
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2469
);
2470
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2471
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2472
);
2473
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2474
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2475
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2476
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2477
$result = $model->select(
2478
    column => [
2479
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2480
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2481
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2482
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2483
);
2484
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2485
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2486
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2487

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2488
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2489
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2490
$result = $model->select(
2491
    column => [
2492
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2493
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2494
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2495
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2496
);
2497
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2498
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
2499
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2500

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2501
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2502
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2503
$result = $model->select(
2504
    column => [
2505
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2506
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2507
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2508
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2509
);
2510
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2511
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2512
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2513

            
2514

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2515
test 'filter_off';
2516
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2517
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2518
eval { $dbi->execute("drop table $table1") };
2519
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2520
$dbi->execute($create_table1);
2521
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2522

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2523
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2524
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2525
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2526
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2527
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2528
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2529
);
2530
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2531
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2532
$model = $dbi->model($table1);
2533
$result = $model->select(column => $key1);
2534
$result->filter($key1 => sub { $_[0] * 2 });
2535
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2536

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2537
test 'available_datetype';
2538
$dbi = DBIx::Custom->connect;
2539
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2540

            
2541

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2542
test 'select prefix option';
2543
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2544
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2545
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2546
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2547
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2548
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2549

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2550

            
added tests
Yuki Kimoto authored on 2011-08-26
2551
test 'mapper';
2552
$dbi = DBIx::Custom->connect;
2553
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
2554
    id => "$table1.id",
2555
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2556
    price => ["$table1.price", {condition => sub { $_[0] eq 1900 }}]
2557
);
2558
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2559
  "$table1.price" => 1900});
2560

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2561
$dbi = DBIx::Custom->connect;
2562
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
2563
    id => "$table1.id",
2564
    author => ["$table1.author" => $dbi->like_value],
2565
    price => ["$table1.price", {condition => sub { $_[0] eq 1900 }}]
2566
);
2567
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2568
  "$table1.price" => 1900});
2569

            
added tests
Yuki Kimoto authored on 2011-08-26
2570
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
2571
    id => "$table1.id",
2572
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2573
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
2574
      {condition => sub { $_[0] eq 0 }}]
2575
);
2576
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2577

            
2578
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
2579
    id => "$table1.id",
2580
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2581
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
2582
      {condition => sub { $_[0] eq 1 }}]
2583
);
2584
is_deeply($param, {});
2585

            
2586
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
2587
    id => "$table1.id",
2588
    price => ["$table1.price", {condition => 'exists'}]
2589
);
2590
is_deeply($param, {"$table1.price" => undef});
2591

            
2592
$param = $dbi->mapper(param => {price => 'a'})->map(
2593
    id => ["$table1.id", {condition => 'exists'}],
2594
    price => ["$table1.price", sub { '%' . $_[0] }, {condition => 'exists'}]
2595
);
2596
is_deeply($param, {"$table1.price" => '%a'});
2597

            
2598
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
2599
    id => ["$table1.id"],
2600
    price => ["$table1.price", sub { '%' . $_[0] }]
2601
);
2602
is_deeply($param, {"$table1.price" => '%a'});
2603

            
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2604
$param = $dbi->mapper(param => {price => 'a'})->map(
2605
    price => sub { '%' . $_[0] }
2606
);
2607
is_deeply($param, {price => '%a'});
2608

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2609
eval { $dbi->execute("drop table $table1") };
2610
$dbi->execute($create_table1);
2611
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2612
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
2613

            
2614
$where = $dbi->where;
2615
$where->clause(['and', ":${key1}{=}"]);
2616
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
2617
$where->param($param);
2618
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2619
$row = $result->all;
2620
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2621

            
2622
$where = $dbi->where;
2623
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2624
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
2625
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2626
$row = $result->all;
2627
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2628
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2629
$row = $result->all;
2630
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2631

            
2632
$where = $dbi->where;
2633
$where->clause(['and', ":${key1}{=}"]);
2634
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
2635
$where->param($param);
2636
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2637
$row = $result->all;
2638
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2639
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2640
$row = $result->all;
2641
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2642

            
2643
$where = $dbi->where;
2644
$where->clause(['and', ":${key1}{=}"]);
2645
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
2646
  ->pass([$key1, $key2])->map;
2647
$where->param($param);
2648
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2649
$row = $result->all;
2650
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2651

            
2652
$where = $dbi->where;
2653
$where->clause(['and', ":${key1}{=}"]);
2654
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
2655
$where->param($param);
2656
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2657
$row = $result->all;
2658
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2659

            
2660
$where = $dbi->where;
2661
$where->clause(['and', ":${key1}{=}"]);
2662
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
2663
  ->pass([$key1, $key2])->map;
2664
$where->param($param);
2665
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2666
$row = $result->all;
2667
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2668

            
2669
$where = $dbi->where;
2670
$where->clause(['and', ":${key1}{=}"]);
2671
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
2672
$where->param($param);
2673
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2674
$row = $result->all;
2675
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2676

            
2677
$where = $dbi->where;
2678
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
2679
    id => "$table1.id",
2680
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2681
    price => ["$table1.price", {condition => sub { $_[0] eq 1900 }}]
2682
);
2683
$where->param($param);
2684
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2685
  "$table1.price" => 1900});
2686

            
2687
$where = $dbi->where;
2688
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
2689
    id => "$table1.id",
2690
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2691
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, {condition => sub { $_[0] eq 0 }}]
2692
);
2693
$where->param($param);
2694
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2695

            
2696
$where = $dbi->where;
2697
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
2698
    id => "$table1.id",
2699
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2700
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, {condition => sub { $_[0] eq 1 }}]
2701
);
2702
$where->param($param);
2703
is_deeply($where->param, {});
2704

            
2705
$where = $dbi->where;
2706
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
2707
    id => "$table1.id",
2708
    price => ["$table1.price", {condition => 'exists'}]
2709
);
2710
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
2711

            
2712
$where = $dbi->where;
2713
$param = $dbi->mapper(param => {price => 'a'})->map(
2714
    id => ["$table1.id", {condition => 'exists'}],
2715
    price => ["$table1.price", sub { '%' . $_[0] }, {condition => 'exists'}]
2716
);
2717
is_deeply($param, {"$table1.price" => '%a'});
2718

            
2719
$where = $dbi->where;
2720
$param = $dbi->mapper(param => {id => [1, 2], author => 'Ken', price => 1900})->map(
2721
    id => "$table1.id",
2722
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2723
    price => ["$table1.price", {condition => sub { $_[0] eq 1900 }}]
2724
);
2725
is_deeply($param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
2726
  "$table1.price" => 1900});
2727

            
2728
$where = $dbi->where;
2729
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900}, condition => 'length')->map(
2730
    id => "$table1.id",
2731
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2732
    price => ["$table1.price", {condition => sub { $_[0] eq 1900 }}]
2733
);
2734
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2735
  "$table1.price" => 1900});
2736

            
2737
$where = $dbi->where;
2738
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
2739
    id => ["$table1.id", {condition => 'length'}],
2740
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, {condition => 'defined'}],
2741
    price => ["$table1.price", {condition => sub { $_[0] eq 1900 }}]
2742
);
2743
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2744
  "$table1.price" => 1900});
2745

            
2746
$where = $dbi->where;
2747
$param = $dbi->mapper(param => {id => 'a', author => 'b', price => 'c'}, pass => [qw/id author/])
2748
  ->map(price => 'book.price');
2749
is_deeply($param, {id => 'a', author => 'b', 'book.price' => 'c'});
2750

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2751
test 'order';
2752
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2753
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2754
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2755
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2756
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
2757
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
2758
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2759
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2760
$order->prepend($key1, "$key2 desc");
2761
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2762
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
2763
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2764
$order->prepend("$key1 desc");
2765
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2766
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
2767
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2768

            
2769
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2770
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2771
$result = $dbi->select(table => $table1,
2772
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2773
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2774
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
2775
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
2776
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
2777
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2778

            
2779
test 'tag_parse';
2780
$dbi = DBIx::Custom->connect;
2781
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2782
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2783
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2784
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2785
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2786
ok($@);
2787

            
2788
test 'last_sql';
2789
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2790
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2791
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2792
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
2793
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2794

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2826
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
2827
$result = $dbi->execute(
2828
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2829
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2830
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
2831
);
2832
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2833
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2834

            
2835
test 'high perfomance way';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2836
$dbi->execute("drop table $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2837
$dbi->execute($create_table1_highperformance);
2838
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2839
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2840
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2841
];
2842
{
2843
    my $query;
2844
    foreach my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2845
      $query ||= $dbi->insert($row, table => $table1, query => 1);
2846
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
2847
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2848
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2849
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2850
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2851
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2852
      ]
2853
    );
2854
}
2855

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2856
$dbi->execute("drop table $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2857
$dbi->execute($create_table1_highperformance);
2858
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2859
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2860
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2861
];
2862
{
2863
    my $query;
2864
    my $sth;
2865
    foreach my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2866
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2867
      $sth ||= $query->sth;
2868
      $sth->execute(map { $row->{$_} } sort keys %$row);
2869
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2870
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2871
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2872
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2873
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2874
      ]
2875
    );
2876
}
2877

            
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2878
$dbi->execute("drop table $table1");
2879
$dbi->execute($create_table1_highperformance);
2880
$rows = [
2881
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
2882
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
2883
];
2884
{
2885
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
2886
    my $query;
2887
    foreach my $row (@$rows) {
2888
      $query ||= $model->insert($row, id => 1, query => 1);
2889
      $model->execute($query, $row, id => 1, filter => {$key7 => sub { $_[0] * 2 }});
2890
    }
2891
    is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
2892
      [
2893
          {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 1},
2894
          {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 1},
2895
      ]
2896
    );
2897
}
2898

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2899
test 'result';
2900
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2901
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2902
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2903
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2904
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2905

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2906
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2907
@rows = ();
2908
while (my $row = $result->fetch) {
2909
    push @rows, [@$row];
2910
}
2911
is_deeply(\@rows, [[1, 2], [3, 4]]);
2912

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2913
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2914
@rows = ();
2915
while (my $row = $result->fetch_hash) {
2916
    push @rows, {%$row};
2917
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2918
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2919

            
2920
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2921
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2922
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2923
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2924
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2925

            
2926
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2927
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2928
$rows = $result->fetch_all;
2929
is_deeply($rows, [[1, 2], [3, 4]]);
2930

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

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

            
2939
$rows = $result->fetch_all;
2940
is_deeply($rows, [[3, 2], [9, 4]], "array");
2941

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

            
2948
test "query_builder";
2949
$datas = [
2950
    # Basic tests
2951
    {   name            => 'placeholder basic',
2952
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
2953
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
2954
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
2955
    },
2956
    {
2957
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
2958
        source            => "{in k1 3}",
2959
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
2960
        columns_expected   => [qw/k1 k1 k1/]
2961
    },
2962
    
2963
    # Table name
2964
    {
2965
        name            => 'placeholder with table name',
2966
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
2967
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
2968
        columns_expected  => [qw/a.k1 a.k2/]
2969
    },
2970
    {   
2971
        name            => 'placeholder in with table name',
2972
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
2973
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
2974
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
2975
    },
2976
    {
2977
        name            => 'not contain tag',
2978
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
2979
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
2980
        columns_expected  => [],
2981
    }
2982
];
2983

            
2984
for (my $i = 0; $i < @$datas; $i++) {
2985
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
2986
    my $dbi = DBIx::Custom->new;
2987
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
2988
    my $query = $builder->build_query($data->{source});
2989
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
2990
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
2991
}
2992

            
cleanup
Yuki Kimoto authored on 2011-08-13
2993
$dbi = DBIx::Custom->new;
2994
$builder = $dbi->query_builder;
2995
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
2996
    p => sub {
2997
        my @args = @_;
2998
        
2999
        my $expand    = "? $args[0] $args[1]";
3000
        my $columns = [2];
3001
        return [$expand, $columns];
3002
    }
3003
);
3004

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3015
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3016
    q => 'string'
3017
});
3018

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3022
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3023
   r => sub {} 
3024
});
3025

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3029
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3030
   s => sub { return ["a", ""]} 
3031
});
3032

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3036
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3037
    t => sub {return ["a", []]}
3038
);
3039

            
3040

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

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

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

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

            
3056
test 'variouse source';
3057
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3058
$query = $builder->build_query($source);
3059
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3060

            
3061
$source = "abc";
3062
$query = $builder->build_query($source);
3063
is($query->sql, 'abc', "basic : 2");
3064

            
3065
$source = "{= a}";
3066
$query = $builder->build_query($source);
3067
is($query->sql, 'a = ?', "only tag");
3068

            
3069
$source = "000";
3070
$query = $builder->build_query($source);
3071
is($query->sql, '000', "contain 0 value");
3072

            
3073
$source = "a {= b} }";
3074
eval{$builder->build_query($source)};
3075
like($@, qr/unexpected "}"/, "error : 1");
3076

            
3077
$source = "a {= {}";
3078
eval{$builder->build_query($source)};
3079
like($@, qr/unexpected "{"/, "error : 2");
3080

            
3081
test 'select() sqlfilter option';
3082
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3083
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3084
eval { $dbi->execute("drop table $table1") };
3085
$dbi->execute($create_table1);
3086
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3087
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3088
$rows = $dbi->select(
3089
    table => $table1,
3090
    column => $key1,
3091
    sqlfilter => sub {
3092
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
3093
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
3094
        return $sql;
3095
    }
3096
)->all;
3097
is_deeply($rows, [{$key1 => 1}]);
3098

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3099
test 'select() after_build_sql option';
3100
$dbi = DBIx::Custom->connect;
3101
$dbi->user_table_info($user_table_info);
3102
eval { $dbi->execute("drop table $table1") };
3103
$dbi->execute($create_table1);
3104
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3105
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3106
$rows = $dbi->select(
3107
    table => $table1,
3108
    column => $key1,
3109
    after_build_sql => sub {
3110
        my $sql = shift;
3111
        $sql = "select * from ( $sql ) t where $key1 = 1";
3112
        return $sql;
3113
    }
3114
)->all;
3115
is_deeply($rows, [{$key1 => 1}]);
3116

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3117
test 'dbi method from model';
3118
$dbi = MyDBI9->connect;
3119
eval { $dbi->execute("drop table $table1") };
3120
$dbi->execute($create_table1);
3121
$dbi->setup_model;
3122
$model = $dbi->model($table1);
3123
eval{$model->execute("select * from $table1")};
3124
ok(!$@);
3125

            
3126
test 'column table option';
3127
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3128
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3129
eval { $dbi->execute("drop table $table1") };
3130
$dbi->execute($create_table1);
3131
eval { $dbi->execute("drop table $table2") };
3132
$dbi->execute($create_table2);
3133
$dbi->setup_model;
3134
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3135
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3136
$model = $dbi->model($table1);
3137
$result = $model->select(
3138
    column => [
3139
        $model->column($table2, {alias => $table2_alias})
3140
    ],
3141
    where => {"$table2_alias.$key3" => 4}
3142
);
3143
is_deeply($result->one, 
3144
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3145

            
3146
$dbi->separator('__');
3147
$result = $model->select(
3148
    column => [
3149
        $model->column($table2, {alias => $table2_alias})
3150
    ],
3151
    where => {"$table2_alias.$key3" => 4}
3152
);
3153
is_deeply($result->one, 
3154
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3155

            
3156
$dbi->separator('-');
3157
$result = $model->select(
3158
    column => [
3159
        $model->column($table2, {alias => $table2_alias})
3160
    ],
3161
    where => {"$table2_alias.$key3" => 4}
3162
);
3163
is_deeply($result->one, 
3164
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3165

            
3166
test 'create_model';
3167
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3168
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3169
eval { $dbi->execute("drop table $table1") };
3170
eval { $dbi->execute("drop table $table2") };
3171
$dbi->execute($create_table1);
3172
$dbi->execute($create_table2);
3173

            
3174
$dbi->create_model(
3175
    table => $table1,
3176
    join => [
3177
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3178
    ],
3179
    primary_key => [$key1]
3180
);
3181
$model2 = $dbi->create_model(
3182
    table => $table2
3183
);
3184
$dbi->create_model(
3185
    table => $table3,
3186
    filter => [
3187
        $key1 => {in => sub { uc $_[0] }}
3188
    ]
3189
);
3190
$dbi->setup_model;
3191
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3192
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3193
$model = $dbi->model($table1);
3194
$result = $model->select(
3195
    column => [$model->mycolumn, $model->column($table2)],
3196
    where => {"$table1.$key1" => 1}
3197
);
3198
is_deeply($result->one,
3199
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3200
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3201

            
3202
test 'model method';
3203
$dbi = DBIx::Custom->connect;
3204
eval { $dbi->execute("drop table $table2") };
3205
$dbi->execute($create_table2);
3206
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3207
$model = $dbi->create_model(
3208
    table => $table2
3209
);
3210
$model->method(foo => sub { shift->select(@_) });
3211
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
3212

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3213
test 'assign_clause';
cleanup test
Yuki Kimoto authored on 2011-08-15
3214
$dbi = DBIx::Custom->connect;
3215
eval { $dbi->execute("drop table $table1") };
3216
$dbi->execute($create_table1_2);
3217
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3218
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3219

            
3220
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3221
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3222
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3223
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3224
where $key1 = 1
3225
EOS
3226
$dbi->execute($sql, param => $param);
3227
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3228
$rows   = $result->all;
3229
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3230
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3231
                  "basic");
3232

            
3233

            
3234
$dbi = DBIx::Custom->connect;
3235
eval { $dbi->execute("drop table $table1") };
3236
$dbi->execute($create_table1_2);
3237
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3238
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3239

            
3240
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3241
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3242
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3243
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3244
where $key1 = 1
3245
EOS
3246
$dbi->execute($sql, param => $param);
3247
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3248
$rows   = $result->all;
3249
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3250
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3251
                  "basic");
3252

            
3253
$dbi = DBIx::Custom->connect;
3254
eval { $dbi->execute("drop table $table1") };
3255
$dbi->execute($create_table1_2);
3256
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3257
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3258

            
3259
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3260
$assign_clause = $dbi->update_param($param, {no_set => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
3261
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3262
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3263
where $key1 = 1
3264
EOS
3265
$dbi->execute($sql, param => $param);
3266
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3267
$rows   = $result->all;
3268
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3269
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3270
                  "update param no_set");
3271

            
3272
            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3273
eval { $dbi->assign_clause({";" => 1}) };
cleanup test
Yuki Kimoto authored on 2011-08-15
3274
like($@, qr/not safety/);
3275

            
3276
$dbi = DBIx::Custom->connect;
3277
eval { $dbi->execute("drop table $table1") };
3278
$dbi->execute($create_table1_2);
3279
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3280
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3281

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3282
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3283
$assign_clause = $dbi->assign_param($param);
3284
$sql = <<"EOS";
3285
update $table1 set $assign_clause
3286
where $key1 = 1
3287
EOS
3288
$dbi->execute($sql, param => $param, table => $table1);
3289
$result = $dbi->execute("select * from $table1 order by $key1");
3290
$rows   = $result->all;
3291
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3292
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3293
                  "basic");
3294

            
3295
$param = {$key2 => 11};
3296
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3297
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3298
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3299
where $key1 = 1
3300
EOS
3301
$dbi->execute($sql, param => $param, table => $table1);
3302
$result = $dbi->execute("select * from $table1 order by $key1");
3303
$rows   = $result->all;
3304
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3305
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3306
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3307

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3308
test 'Model class';
3309
$dbi = MyDBI1->connect;
3310
eval { $dbi->execute("drop table $table1") };
3311
$dbi->execute($create_table1);
3312
$model = $dbi->model($table1);
3313
$model->insert({$key1 => 'a', $key2 => 'b'});
3314
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3315
eval { $dbi->execute("drop table $table2") };
3316
$dbi->execute($create_table2);
3317
$model = $dbi->model($table2);
3318
$model->insert({$key1 => 'a'});
3319
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3320
is($dbi->models->{$table1}, $dbi->model($table1));
3321
is($dbi->models->{$table2}, $dbi->model($table2));
3322

            
3323
$dbi = MyDBI4->connect;
3324
eval { $dbi->execute("drop table $table1") };
3325
$dbi->execute($create_table1);
3326
$model = $dbi->model($table1);
3327
$model->insert({$key1 => 'a', $key2 => 'b'});
3328
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3329
eval { $dbi->execute("drop table $table2") };
3330
$dbi->execute($create_table2);
3331
$model = $dbi->model($table2);
3332
$model->insert({$key1 => 'a'});
3333
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3334

            
3335
$dbi = MyDBI5->connect;
3336
eval { $dbi->execute("drop table $table1") };
3337
eval { $dbi->execute("drop table $table2") };
3338
$dbi->execute($create_table1);
3339
$dbi->execute($create_table2);
3340
$model = $dbi->model($table2);
3341
$model->insert({$key1 => 'a'});
3342
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3343
$dbi->insert(table => $table1, param => {$key1 => 1});
3344
$model = $dbi->model($table1);
3345
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3346

            
3347
test 'primary_key';
3348
$dbi = MyDBI1->connect;
3349
$model = $dbi->model($table1);
3350
$model->primary_key([$key1, $key2]);
3351
is_deeply($model->primary_key, [$key1, $key2]);
3352

            
3353
test 'columns';
3354
$dbi = MyDBI1->connect;
3355
$model = $dbi->model($table1);
3356
$model->columns([$key1, $key2]);
3357
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3358

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3359
test 'setup_model';
3360
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3361
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3362
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3363
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3364

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3365
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3366
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3367
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3368
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3369
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3370

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3371
test 'each_column';
3372
$dbi = DBIx::Custom->connect;
3373
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3374
eval { $dbi->execute("drop table $table1") };
3375
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3376
eval { $dbi->execute("drop table $table3") };
3377
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3378
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3379

            
3380
$infos = [];
3381
$dbi->each_column(sub {
3382
    my ($self, $table, $column, $cinfo) = @_;
3383
    
3384
    if ($table =~ /^table\d/i) {
3385
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3386
         push @$infos, $info;
3387
    }
3388
});
3389
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3390
is_deeply($infos, 
3391
    [
3392
        [$table1, $key1, $key1],
3393
        [$table1, $key2, $key2],
3394
        [$table2, $key1, $key1],
3395
        [$table2, $key3, $key3]
3396
    ]
3397
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3398
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3399

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3400
test 'each_table';
3401
$dbi = DBIx::Custom->connect;
3402
eval { $dbi->execute("drop table $table1") };
3403
eval { $dbi->execute("drop table $table2") };
3404
$dbi->execute($create_table2);
3405
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3406

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3407
$infos = [];
3408
$dbi->each_table(sub {
3409
    my ($self, $table, $table_info) = @_;
3410
    
3411
    if ($table =~ /^table\d/i) {
3412
         my $info = [$table, $table_info->{TABLE_NAME}];
3413
         push @$infos, $info;
3414
    }
3415
});
3416
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3417
is_deeply($infos, 
3418
    [
3419
        [$table1, $table1],
3420
        [$table2, $table2],
3421
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3422
);
3423

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3424
$dbi = DBIx::Custom->connect;
3425
eval { $dbi->execute("drop table $table1") };
3426
eval { $dbi->execute("drop table $table2") };
3427
$dbi->execute($create_table2);
3428
$dbi->execute($create_table1_type);
3429

            
3430
$infos = [];
3431
$dbi->user_table_info($user_table_info);
3432
$dbi->each_table(sub {
3433
    my ($self, $table, $table_info) = @_;
3434
    
3435
    if ($table =~ /^table\d/i) {
3436
         my $info = [$table, $table_info->{TABLE_NAME}];
3437
         push @$infos, $info;
3438
    }
3439
});
3440
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3441
is_deeply($infos, 
3442
    [
3443
        [$table1, $table1],
3444
        [$table2, $table2],
3445
        [$table3, $table3],
3446
    ]
3447
);
3448

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3449
test 'type_rule into';
3450
eval { $dbi->execute("drop table $table1") };
3451
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3452
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3453

            
3454

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3455
$dbi = DBIx::Custom->connect;
3456
eval { $dbi->execute("drop table $table1") };
3457
$dbi->execute($create_table1_type);
3458

            
cleanup
Yuki Kimoto authored on 2011-08-16
3459
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3460
$dbi->type_rule(
3461
    into1 => {
3462
        $date_typename => sub { '2010-' . $_[0] }
3463
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3464
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3465
$dbi->insert({$key1 => '01-01'}, table => $table1);
3466
$result = $dbi->select(table => $table1);
3467
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3468

            
3469
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3470
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3471
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3472
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3473
$dbi->type_rule(
3474
    into1 => [
3475
         [$date_typename, $datetime_typename] => sub {
3476
            my $value = shift;
3477
            $value =~ s/02/03/g;
3478
            return $value;
3479
         }
3480
    ]
3481
);
3482
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3483
$result = $dbi->select(table => $table1);
3484
$row = $result->one;
3485
like($row->{$key1}, qr/^2010-01-03/);
3486
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3487

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3488
$dbi = DBIx::Custom->connect;
3489
eval { $dbi->execute("drop table $table1") };
3490
$dbi->execute($create_table1_type);
3491
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3492
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3493
$dbi->type_rule(
3494
    into1 => [
3495
        [$date_typename, $datetime_typename] => sub {
3496
            my $value = shift;
3497
            $value =~ s/02/03/g;
3498
            return $value;
3499
        }
3500
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3501
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3502
$result = $dbi->execute(
3503
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3504
    param => {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
3505
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3506
$row = $result->one;
3507
like($row->{$key1}, qr/^2010-01-03/);
3508
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3509

            
3510
$dbi = DBIx::Custom->connect;
3511
eval { $dbi->execute("drop table $table1") };
3512
$dbi->execute($create_table1_type);
3513
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3514
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3515
$dbi->type_rule(
3516
    into1 => [
3517
        [$date_typename, $datetime_typename] => sub {
3518
            my $value = shift;
3519
            $value =~ s/02/03/g;
3520
            return $value;
3521
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3522
    ]
3523
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3524
$result = $dbi->execute(
3525
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3526
    param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
3527
    table => $table1
3528
);
3529
$row = $result->one;
3530
like($row->{$key1}, qr/^2010-01-03/);
3531
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3532

            
3533
$dbi = DBIx::Custom->connect;
3534
eval { $dbi->execute("drop table $table1") };
3535
$dbi->execute($create_table1_type);
3536
$dbi->register_filter(convert => sub {
3537
    my $value = shift || '';
3538
    $value =~ s/02/03/;
3539
    return $value;
3540
});
cleanup
Yuki Kimoto authored on 2011-08-16
3541
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3542
$dbi->type_rule(
3543
    from1 => {
3544
        $date_datatype => 'convert',
3545
    },
3546
    into1 => {
3547
        $date_typename => 'convert',
3548
    }
3549
);
3550
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3551
$result = $dbi->select(table => $table1);
3552
like($result->fetch->[0], qr/^2010-03-03/);
3553

            
3554
test 'type_rule and filter order';
3555
$dbi = DBIx::Custom->connect;
3556
eval { $dbi->execute("drop table $table1") };
3557
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3558
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3559
$dbi->type_rule(
3560
    into1 => {
3561
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3562
    },
3563
    into2 => {
3564
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3565
    },
3566
    from1 => {
3567
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3568
    },
3569
    from2 => {
3570
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
3571
    }
3572
);
3573
$dbi->insert({$key1 => '2010-01-03'}, 
3574
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
3575
$result = $dbi->select(table => $table1);
3576
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3577
like($result->fetch_first->[0], qr/^2010-01-09/);
3578

            
3579

            
3580
$dbi = DBIx::Custom->connect;
3581
eval { $dbi->execute("drop table $table1") };
3582
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3583
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3584
$dbi->type_rule(
3585
    from1 => {
3586
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3587
    },
3588
    from2 => {
3589
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3590
    },
3591
);
3592
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3593
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3594
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3595
$result->type_rule(
3596
    from1 => {
3597
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3598
    },
3599
    from2 => {
3600
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3601
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3602
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3603
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3604
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3605

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3606
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
3607
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
3608
eval { $dbi->execute("drop table $table1") };
3609
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3610
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3611
$dbi->type_rule(
3612
    from1 => {
3613
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3614
    },
3615
    into1 => {
3616
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3617
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3618
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3619
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3620
$result = $dbi->select(table => $table1, type_rule_off => 1);
3621
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3622

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3623
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3624
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3625
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3626
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3627
$dbi->type_rule(
3628
    from1 => {
3629
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3630
    },
3631
    into1 => {
3632
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3633
    }
3634
);
3635
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3636
$result = $dbi->select(table => $table1, type_rule_off => 1);
3637
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3638

            
3639
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3640
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3641
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3642
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3643
$dbi->type_rule(
3644
    from1 => {
3645
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3646
    },
3647
    into1 => {
3648
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3649
    }
3650
);
3651
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3652
$result = $dbi->select(table => $table1);
3653
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3654

            
3655
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3656
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3657
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3658
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3659
$dbi->type_rule(
3660
    from1 => {
3661
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3662
    },
3663
    into1 => {
3664
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3665
    }
3666
);
3667
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3668
$result = $dbi->select(table => $table1);
3669
like($result->fetch->[0], qr/2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3670

            
3671
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3672
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3673
$dbi->execute($create_table1_type);
3674
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
3675
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3676
$dbi->type_rule(
3677
    into1 => {
3678
        $date_typename => 'ppp'
3679
    }
3680
);
3681
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3682
$result = $dbi->select(table => $table1);
3683
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3684

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3685
eval{$dbi->type_rule(
3686
    into1 => {
3687
        $date_typename => 'pp'
3688
    }
3689
)};
3690
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3691

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3692
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3693
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3694
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3695
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3696
    $dbi->type_rule(
3697
        from1 => {
3698
            Date => sub { $_[0] * 2 },
3699
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3700
    );
3701
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3702
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3703

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3704
eval {
3705
    $dbi->type_rule(
3706
        into1 => {
3707
            Date => sub { $_[0] * 2 },
3708
        }
3709
    );
3710
};
3711
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3712

            
3713
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3714
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3715
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3716
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3717
$dbi->type_rule(
3718
    from1 => {
3719
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3720
    },
3721
    into1 => {
3722
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3723
    }
3724
);
3725
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3726
$result = $dbi->select(table => $table1);
3727
$result->type_rule_off;
3728
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3729

            
3730
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3731
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3732
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3733
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3734
$dbi->type_rule(
3735
    from1 => {
3736
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3737
        $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3738
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3739
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3740
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3741
$result = $dbi->select(table => $table1);
3742
$result->type_rule(
3743
    from1 => {
3744
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3745
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3746
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3747
$row = $result->one;
3748
like($row->{$key1}, qr/^2010-01-05/);
3749
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3750

            
3751
$result = $dbi->select(table => $table1);
3752
$result->type_rule(
3753
    from1 => {
3754
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3755
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3756
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3757
$row = $result->one;
3758
like($row->{$key1}, qr/2010-01-05/);
3759
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3760

            
3761
$result = $dbi->select(table => $table1);
3762
$result->type_rule(
3763
    from1 => {
3764
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3765
    }
3766
);
3767
$row = $result->one;
3768
like($row->{$key1}, qr/2010-01-05/);
3769
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3770

            
3771
$result = $dbi->select(table => $table1);
3772
$result->type_rule(
3773
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
3774
);
3775
$row = $result->one;
3776
like($row->{$key1}, qr/2010-01-05/);
3777
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3778

            
3779
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
3780
$result = $dbi->select(table => $table1);
3781
$result->type_rule(
3782
    from1 => [$date_datatype => 'five']
3783
);
3784
$row = $result->one;
3785
like($row->{$key1}, qr/^2010-01-05/);
3786
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3787

            
3788
$result = $dbi->select(table => $table1);
3789
$result->type_rule(
3790
    from1 => [$date_datatype => undef]
3791
);
3792
$row = $result->one;
3793
like($row->{$key1}, qr/^2010-01-03/);
3794
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3795

            
3796
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3797
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3798
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3799
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3800
$dbi->type_rule(
3801
    from1 => {
3802
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3803
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3804
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3805
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3806
$result = $dbi->select(table => $table1);
3807
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3808
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3809

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3810
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3811
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3812
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3813
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3814
$dbi->type_rule(
3815
    from1 => {
3816
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3817
    },
3818
);
3819
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3820
$result = $dbi->select(table => $table1);
3821
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3822
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3823

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3824
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3825
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3826
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3827
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3828
$dbi->type_rule(
3829
    into1 => {
3830
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3831
    },
3832
    into2 => {
3833
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3834
    },
3835
    from1 => {
3836
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3837
    },
3838
    from2 => {
3839
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
3840
    }
3841
);
3842
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3843
$result = $dbi->select(table => $table1);
3844
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/);
3845
$result = $dbi->select(table => $table1);
3846
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3847

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3848
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3849
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3850
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3851
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3852
$dbi->type_rule(
3853
    into1 => {
3854
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3855
    },
3856
    into2 => {
3857
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3858
    },
3859
    from1 => {
3860
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
3861
    },
3862
    from2 => {
3863
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3864
    }
3865
);
3866
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
3867
$result = $dbi->select(table => $table1);
3868
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/);
3869
$result = $dbi->select(table => $table1);
3870
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3871

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3872
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3873
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3874
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3875
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3876
$dbi->type_rule(
3877
    into1 => {
3878
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3879
    },
3880
    into2 => {
3881
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3882
    },
3883
    from1 => {
3884
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3885
    },
3886
    from2 => {
3887
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
3888
    }
3889
);
3890
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
3891
$result = $dbi->select(table => $table1);
3892
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
3893
$result = $dbi->select(table => $table1);
3894
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3895

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
3896
test 'join';
3897
$dbi = DBIx::Custom->connect;
3898
eval { $dbi->execute("drop table $table1") };
3899
$dbi->execute($create_table1);
3900
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3901
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
3902
eval { $dbi->execute("drop table $table2") };
3903
$dbi->execute($create_table2);
3904
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3905
eval { $dbi->execute("drop table $table3") };
3906
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
3907
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
3908
$rows = $dbi->select(
3909
    table => $table1,
3910
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3911
    where   => {"$table1.$key2" => 2},
3912
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
3913
)->all;
3914
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
3915

            
3916
$rows = $dbi->select(
3917
    table => $table1,
3918
    where   => {$key1 => 1},
3919
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
3920
)->all;
3921
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
3922

            
3923
eval {
3924
    $rows = $dbi->select(
3925
        table => $table1,
3926
        column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3927
        where   => {"$table1.$key2" => 2},
3928
        join  => {"$table1.$key1" => "$table2.$key1"}
3929
    );
3930
};
3931
like ($@, qr/array/);
3932

            
3933
$rows = $dbi->select(
3934
    table => $table1,
3935
    where   => {$key1 => 1},
3936
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3937
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
3938
)->all;
3939
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
3940

            
3941
$rows = $dbi->select(
3942
    column => "$table3.$key4 as ${table3}__$key4",
3943
    table => $table1,
3944
    where   => {"$table1.$key1" => 1},
3945
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3946
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
3947
)->all;
3948
is_deeply($rows, [{"${table3}__$key4" => 4}]);
3949

            
3950
$rows = $dbi->select(
3951
    column => "$table1.$key1 as ${table1}__$key1",
3952
    table => $table1,
3953
    where   => {"$table3.$key4" => 4},
3954
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3955
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
3956
)->all;
3957
is_deeply($rows, [{"${table1}__$key1" => 1}]);
3958

            
3959
$dbi = DBIx::Custom->connect;
3960
eval { $dbi->execute("drop table $table1") };
3961
$dbi->execute($create_table1);
3962
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3963
eval { $dbi->execute("drop table $table2") };
3964
$dbi->execute($create_table2);
3965
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3966
$rows = $dbi->select(
3967
    table => $table1,
3968
    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",
3969
    where   => {"$table1.$key2" => 2},
3970
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
3971
)->all;
3972
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
3973
          'quote');
3974

            
3975

            
3976
$dbi = DBIx::Custom->connect;
3977
eval { $dbi->execute("drop table $table1") };
3978
$dbi->execute($create_table1);
3979
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3980
$sql = <<"EOS";
3981
left outer join (
3982
  select * from $table1 t1
3983
  where t1.$key2 = (
3984
    select max(t2.$key2) from $table1 t2
3985
    where t1.$key1 = t2.$key1
3986
  )
3987
) $table3 on $table1.$key1 = $table3.$key1
3988
EOS
3989
$join = [$sql];
3990
$rows = $dbi->select(
3991
    table => $table1,
3992
    column => "$table3.$key1 as ${table3}__$key1",
3993
    join  => $join
3994
)->all;
3995
is_deeply($rows, [{"${table3}__$key1" => 1}]);
3996

            
3997
$dbi = DBIx::Custom->connect;
3998
eval { $dbi->execute("drop table $table1") };
3999
eval { $dbi->execute("drop table $table2") };
4000
$dbi->execute($create_table1);
4001
$dbi->execute($create_table2);
4002
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4003
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4004
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4005
$result = $dbi->select(
4006
    table => $table1,
4007
    join => [
4008
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4009
    ]
4010
);
4011
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4012
$result = $dbi->select(
4013
    table => $table1,
4014
    column => [{$table2 => [$key3]}],
4015
    join => [
4016
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4017
    ]
4018
);
4019
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4020
$result = $dbi->select(
4021
    table => $table1,
4022
    column => [{$table2 => [$key3]}],
4023
    join => [
4024
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4025
    ]
4026
);
4027
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4028

            
4029
$dbi = DBIx::Custom->connect;
4030
eval { $dbi->execute("drop table $table1") };
4031
eval { $dbi->execute("drop table $table2") };
4032
$dbi->execute($create_table1);
4033
$dbi->execute($create_table2);
4034
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4035
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4036
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4037
$result = $dbi->select(
4038
    table => $table1,
4039
    column => [{$table2 => [$key3]}],
4040
    join => [
4041
        {
4042
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4043
            table => [$table1, $table2]
4044
        }
4045
    ]
4046
);
4047
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4048

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4049
$dbi = DBIx::Custom->connect;
4050
eval { $dbi->execute("drop table $table1") };
4051
eval { $dbi->execute("drop table $table2") };
4052
$dbi->execute($create_table1);
4053
$dbi->execute($create_table2);
4054
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4055
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4056
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4057
$result = $dbi->select(
4058
    table => $table1,
4059
    column => [{$table2 => [$key3]}],
4060
    join => [
4061
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4062
    ]
4063
);
4064
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4065

            
4066
$dbi = DBIx::Custom->connect;
4067
eval { $dbi->execute("drop table $table1") };
4068
eval { $dbi->execute("drop table $table2") };
4069
$dbi->execute($create_table1);
4070
$dbi->execute($create_table2);
4071
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4072
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4073
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4074
$result = $dbi->select(
4075
    table => $table1,
4076
    column => [{$table2 => [$key3]}],
4077
    join => [
4078
        "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4079
    ]
4080
);
4081
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4082

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4083
test 'columns';
4084
$dbi = MyDBI1->connect;
4085
$model = $dbi->model($table1);
4086

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4087
test 'count';
4088
$dbi = DBIx::Custom->connect;
4089
eval { $dbi->execute("drop table $table1") };
4090
$dbi->execute($create_table1);
4091
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4092
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 3});
4093
is($dbi->count(table => $table1), 2);
4094
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4095
$model = $dbi->create_model(table => $table1);
4096
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4097

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