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

            
- added {key => ..., value =...
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
        
cleanup
Yuki Kimoto authored on 2011-10-21
121
        return $self->SUPER::insert($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
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
        
cleanup
Yuki Kimoto authored on 2011-10-21
136
        return $self->SUPER::insert($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
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
        
cleanup
Yuki Kimoto authored on 2011-10-21
151
        return $self->SUPER::insert($param);
test cleanup
Yuki Kimoto authored on 2011-08-15
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
        
cleanup
Yuki Kimoto authored on 2011-10-21
166
        return $self->SUPER::insert($param);
test cleanup
Yuki Kimoto authored on 2011-08-15
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});
cleanup
Yuki Kimoto authored on 2011-10-21
261
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
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

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

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

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

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

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

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
538
test 'update_or_insert';
539
eval { $dbi->execute("drop table $table1") };
540
$dbi->execute($create_table1);
541
$dbi->update_or_insert(
542
    {$key2 => 2},
543
    table => $table1,
544
    primary_key => $key1,
545
    id => 1
546
);
547
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
548
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
549

            
550
$dbi->update_or_insert(
551
    {$key2 => 3},
552
    table => $table1,
553
    primary_key => $key1,
554
    id => 1
555
);
556
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
557
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
558

            
559
eval { $dbi->execute("drop table $table1") };
560
$dbi->execute($create_table1);
561
$dbi->update_or_insert(
562
    {$key1 => 1, $key2 => 2},
563
    table => $table1,
564
    where => {$key1 => 1}
565
);
566
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
567
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
568

            
569

            
570
test 'default_bind_filter';
571
$dbi->execute("delete from $table1");
572
$dbi->register_filter(
573
    twice       => sub { $_[0] * 2 },
574
    three_times => sub { $_[0] * 3 }
575
);
576
$dbi->default_bind_filter('twice');
577
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => 'three_times'});
578
$result = $dbi->execute("select * from $table1");
579
$rows   = $result->all;
580
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
581
$dbi->default_bind_filter(undef);
582

            
test cleanup
Yuki Kimoto authored on 2011-08-10
583
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
584
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
585
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
586
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
587
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
588
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
589
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
590
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
591
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
592
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
593
                  "basic");
594
                  
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
595
$dbi->execute("delete from $table1");
596
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
597
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
598
$dbi->update(table => $table1, param => {$key2 => 12}, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
599
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
600
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
601
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
602
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
603
                  "update key same as search key");
604

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

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
629
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
630
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
631
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
632
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
633
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
634
$where->param({$key1 => 1, $key2 => 2});
635
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
636
$result = $dbi->select(table => $table1);
637
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
638

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
639
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
640
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
641
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
642
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
643
    table => $table1,
644
    param => {$key1 => 3},
test cleanup
Yuki Kimoto authored on 2011-08-10
645
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
646
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
647
        {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
648
    ]
649
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
650
$result = $dbi->select(table => $table1);
651
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
652

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
653
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
654
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
655
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
656
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
657
$where->clause(['and', "$key2 = :$key2"]);
658
$where->param({$key2 => 2});
659
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
660
$result = $dbi->select(table => $table1);
661
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
662

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
669
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
670
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
671
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
672
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
673
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
674
$dbi->insert(table => 'table', param => {select => 1});
675
$dbi->update(table => 'table', where => {select => 1}, param => {update => 2});
676
$result = $dbi->execute("select * from ${q}table$p");
677
$rows   = $result->all;
678
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
679

            
680
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
681
like($@, qr/safety/);
682

            
683
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
684
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
685
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
686
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
687
$dbi->insert(table => 'table', param => {select => 1});
688
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
689
$result = $dbi->execute("select * from ${q}table$p");
690
$rows   = $result->all;
691
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
692

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
693
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
694
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
695
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
696
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
697
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
698
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
699
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
700
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
701
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
702
                  "basic");
703

            
updated pod
Yuki Kimoto authored on 2011-09-02
704
eval { $dbi->execute("drop table $table1") };
705
$dbi->execute($create_table1_2);
706
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
707
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
708
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1},
709
wrap => {$key2 => sub { "$_[0] - 1" }});
710
$result = $dbi->execute("select * from $table1 order by $key1");
711
$rows   = $result->all;
712
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5},
713
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
714
                  "basic");
715

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
716
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
717
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
718
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
719
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
720
$dbi->update(table => $table1, param => {$key2 => \"'11'"}, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
721
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
722
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
723
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
724
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
725
                  "basic");
726

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
727
eval { $dbi->execute("drop table $table1") };
728
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
729
$dbi->update_timestamp(
730
    $key1 => '5'
731
);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
732
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
733
$dbi->update(table => $table1, timestamp => 1, where => {$key2 => 2});
734
$result = $dbi->execute("select * from $table1");
735
$rows   = $result->all;
736
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
737

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
738
eval { $dbi->execute("drop table $table1") };
739
$dbi->execute($create_table1);
740
$dbi->update_timestamp(
741
    [$key1, $key2] => sub { '5' }
742
);
743
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
744
$dbi->update_all(table => $table1, timestamp => 1);
745
$result = $dbi->execute("select * from $table1");
746
$rows   = $result->all;
747
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
748

            
749
eval { $dbi->execute("drop table $table1") };
750
$dbi->execute($create_table1);
751
$dbi->update_timestamp(
752
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
753
);
754
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
755
$dbi->update_all(table => $table1, timestamp => 1);
756
$result = $dbi->execute("select * from $table1");
757
$rows   = $result->all;
758
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
759

            
test cleanup
Yuki Kimoto authored on 2011-08-10
760
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
761
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
762
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
763
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
764
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
765
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
766
$dbi->update_all(table => $table1, param => {$key2 => 10}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
767
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
768
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
769
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
770
                  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
771
                  "filter");
772

            
773

            
774
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
775
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
776
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
777
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
778
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
779
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
780
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
781
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
782
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
783

            
cleanup test
Yuki Kimoto authored on 2011-08-15
784
$dbi->execute("delete from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
785
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
786
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
787
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
788
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
789
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
790
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
791
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
792

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
795
$dbi->delete_all(table => $table1);
796
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
797
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
798
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
799
$rows = $dbi->select(table => $table1)->all;
800
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
801

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
802
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
803
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
804
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
805
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
806
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
807
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
808
$where->param({ke1 => 1, $key2 => 2});
809
$dbi->delete(table => $table1, where => $where);
810
$result = $dbi->select(table => $table1);
811
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
812

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
813
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
814
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
815
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
816
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
817
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
818
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
819
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
820
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
821
        {ke1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
822
    ]
823
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
824
$result = $dbi->select(table => $table1);
825
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
826

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
827
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
828
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
829
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
830
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
831
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
832
$rows   = $result->all;
833
is_deeply($rows, [], "basic");
834

            
835
test 'delete error';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
836
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
837
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
838
eval{$dbi->delete(table => $table1)};
cleanup
Yuki Kimoto authored on 2011-10-21
839
like($@, qr/where/, "where key-value pairs not specified");
test cleanup
Yuki Kimoto authored on 2011-08-10
840

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
844
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
845
$dbi = DBIx::Custom->connect;
846
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
847
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
848
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
849
$dbi->insert(table => 'table', param => {select => 1});
850
$dbi->delete(table => 'table', where => {select => 1});
851
$result = $dbi->execute("select * from ${q}table$p");
852
$rows   = $result->all;
853
is_deeply($rows, [], "reserved word");
854

            
855
test 'delete_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
856
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
857
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
858
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
859
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
860
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
861
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
862
$rows   = $result->all;
863
is_deeply($rows, [], "basic");
864

            
865

            
866
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
867
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
868
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
869
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
870
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
871
$rows = $dbi->select(table => $table1)->all;
872
is_deeply($rows, [{$key1 => 1, $key2 => 2},
873
                  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
874

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
889
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
890
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
891
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
test cleanup
Yuki Kimoto authored on 2011-08-10
892
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
893
    table => [$table1, $table2],
894
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
895
    where   => {"$table1.$key2" => 2},
896
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
897
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
898
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
899

            
900
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
901
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
902
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
903
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
904
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
905
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
906

            
907
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
908
eval { $dbi->execute("drop table ${q}table$p") };
909
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
910
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
911
$dbi->insert(table => 'table', param => {select => 1, update => 2});
912
$result = $dbi->select(table => 'table', where => {select => 1});
913
$rows   = $result->all;
914
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
915

            
916
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
917
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
918
$dbi->register_filter(
919
    twice       => sub { $_[0] * 2 },
920
    three_times => sub { $_[0] * 3 }
921
);
922
$dbi->default_fetch_filter('twice');
923
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
924
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
925
$result = $dbi->select(table => $table1);
926
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
927
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
928
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
929

            
930
test 'filters';
931
$dbi = DBIx::Custom->new;
932

            
933
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
934
   'あ', "decode_utf8");
935

            
936
is($dbi->filters->{encode_utf8}->('あ'),
937
   encode_utf8('あ'), "encode_utf8");
938

            
cleanup test
Yuki Kimoto authored on 2011-08-10
939
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
940
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
941
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
942
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
943
$dbi->begin_work;
944
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
945
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
946
$dbi->rollback;
947
$dbi->dbh->{AutoCommit} = 1;
948

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

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

            
953
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
954
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
955
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
956
$dbi->begin_work;
957
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
958
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
959
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
960
$dbi->commit;
961
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
962
$result = $dbi->select(table => $table1);
963
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
964
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
965

            
966
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
967
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
968
$dbi->execute($create_table1);
969
{
970
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
971
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
972
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
973
    like($@, qr/\.t /, "fail : not verbose");
974
}
975
{
976
    local $Carp::Verbose = 1;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
977
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
978
    like($@, qr/Custom.*\.t /s, "fail : verbose");
979
}
980

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

            
986
{
987
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
988
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
989
    like($@, qr/\Q.t /, "caller spec : not vebose");
990
}
991
{
992
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
993
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
994
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
995
}
996

            
997

            
cleanup test
Yuki Kimoto authored on 2011-08-10
998
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
999
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1000
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1001
$dbi->execute($create_table1);
1002

            
1003
$dbi->begin_work;
1004

            
1005
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1006
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1007
    die "Error";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1008
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1009
};
1010

            
1011
$dbi->rollback if $@;
1012

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

            
1017
$dbi->begin_work;
1018

            
1019
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1020
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1021
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1022
};
1023

            
1024
$dbi->commit unless $@;
1025

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

            
1030
$dbi->dbh->{AutoCommit} = 0;
1031
eval{ $dbi->begin_work };
1032
ok($@, "exception");
1033
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1034

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1035
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1036
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1037
$dbi->cache(1);
1038
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1039
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1040
$dbi->execute($source, {}, query => 1);
1041
is_deeply($dbi->{_cached}->{$source}, 
cleanup test
Yuki Kimoto authored on 2011-08-15
1042
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1043

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1044
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1045
$dbi->execute($create_table1);
1046
$dbi->{_cached} = {};
1047
$dbi->cache(0);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1048
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1049
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1050

            
1051
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1052
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1053
$dbi->execute($create_table1);
1054
{
1055
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1056
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1057
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1058
    like($@, qr/\.t /, "fail : not verbose");
1059
}
1060
{
1061
    local $Carp::Verbose = 1;
- removed argument checking ...
Yuki Kimoto authored on 2011-10-21
1062
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1063
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1064
}
1065

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

            
1071
{
1072
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1073
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1074
    like($@, qr/\Q.t /, "caller spec : not vebose");
1075
}
1076
{
1077
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1078
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1079
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1080
}
1081

            
1082
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1083
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1084
    one => sub { 1 }
1085
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1086
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1087
    two => sub { 2 }
1088
);
1089
$dbi->method({
1090
    twice => sub {
1091
        my $self = shift;
1092
        return $_[0] * 2;
1093
    }
1094
});
1095

            
1096
is($dbi->one, 1, "first");
1097
is($dbi->two, 2, "second");
1098
is($dbi->twice(5), 10 , "second");
1099

            
1100
eval {$dbi->XXXXXX};
1101
ok($@, "not exists");
1102

            
1103
test 'out filter';
1104
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1105
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1106
$dbi->execute($create_table1);
1107
$dbi->register_filter(twice => sub { $_[0] * 2 });
1108
$dbi->register_filter(three_times => sub { $_[0] * 3});
1109
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1110
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1111
              $key2 => {out => 'three_times', in => 'twice'});
1112
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1113
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1114
$row   = $result->fetch_hash_first;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1115
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1116
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1117
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1118
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1119

            
1120
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1121
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1122
$dbi->execute($create_table1);
1123
$dbi->register_filter(twice => sub { $_[0] * 2 });
1124
$dbi->register_filter(three_times => sub { $_[0] * 3});
1125
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1126
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1127
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1128
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1129
    $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1130
); 
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1131
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
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
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1134
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
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 => 1, $key2 => 2}, filter => {$key1 => undef});
1144
$dbi->update(table => $table1, param => {$key1 => 2}, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1145
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1146
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1147
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
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});
1157
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1158
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1159
$rows   = $result->all;
1160
is_deeply($rows, [], "delete");
1161

            
1162
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1163
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1164
$dbi->execute($create_table1);
1165
$dbi->register_filter(twice => sub { $_[0] * 2 });
1166
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1167
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1168
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1169
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
1170
$result = $dbi->select(table => $table1, where => {$key1 => 1});
1171
$result->filter({$key2 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1172
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1173
is_deeply($rows, [{$key1 => 4, $key2 => 4}], "select");
test cleanup
Yuki Kimoto authored on 2011-08-10
1174

            
1175
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1176
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1177
$dbi->execute($create_table1);
1178
$dbi->register_filter(twice => sub { $_[0] * 2 });
1179
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1180
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1181
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1182
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1183
$result = $dbi->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1184
                        param => {$key1 => 1, $key2 => 2},
1185
                        table => [$table1]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1186
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1187
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute");
test cleanup
Yuki Kimoto authored on 2011-08-10
1188

            
1189
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1190
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1191
$dbi->execute($create_table1);
1192
$dbi->register_filter(twice => sub { $_[0] * 2 });
1193
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1194
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1195
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1196
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1197
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1198
                        param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1199
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1200
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1201

            
1202
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1203
eval { $dbi->execute("drop table $table1") };
1204
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1205
$dbi->execute($create_table1);
1206
$dbi->execute($create_table2);
1207
$dbi->register_filter(twice => sub { $_[0] * 2 });
1208
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1209
$dbi->apply_filter(
cleanup test
Yuki Kimoto authored on 2011-08-15
1210
    $table1, $key2 => {out => 'twice', in => 'twice'}
1211
);
1212
$dbi->apply_filter(
1213
    $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1214
);
cleanup test
Yuki Kimoto authored on 2011-08-15
1215
$dbi->insert(table => $table1, param => {$key1 => 5, $key2 => 2}, filter => {$key2 => undef});
1216
$dbi->insert(table => $table2, param => {$key1 => 5, $key3 => 6}, filter => {$key3 => undef});
1217
$result = $dbi->select(
1218
     table => [$table1, $table2],
1219
     column => [$key2, $key3],
1220
     where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1221

            
1222
$result->filter({$key2 => 'twice'});
1223
$rows   = $result->all;
1224
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1225

            
1226
$result = $dbi->select(
1227
     table => [$table1, $table2],
1228
     column => [$key2, $key3],
1229
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1230

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

            
1235
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1236
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1237
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1238
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1239
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1240
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1241

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1242
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1243
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1244
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1245
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1246
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1247
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1248

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1249
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1250
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1251
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1252
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1253
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1254

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

            
1266
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1267
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1268
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1269
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1270
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1271
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1272
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1273
$row = $result->fetch_first;
1274
is_deeply($row, [6, 12]);
1275

            
1276
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1277
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1278
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1279
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1280
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1281
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1282
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1283
$row = $result->fetch_first;
1284
is_deeply($row, [6, 12]);
1285

            
1286
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1287
$result = $dbi->select(table => $table1);
1288
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1289
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1290
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1291
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1292

            
1293
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1294
$dbi->apply_filter($table1,
1295
    $key1 => {end => sub { $_[0] * 3 } },
1296
    $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1297
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1298
$result = $dbi->select(table => $table1);
1299
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1300
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1301
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1302

            
1303
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1304
$dbi->apply_filter($table1,
1305
    $key1 => {end => sub { $_[0] * 3 } },
1306
    $key2 => {end => 'five_times'}
1307
);
1308
$result = $dbi->select(table => $table1);
1309
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1310
$result->filter($key1 => undef);
1311
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1312
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1313
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1314

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1315
test 'remove_end_filter and remove_filter';
1316
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1317
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1318
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1319
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1320
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1321
$row = $result
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1322
       ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1323
       ->remove_filter
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1324
       ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1325
       ->remove_end_filter
1326
       ->fetch_first;
1327
is_deeply($row, [1, 2]);
1328

            
1329
test 'empty where select';
1330
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1331
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1332
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1333
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1334
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1335
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1336
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1337

            
1338
test 'select query option';
1339
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1340
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1341
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1342
$query = $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1343
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1344
$query = $dbi->update(table => $table1, where => {$key1 => 1}, param => {$key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1345
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1346
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1347
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1348
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1349
is(ref $query, 'DBIx::Custom::Query');
1350

            
1351
test 'where';
1352
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1353
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1354
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1355
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1356
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1357
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1358
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1359

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

            
1364
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1365
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1366
    where => $where
1367
);
1368
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1369
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1370

            
1371
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1372
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1373
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1374
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
1375
        {$key1 => 1}
test cleanup
Yuki Kimoto authored on 2011-08-10
1376
    ]
1377
);
1378
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1379
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1380

            
1381
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1382
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1383
             ->param({$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1384
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1385
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1386
    where => $where
1387
);
1388
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1389
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1390

            
1391
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1392
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
test cleanup
Yuki Kimoto authored on 2011-08-10
1393
             ->param({});
1394
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1395
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1396
    where => $where,
1397
);
1398
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1399
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1400

            
1401
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1402
             ->clause(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"])
1403
             ->param({$key1 => [0, 3], $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1404
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1405
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1406
    where => $where,
1407
); 
1408
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1409
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1410

            
1411
$where = $dbi->where;
1412
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1413
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1414
    where => $where
1415
);
1416
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1417
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1418

            
1419
eval {
1420
$where = $dbi->where
1421
             ->clause(['uuu']);
1422
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1423
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1424
    where => $where
1425
);
1426
};
1427
ok($@);
1428

            
1429
$where = $dbi->where;
1430
is("$where", '');
1431

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

            
1442
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1443
             ->clause(['or', ("$key1 = :$key1") x 2])
1444
             ->param({$key1 => [1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1445
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1446
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1447
    where => $where,
1448
);
1449
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1450
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1451

            
1452
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1453
             ->clause(['or', ("$key1 = :$key1") x 2])
1454
             ->param({$key1 => 1});
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}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1461

            
1462
$where = $dbi->where
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1463
             ->clause("$key1 = :$key1")
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1464
             ->param({$key1 => 1});
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}]);
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("$key1 = :$key1 $key2 = :$key2")
1474
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1475
eval{$where->to_string};
1476
like($@, qr/one column/);
1477

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

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

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

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

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

            
1528
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1529
             ->clause(['or', ("$key1 = :$key1") x 3])
1530
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1531
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1532
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1533
    where => $where,
1534
);
1535
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1536
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1537

            
1538
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1539
             ->clause(['or', ("$key1 = :$key1") x 3])
1540
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1541
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1542
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1543
    where => $where,
1544
);
1545
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1546
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1547

            
1548
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1549
             ->clause(['or', ("$key1 = :$key1") x 3])
1550
             ->param({$key1 => []});
test cleanup
Yuki Kimoto authored on 2011-08-10
1551
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1552
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1553
    where => $where,
1554
);
1555
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1556
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1557

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

            
1568
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1569
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1570
             ->param({$key1 => [$dbi->not_exists, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1571
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1572
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1573
    where => $where,
1574
);
1575
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1576
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1577

            
1578
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1579
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1580
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1581
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1582
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1583
    where => $where,
1584
);
1585
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1586
is_deeply($row, [{$key1 => 1, $key2 => 2},{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1587

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

            
1598
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1599
             ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
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}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1606

            
1607
eval {$dbi->where(ppp => 1) };
1608
like($@, qr/invalid/);
1609

            
1610
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1611
    clause => ['and', ['or'], ['and', "$key1 = :$key1", "$key2 = :$key2"]],
1612
    param => {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
1613
);
1614
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1615
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1616
    where => $where,
1617
);
1618
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1619
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1620

            
1621

            
1622
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1623
    clause => ['and', ['or'], ['or', ":$key1", ":$key2"]],
test cleanup
Yuki Kimoto authored on 2011-08-10
1624
    param => {}
1625
);
1626
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1627
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1628
    where => $where,
1629
);
1630
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1631
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1632

            
1633
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1634
$where->clause(['and', ":${key1}{=}"]);
1635
$where->param({$key1 => undef});
1636
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1637
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1638
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1639

            
1640
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1641
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1642
$where->param({$key1 => [undef, undef]});
1643
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1644
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1645
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1646
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1647
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1648
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1649

            
1650
test 'register_tag_processor';
1651
$dbi = DBIx::Custom->connect;
1652
$dbi->register_tag_processor(
1653
    a => sub { 1 }
1654
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1655
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1656

            
1657
test 'register_tag';
1658
$dbi = DBIx::Custom->connect;
1659
$dbi->register_tag(
1660
    b => sub { 2 }
1661
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1662
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1663

            
1664
test 'table not specify exception';
1665
$dbi = DBIx::Custom->connect;
1666
eval {$dbi->select};
1667
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1668

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1669
test 'more tests';
1670
$dbi = DBIx::Custom->connect;
1671
eval{$dbi->apply_filter('table', 'column', [])};
1672
like($@, qr/apply_filter/);
1673

            
1674
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1675
like($@, qr/apply_filter/);
1676

            
1677
$dbi->apply_filter(
1678

            
1679
);
1680
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1681
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1682
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1683
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1684
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1685
$dbi->apply_filter($table1, $key2, 
test cleanup
Yuki Kimoto authored on 2011-08-10
1686
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1687
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
1688
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
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);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1693
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1694
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1695
$dbi->apply_filter($table1, $key2, {});
1696
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1697
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1698

            
1699
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1700
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1701
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1702
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1703
like($@, qr/not registered/);
1704
$dbi->method({one => sub { 1 }});
1705
is($dbi->one, 1);
1706

            
1707
eval{DBIx::Custom->connect(dsn => undef)};
1708
like($@, qr/_connect/);
1709

            
1710
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1711
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1712
$dbi->execute($create_table1);
1713
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1714
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1715
             filter => {$key1 => 'twice'});
1716
$row = $dbi->select(table => $table1)->one;
1717
is_deeply($row, {$key1 => 2, $key2 => 2});
1718
eval {$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1719
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
1720
like($@, qr//);
1721

            
1722
$dbi->register_filter(one => sub { });
1723
$dbi->default_fetch_filter('one');
1724
ok($dbi->default_fetch_filter);
1725
$dbi->default_bind_filter('one');
1726
ok($dbi->default_bind_filter);
1727
eval{$dbi->default_fetch_filter('no')};
1728
like($@, qr/not registered/);
1729
eval{$dbi->default_bind_filter('no')};
1730
like($@, qr/not registered/);
1731
$dbi->default_bind_filter(undef);
1732
ok(!defined $dbi->default_bind_filter);
1733
$dbi->default_fetch_filter(undef);
1734
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1735
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1736
like($@, qr/Tag not finished/);
1737

            
1738
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1739
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1740
$dbi->execute($create_table1);
1741
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1742
$result = $dbi->select(table => $table1);
1743
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1744
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1745
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1746
like($@, qr/not registered/);
1747
$result->default_filter(undef);
1748
ok(!defined $result->default_filter);
1749
$result->default_filter('one');
1750
is($result->default_filter->(), 1);
1751

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1752
test 'option';
1753
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
1754
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
1755
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
1756
ok($dbi->dbh->{PrintError});
1757
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
1758
ok($dbi->dbh->{PrintError});
1759

            
1760
test 'DBIx::Custom::Result stash()';
1761
$result = DBIx::Custom::Result->new;
1762
is_deeply($result->stash, {}, 'default');
1763
$result->stash->{foo} = 1;
1764
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
1765

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

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

            
1786
test 'insert_at';
1787
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1788
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1789
$dbi->execute($create_table1_2);
1790
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1791
    primary_key => [$key1, $key2], 
1792
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1793
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1794
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1795
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1796
is($dbi->select(table => $table1)->one->{$key1}, 1);
1797
is($dbi->select(table => $table1)->one->{$key2}, 2);
1798
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1799

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1800
$dbi->delete_all(table => $table1);
1801
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1802
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1803
    primary_key => $key1, 
1804
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1805
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1806
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1807
);
1808

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

            
1813
eval {
1814
    $dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1815
        table => $table1,
1816
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1817
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1818
        param => {$key1 => 1, $key2 => 2, $key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
1819
    );
1820
};
1821
like($@, qr/must be/);
1822

            
1823
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1824
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1825
$dbi->execute($create_table1_2);
1826
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1827
    {$key3 => 3},
1828
    primary_key => [$key1, $key2], 
1829
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1830
    where => [1, 2],
1831
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1832
is($dbi->select(table => $table1)->one->{$key1}, 1);
1833
is($dbi->select(table => $table1)->one->{$key2}, 2);
1834
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1835

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1851
$dbi->delete_all(table => $table1);
1852
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1853
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1854
    table => $table1,
1855
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1856
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1857
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
1858
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1859
is($dbi->select(table => $table1)->one->{$key1}, 1);
1860
is($dbi->select(table => $table1)->one->{$key2}, 2);
1861
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1862

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

            
1877
test 'select_at';
1878
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1879
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1880
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1881
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1882
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1883
    table => $table1,
1884
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1885
    where => [1, 2]
1886
);
1887
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1888
is($row->{$key1}, 1);
1889
is($row->{$key2}, 2);
1890
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1891

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1892
$dbi->delete_all(table => $table1);
1893
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1894
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1895
    table => $table1,
1896
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1897
    where => 1,
1898
);
1899
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1900
is($row->{$key1}, 1);
1901
is($row->{$key2}, 2);
1902
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1903

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1904
$dbi->delete_all(table => $table1);
1905
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1906
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1907
    table => $table1,
1908
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1909
    where => [1, 2]
1910
);
1911
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1912
is($row->{$key1}, 1);
1913
is($row->{$key2}, 2);
1914
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1915

            
1916
eval {
1917
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1918
        table => $table1,
1919
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1920
        where => {},
1921
    );
1922
};
1923
like($@, qr/must be/);
1924

            
1925
eval {
1926
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1927
        table => $table1,
1928
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1929
        where => [1],
1930
    );
1931
};
1932
like($@, qr/same/);
1933

            
1934
eval {
1935
    $result = $dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1936
        table => $table1,
1937
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1938
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1939
        param => {$key1 => 1, $key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-10
1940
    );
1941
};
1942
like($@, qr/must be/);
1943

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

            
1953
test 'model delete_at';
1954
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1955
eval { $dbi->execute("drop table $table1") };
1956
eval { $dbi->execute("drop table $table2") };
1957
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1958
$dbi->execute($create_table1_2);
1959
$dbi->execute($create_table2_2);
1960
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1961
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1962
$dbi->model($table1)->delete_at(where => [1, 2]);
1963
is_deeply($dbi->select(table => $table1)->all, []);
1964
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1965
$dbi->model($table1)->delete_at(where => [1, 2]);
1966
is_deeply($dbi->select(table => $table1)->all, []);
1967
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1968
$dbi->model($table3)->delete_at(where => [1, 2]);
1969
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1970

            
1971
test 'model insert_at';
1972
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1973
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1974
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1975
$dbi->model($table1)->insert_at(
cleanup test
Yuki Kimoto authored on 2011-08-10
1976
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1977
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1978
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1979
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
1980
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1981
is($row->{$key1}, 1);
1982
is($row->{$key2}, 2);
1983
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1984

            
1985
test 'model update_at';
1986
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1987
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1988
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1989
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1990
$dbi->model($table1)->update_at(
cleanup test
Yuki Kimoto authored on 2011-08-10
1991
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1992
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
1993
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1994
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
1995
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1996
is($row->{$key1}, 1);
1997
is($row->{$key2}, 2);
1998
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1999

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

            
2011

            
2012
test 'mycolumn and column';
2013
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2014
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2015
eval { $dbi->execute("drop table $table1") };
2016
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2017
$dbi->execute($create_table1);
2018
$dbi->execute($create_table2);
2019
$dbi->separator('__');
2020
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2021
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2022
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2023
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2024
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2025
    column => [$model->mycolumn, $model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2026
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2027
);
2028
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2029
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2030

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2031
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2032
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2033
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2034
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2035
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2036
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2037
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2038
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2039
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2040
$dbi->execute($sql, param => $param, table => $table1);
2041
is($dbi->select(table => $table1)->one->{$key1}, 1);
2042
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2043

            
2044
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2045
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2046
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2047
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2048
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2049
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2050
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2051
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2052
$dbi->execute($sql, param => $param, table => $table1);
2053
is($dbi->select(table => $table1)->one->{$key1}, 1);
2054
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2055

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2059
test 'mycolumn';
2060
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2061
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2062
eval { $dbi->execute("drop table $table1") };
2063
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2064
$dbi->execute($create_table1);
2065
$dbi->execute($create_table2);
2066
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2067
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2068
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2069
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2070
$result = $model->select_at(
2071
    column => [
2072
        $model->mycolumn,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2073
        $model->column($table2)
cleanup test
Yuki Kimoto authored on 2011-08-10
2074
    ]
2075
);
2076
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2077
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2078

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

            
2096
$result = $model->select_at(
2097
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2098
        $model->mycolumn([$key1]),
2099
        ["$table2.$key1", as => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2100
    ]
2101
);
2102
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2103
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2104

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2114
test 'merge_param';
2115
$dbi = DBIx::Custom->new;
2116
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2117
    {$key1 => 1, $key2 => 2, $key3 => 3},
2118
    {$key1 => 1, $key2 => 2},
2119
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2120
];
2121
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2122
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2123

            
2124
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2125
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2126
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2127
];
2128
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2129
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
2130

            
2131
test 'select() param option';
2132
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2133
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2134
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2135
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2136
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2137
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2138
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2139
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
2140
$dbi->insert(table => $table2, param => {$key1 => 2, $key3 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-10
2141
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2142
    table => $table1,
2143
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2144
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2145
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
test cleanup
Yuki Kimoto authored on 2011-08-15
2146
              " $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2147
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2148
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2149
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2150

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

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

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

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

            
2207

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2251
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2252
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2253
    primary_key => $key1, 
2254
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2255
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2256
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2257
);
2258

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2276
test 'model insert id and primary_key option';
2277
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2278
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2279
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2280
$dbi->model($table1)->insert(
cleanup test
Yuki Kimoto authored on 2011-08-10
2281
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2282
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2283
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2284
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2285
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2286
is($row->{$key1}, 1);
2287
is($row->{$key2}, 2);
2288
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2289

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2318
$dbi->delete_all(table => $table1);
2319
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2320
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2321
    table => $table1,
2322
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2323
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2324
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2325
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2326
is($dbi->select(table => $table1)->one->{$key1}, 0);
2327
is($dbi->select(table => $table1)->one->{$key2}, 2);
2328
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2329

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

            
2344

            
2345
test 'model update and id option';
2346
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2347
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2348
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2349
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2350
$dbi->model($table1)->update(
cleanup test
Yuki Kimoto authored on 2011-08-10
2351
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2352
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2353
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2354
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2355
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2356
is($row->{$key1}, 1);
2357
is($row->{$key2}, 2);
2358
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2359

            
2360

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2373
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2374
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2375
    table => $table1,
2376
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2377
    id => 0,
2378
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2379
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2380

            
2381

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

            
2400

            
2401
test 'select and id option';
2402
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2403
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2404
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2405
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2406
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2407
    table => $table1,
2408
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2409
    id => [1, 2]
2410
);
2411
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2412
is($row->{$key1}, 1);
2413
is($row->{$key2}, 2);
2414
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2415

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2416
$dbi->delete_all(table => $table1);
2417
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2418
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2419
    table => $table1,
2420
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2421
    id => 0,
2422
);
2423
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2424
is($row->{$key1}, 0);
2425
is($row->{$key2}, 2);
2426
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2427

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2428
$dbi->delete_all(table => $table1);
2429
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2430
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2431
    table => $table1,
2432
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2433
    id => [1, 2]
2434
);
2435
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2436
is($row->{$key1}, 1);
2437
is($row->{$key2}, 2);
2438
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2439

            
2440

            
2441
test 'model select_at';
2442
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2443
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2444
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2445
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2446
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2447
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2448
is($row->{$key1}, 1);
2449
is($row->{$key2}, 2);
2450
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2451

            
2452
test 'column separator is default .';
2453
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2454
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2455
eval { $dbi->execute("drop table $table1") };
2456
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2457
$dbi->execute($create_table1);
2458
$dbi->execute($create_table2);
2459
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2460
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2461
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2462
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2463
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2464
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2465
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2466
);
2467
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2468
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2469

            
2470
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2471
    column => [$model->column($table2 => [$key1, $key3])],
2472
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2473
);
2474
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2475
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2476

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2477
test 'separator';
2478
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2479
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2480
eval { $dbi->execute("drop table $table1") };
2481
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2482
$dbi->execute($create_table1);
2483
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2484

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2485
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2486
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2487
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2488
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2489
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2490
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2491
);
2492
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2493
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2494
);
2495
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2496
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2497
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2498
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2499
$result = $model->select(
2500
    column => [
2501
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2502
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2503
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2504
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2505
);
2506
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2507
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2508
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2509

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2510
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2511
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2512
$result = $model->select(
2513
    column => [
2514
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2515
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2516
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2517
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2518
);
2519
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2520
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
2521
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2522

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2523
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2524
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2525
$result = $model->select(
2526
    column => [
2527
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2528
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2529
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2530
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2531
);
2532
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2533
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2534
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2535

            
2536

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2537
test 'filter_off';
2538
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2539
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2540
eval { $dbi->execute("drop table $table1") };
2541
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2542
$dbi->execute($create_table1);
2543
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2544

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2545
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2546
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2547
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2548
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2549
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2550
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2551
);
2552
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2553
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2554
$model = $dbi->model($table1);
2555
$result = $model->select(column => $key1);
2556
$result->filter($key1 => sub { $_[0] * 2 });
2557
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2558

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2559
test 'available_datetype';
2560
$dbi = DBIx::Custom->connect;
2561
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2562

            
2563

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2564
test 'select prefix option';
2565
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2566
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2567
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2568
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2569
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2570
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2571

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

            
added tests
Yuki Kimoto authored on 2011-08-26
2573
test 'mapper';
2574
$dbi = DBIx::Custom->connect;
2575
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2576
    id => {key => "$table1.id"},
2577
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2578
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
2579
);
2580
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2581
  "$table1.price" => 1900});
2582

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2583
$dbi = DBIx::Custom->connect;
2584
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2585
    id => {key => "$table1.id"},
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2586
    author => ["$table1.author" => $dbi->like_value],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2587
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2588
);
2589
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2590
  "$table1.price" => 1900});
2591

            
added tests
Yuki Kimoto authored on 2011-08-26
2592
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2593
    id => {key => "$table1.id"},
2594
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2595
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
2596
);
2597
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2598

            
2599
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2600
    id => {key => "$table1.id"},
2601
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2602
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
added tests
Yuki Kimoto authored on 2011-08-26
2603
);
2604
is_deeply($param, {});
2605

            
2606
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2607
    id => {key => "$table1.id"},
2608
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2609
);
2610
is_deeply($param, {"$table1.price" => undef});
2611

            
2612
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2613
    id => {key => "$table1.id", condition => 'exists'},
2614
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
2615
);
2616
is_deeply($param, {"$table1.price" => '%a'});
2617

            
2618
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2619
    id => {key => "$table1.id"},
added tests
Yuki Kimoto authored on 2011-08-26
2620
    price => ["$table1.price", sub { '%' . $_[0] }]
2621
);
2622
is_deeply($param, {"$table1.price" => '%a'});
2623

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2624
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2625
    price => sub { '%' . $_[0] },
2626
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2627
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2628
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2629

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2630
eval { $dbi->execute("drop table $table1") };
2631
$dbi->execute($create_table1);
2632
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2633
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
2634

            
2635
$where = $dbi->where;
2636
$where->clause(['and', ":${key1}{=}"]);
2637
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
2638
$where->param($param);
2639
$result = $dbi->execute("select * from $table1 $where", {$key1 => 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(['or', ":${key1}{=}", ":${key1}{=}"]);
2645
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
2646
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2647
$row = $result->all;
2648
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2649
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2650
$row = $result->all;
2651
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2652

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

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2664

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2665
$where = $dbi->where;
2666
$where->clause(['and', ":${key1}{=}"]);
2667
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
2668
  ->pass([$key1, $key2])->map;
2669
$where->param($param);
2670
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2671
$row = $result->all;
2672
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2673

            
2674
$where = $dbi->where;
2675
$where->clause(['and', ":${key1}{=}"]);
2676
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
2677
$where->param($param);
2678
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2679
$row = $result->all;
2680
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2681

            
2682
$where = $dbi->where;
2683
$where->clause(['and', ":${key1}{=}"]);
2684
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
2685
  ->pass([$key1, $key2])->map;
2686
$where->param($param);
2687
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2688
$row = $result->all;
2689
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2690

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2691

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2692
$where = $dbi->where;
2693
$where->clause(['and', ":${key1}{=}"]);
2694
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
2695
$where->param($param);
2696
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2697
$row = $result->all;
2698
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2699

            
2700
$where = $dbi->where;
2701
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2702
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2703
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2704
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2705
);
2706
$where->param($param);
2707
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2708
  "$table1.price" => 1900});
2709

            
2710
$where = $dbi->where;
2711
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2712
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2713
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2714
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2715
);
2716
$where->param($param);
2717
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2718

            
2719
$where = $dbi->where;
2720
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2721
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2722
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2723
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2724
);
2725
$where->param($param);
2726
is_deeply($where->param, {});
2727

            
2728
$where = $dbi->where;
2729
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2730
    id => {key => "$table1.id"},
2731
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2732
);
2733
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
2734

            
2735
$where = $dbi->where;
2736
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2737
    id => {key => "$table1.id", condition => 'exists'},
2738
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2739
);
2740
is_deeply($param, {"$table1.price" => '%a'});
2741

            
2742
$where = $dbi->where;
2743
$param = $dbi->mapper(param => {id => [1, 2], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2744
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2745
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2746
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2747
);
2748
is_deeply($param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
2749
  "$table1.price" => 1900});
2750

            
2751
$where = $dbi->where;
2752
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900}, condition => 'length')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2753
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2754
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2755
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2756
);
2757
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2758
  "$table1.price" => 1900});
2759

            
2760
$where = $dbi->where;
2761
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2762
    id => {key => "$table1.id", condition => 'length'},
2763
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
2764
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2765
);
2766
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2767
  "$table1.price" => 1900});
2768

            
2769
$where = $dbi->where;
2770
$param = $dbi->mapper(param => {id => 'a', author => 'b', price => 'c'}, pass => [qw/id author/])
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2771
  ->map(price => {key => 'book.price'});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2772
is_deeply($param, {id => 'a', author => 'b', 'book.price' => 'c'});
2773

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2774
test 'order';
2775
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2776
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2777
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2778
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2779
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
2780
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
2781
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2782
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2783
$order->prepend($key1, "$key2 desc");
2784
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2785
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
2786
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2787
$order->prepend("$key1 desc");
2788
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2789
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
2790
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2791

            
2792
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2793
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2794
$result = $dbi->select(table => $table1,
2795
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2796
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2797
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
2798
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
2799
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
2800
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2801

            
2802
test 'tag_parse';
2803
$dbi = DBIx::Custom->connect;
2804
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2805
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2806
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2807
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2808
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2809
ok($@);
2810

            
2811
test 'last_sql';
2812
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2813
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2814
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2815
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
2816
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2817

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

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

            
2828
test 'Named placeholder :name(operater) syntax';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2829
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2830
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2831
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
2832
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
2833

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2849
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
2850
$result = $dbi->execute(
2851
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2852
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2853
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
2854
);
2855
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2856
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2857

            
2858
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2859
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2860
$dbi->execute($create_table1_highperformance);
2861
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2862
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2863
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2864
];
2865
{
2866
    my $query;
2867
    foreach my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2868
      $query ||= $dbi->insert($row, table => $table1, query => 1);
2869
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
2870
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2871
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2872
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2873
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2874
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2875
      ]
2876
    );
2877
}
2878

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2879
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2880
$dbi->execute($create_table1_highperformance);
2881
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2882
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2883
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2884
];
2885
{
2886
    my $query;
2887
    my $sth;
2888
    foreach my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2889
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2890
      $sth ||= $query->sth;
2891
      $sth->execute(map { $row->{$_} } sort keys %$row);
2892
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2893
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2894
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2895
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2896
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2897
      ]
2898
    );
2899
}
2900

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2901
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2902
$dbi->execute($create_table1_highperformance);
2903
$rows = [
2904
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
2905
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
2906
];
2907
{
2908
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
2909
    my $query;
2910
    foreach my $row (@$rows) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2911
      $query ||= $model->insert($row, query => 1);
2912
      $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2913
    }
2914
    is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
2915
      [
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2916
          {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
2917
          {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2918
      ]
2919
    );
2920
}
2921

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2922
test 'id option more';
2923
eval { $dbi->execute("drop table $table1") };
2924
$dbi->execute($create_table1_highperformance);
2925
$row = {
2926
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
2927
};
2928
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2929
$model->insert($row);
2930
$query = $model->update({$key7 => 11}, id => 1, query => 1);
2931
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
2932
is_deeply($dbi->select(table => $table1)->one,
2933
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
2934
);
2935

            
2936
eval { $dbi->execute("drop table $table1") };
2937
eval { $dbi->execute("drop table $table2") };
2938
$dbi->execute($create_table1);
2939
$dbi->execute($create_table2);
2940
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2941
$model->insert({$key1 => 1, $key2 => 2});
2942
$model = $dbi->create_model(table => $table2, primary_key => $key1,
2943
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
2944
$model->insert({$key1 => 1, $key3 => 3});
2945
$result = $model->select(
2946
    column => {$table1 => ["$key2"]},
2947
    id => 1
2948
);
2949
is_deeply($result->all, [{"$table1.$key2" => 2}]);
2950

            
2951
eval { $dbi->execute("drop table $table1") };
2952
$dbi->execute($create_table1_highperformance);
2953
$row = {
2954
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
2955
};
2956
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2957
$model->insert($row);
2958
$query = $model->delete(id => 1, query => 1);
2959
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
2960
is_deeply($dbi->select(table => $table1)->all, []);
2961

            
2962
eval { $dbi->execute("drop table $table1") };
2963
eval { $dbi->execute($create_table1_highperformance) };
2964
$row = {
2965
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
2966
};
2967
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2968
$model->insert($row);
2969
$query = $model->select(id => 1, query => 1);
2970
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
2971
is_deeply($dbi->select(table => $table1)->one,
2972
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
2973
);
2974

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2975
test 'result';
2976
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2977
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2978
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2979
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2980
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2981

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2982
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2983
@rows = ();
2984
while (my $row = $result->fetch) {
2985
    push @rows, [@$row];
2986
}
2987
is_deeply(\@rows, [[1, 2], [3, 4]]);
2988

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2989
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2990
@rows = ();
2991
while (my $row = $result->fetch_hash) {
2992
    push @rows, {%$row};
2993
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2994
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2995

            
2996
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2997
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2998
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2999
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3000
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3001

            
3002
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3003
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3004
$rows = $result->fetch_all;
3005
is_deeply($rows, [[1, 2], [3, 4]]);
3006

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

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

            
3015
$rows = $result->fetch_all;
3016
is_deeply($rows, [[3, 2], [9, 4]], "array");
3017

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

            
3024
test "query_builder";
3025
$datas = [
3026
    # Basic tests
3027
    {   name            => 'placeholder basic',
3028
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3029
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3030
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3031
    },
3032
    {
3033
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3034
        source            => "{in k1 3}",
3035
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3036
        columns_expected   => [qw/k1 k1 k1/]
3037
    },
3038
    
3039
    # Table name
3040
    {
3041
        name            => 'placeholder with table name',
3042
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3043
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3044
        columns_expected  => [qw/a.k1 a.k2/]
3045
    },
3046
    {   
3047
        name            => 'placeholder in with table name',
3048
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3049
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3050
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3051
    },
3052
    {
3053
        name            => 'not contain tag',
3054
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3055
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3056
        columns_expected  => [],
3057
    }
3058
];
3059

            
3060
for (my $i = 0; $i < @$datas; $i++) {
3061
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3062
    my $dbi = DBIx::Custom->new;
3063
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3064
    my $query = $builder->build_query($data->{source});
3065
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3066
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3067
}
3068

            
cleanup
Yuki Kimoto authored on 2011-08-13
3069
$dbi = DBIx::Custom->new;
3070
$builder = $dbi->query_builder;
3071
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3072
    p => sub {
3073
        my @args = @_;
3074
        
3075
        my $expand    = "? $args[0] $args[1]";
3076
        my $columns = [2];
3077
        return [$expand, $columns];
3078
    }
3079
);
3080

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3091
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3092
    q => 'string'
3093
});
3094

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3098
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3099
   r => sub {} 
3100
});
3101

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3105
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3106
   s => sub { return ["a", ""]} 
3107
});
3108

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3112
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3113
    t => sub {return ["a", []]}
3114
);
3115

            
3116

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

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

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

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

            
3132
test 'variouse source';
3133
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3134
$query = $builder->build_query($source);
3135
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3136

            
3137
$source = "abc";
3138
$query = $builder->build_query($source);
3139
is($query->sql, 'abc', "basic : 2");
3140

            
3141
$source = "{= a}";
3142
$query = $builder->build_query($source);
3143
is($query->sql, 'a = ?', "only tag");
3144

            
3145
$source = "000";
3146
$query = $builder->build_query($source);
3147
is($query->sql, '000', "contain 0 value");
3148

            
3149
$source = "a {= b} }";
3150
eval{$builder->build_query($source)};
3151
like($@, qr/unexpected "}"/, "error : 1");
3152

            
3153
$source = "a {= {}";
3154
eval{$builder->build_query($source)};
3155
like($@, qr/unexpected "{"/, "error : 2");
3156

            
3157
test 'select() sqlfilter option';
3158
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3159
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3160
eval { $dbi->execute("drop table $table1") };
3161
$dbi->execute($create_table1);
3162
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3163
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3164
$rows = $dbi->select(
3165
    table => $table1,
3166
    column => $key1,
3167
    sqlfilter => sub {
3168
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
3169
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
3170
        return $sql;
3171
    }
3172
)->all;
3173
is_deeply($rows, [{$key1 => 1}]);
3174

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3175
test 'select() after_build_sql option';
3176
$dbi = DBIx::Custom->connect;
3177
$dbi->user_table_info($user_table_info);
3178
eval { $dbi->execute("drop table $table1") };
3179
$dbi->execute($create_table1);
3180
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3181
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3182
$rows = $dbi->select(
3183
    table => $table1,
3184
    column => $key1,
3185
    after_build_sql => sub {
3186
        my $sql = shift;
3187
        $sql = "select * from ( $sql ) t where $key1 = 1";
3188
        return $sql;
3189
    }
3190
)->all;
3191
is_deeply($rows, [{$key1 => 1}]);
3192

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3193
test 'dbi method from model';
3194
$dbi = MyDBI9->connect;
3195
eval { $dbi->execute("drop table $table1") };
3196
$dbi->execute($create_table1);
3197
$dbi->setup_model;
3198
$model = $dbi->model($table1);
3199
eval{$model->execute("select * from $table1")};
3200
ok(!$@);
3201

            
3202
test 'column table option';
3203
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3204
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3205
eval { $dbi->execute("drop table $table1") };
3206
$dbi->execute($create_table1);
3207
eval { $dbi->execute("drop table $table2") };
3208
$dbi->execute($create_table2);
3209
$dbi->setup_model;
3210
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3211
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3212
$model = $dbi->model($table1);
3213
$result = $model->select(
3214
    column => [
3215
        $model->column($table2, {alias => $table2_alias})
3216
    ],
3217
    where => {"$table2_alias.$key3" => 4}
3218
);
3219
is_deeply($result->one, 
3220
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3221

            
3222
$dbi->separator('__');
3223
$result = $model->select(
3224
    column => [
3225
        $model->column($table2, {alias => $table2_alias})
3226
    ],
3227
    where => {"$table2_alias.$key3" => 4}
3228
);
3229
is_deeply($result->one, 
3230
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3231

            
3232
$dbi->separator('-');
3233
$result = $model->select(
3234
    column => [
3235
        $model->column($table2, {alias => $table2_alias})
3236
    ],
3237
    where => {"$table2_alias.$key3" => 4}
3238
);
3239
is_deeply($result->one, 
3240
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3241

            
3242
test 'create_model';
3243
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3244
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3245
eval { $dbi->execute("drop table $table1") };
3246
eval { $dbi->execute("drop table $table2") };
3247
$dbi->execute($create_table1);
3248
$dbi->execute($create_table2);
3249

            
3250
$dbi->create_model(
3251
    table => $table1,
3252
    join => [
3253
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3254
    ],
3255
    primary_key => [$key1]
3256
);
3257
$model2 = $dbi->create_model(
3258
    table => $table2
3259
);
3260
$dbi->create_model(
3261
    table => $table3,
3262
    filter => [
3263
        $key1 => {in => sub { uc $_[0] }}
3264
    ]
3265
);
3266
$dbi->setup_model;
3267
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3268
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3269
$model = $dbi->model($table1);
3270
$result = $model->select(
3271
    column => [$model->mycolumn, $model->column($table2)],
3272
    where => {"$table1.$key1" => 1}
3273
);
3274
is_deeply($result->one,
3275
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3276
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3277

            
3278
test 'model method';
3279
$dbi = DBIx::Custom->connect;
3280
eval { $dbi->execute("drop table $table2") };
3281
$dbi->execute($create_table2);
3282
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3283
$model = $dbi->create_model(
3284
    table => $table2
3285
);
3286
$model->method(foo => sub { shift->select(@_) });
3287
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3288

            
3289
test 'model helper';
3290
$dbi = DBIx::Custom->connect;
3291
eval { $dbi->execute("drop table $table2") };
3292
$dbi->execute($create_table2);
3293
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3294
$model = $dbi->create_model(
3295
    table => $table2
3296
);
3297
$model->helper(foo => sub { shift->select(@_) });
3298
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3299

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3300
test 'assign_clause';
cleanup test
Yuki Kimoto authored on 2011-08-15
3301
$dbi = DBIx::Custom->connect;
3302
eval { $dbi->execute("drop table $table1") };
3303
$dbi->execute($create_table1_2);
3304
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3305
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3306

            
3307
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3308
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3309
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3310
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3311
where $key1 = 1
3312
EOS
3313
$dbi->execute($sql, param => $param);
3314
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3315
$rows   = $result->all;
3316
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3317
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3318
                  "basic");
3319

            
3320

            
3321
$dbi = DBIx::Custom->connect;
3322
eval { $dbi->execute("drop table $table1") };
3323
$dbi->execute($create_table1_2);
3324
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3325
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3326

            
3327
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3328
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3329
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3330
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3331
where $key1 = 1
3332
EOS
3333
$dbi->execute($sql, param => $param);
3334
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3335
$rows   = $result->all;
3336
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3337
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3338
                  "basic");
3339

            
3340
$dbi = DBIx::Custom->connect;
3341
eval { $dbi->execute("drop table $table1") };
3342
$dbi->execute($create_table1_2);
3343
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3344
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3345

            
3346
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3347
$assign_clause = $dbi->update_param($param, {no_set => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
3348
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3349
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3350
where $key1 = 1
3351
EOS
3352
$dbi->execute($sql, param => $param);
3353
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3354
$rows   = $result->all;
3355
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3356
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3357
                  "update param no_set");
3358

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

            
3363
$dbi = DBIx::Custom->connect;
3364
eval { $dbi->execute("drop table $table1") };
3365
$dbi->execute($create_table1_2);
3366
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3367
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3368

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3369
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3370
$assign_clause = $dbi->assign_param($param);
3371
$sql = <<"EOS";
3372
update $table1 set $assign_clause
3373
where $key1 = 1
3374
EOS
3375
$dbi->execute($sql, param => $param, table => $table1);
3376
$result = $dbi->execute("select * from $table1 order by $key1");
3377
$rows   = $result->all;
3378
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3379
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3380
                  "basic");
3381

            
3382
$param = {$key2 => 11};
3383
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3384
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3385
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3386
where $key1 = 1
3387
EOS
3388
$dbi->execute($sql, param => $param, table => $table1);
3389
$result = $dbi->execute("select * from $table1 order by $key1");
3390
$rows   = $result->all;
3391
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3392
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3393
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3394

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3395
test 'Model class';
3396
$dbi = MyDBI1->connect;
3397
eval { $dbi->execute("drop table $table1") };
3398
$dbi->execute($create_table1);
3399
$model = $dbi->model($table1);
3400
$model->insert({$key1 => 'a', $key2 => 'b'});
3401
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3402
eval { $dbi->execute("drop table $table2") };
3403
$dbi->execute($create_table2);
3404
$model = $dbi->model($table2);
3405
$model->insert({$key1 => 'a'});
3406
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3407
is($dbi->models->{$table1}, $dbi->model($table1));
3408
is($dbi->models->{$table2}, $dbi->model($table2));
3409

            
3410
$dbi = MyDBI4->connect;
3411
eval { $dbi->execute("drop table $table1") };
3412
$dbi->execute($create_table1);
3413
$model = $dbi->model($table1);
3414
$model->insert({$key1 => 'a', $key2 => 'b'});
3415
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3416
eval { $dbi->execute("drop table $table2") };
3417
$dbi->execute($create_table2);
3418
$model = $dbi->model($table2);
3419
$model->insert({$key1 => 'a'});
3420
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3421

            
3422
$dbi = MyDBI5->connect;
3423
eval { $dbi->execute("drop table $table1") };
3424
eval { $dbi->execute("drop table $table2") };
3425
$dbi->execute($create_table1);
3426
$dbi->execute($create_table2);
3427
$model = $dbi->model($table2);
3428
$model->insert({$key1 => 'a'});
3429
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3430
$dbi->insert(table => $table1, param => {$key1 => 1});
3431
$model = $dbi->model($table1);
3432
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3433

            
3434
test 'primary_key';
3435
$dbi = MyDBI1->connect;
3436
$model = $dbi->model($table1);
3437
$model->primary_key([$key1, $key2]);
3438
is_deeply($model->primary_key, [$key1, $key2]);
3439

            
3440
test 'columns';
3441
$dbi = MyDBI1->connect;
3442
$model = $dbi->model($table1);
3443
$model->columns([$key1, $key2]);
3444
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3445

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3446
test 'setup_model';
3447
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3448
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3449
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3450
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3451

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3452
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3453
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3454
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3455
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3456
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3457

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3458
test 'each_column';
3459
$dbi = DBIx::Custom->connect;
3460
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3461
eval { $dbi->execute("drop table $table1") };
3462
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3463
eval { $dbi->execute("drop table $table3") };
3464
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3465
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3466

            
3467
$infos = [];
3468
$dbi->each_column(sub {
3469
    my ($self, $table, $column, $cinfo) = @_;
3470
    
3471
    if ($table =~ /^table\d/i) {
3472
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3473
         push @$infos, $info;
3474
    }
3475
});
3476
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3477
is_deeply($infos, 
3478
    [
3479
        [$table1, $key1, $key1],
3480
        [$table1, $key2, $key2],
3481
        [$table2, $key1, $key1],
3482
        [$table2, $key3, $key3]
3483
    ]
3484
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3485
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3486

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3487
test 'each_table';
3488
$dbi = DBIx::Custom->connect;
3489
eval { $dbi->execute("drop table $table1") };
3490
eval { $dbi->execute("drop table $table2") };
3491
$dbi->execute($create_table2);
3492
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3493

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3494
$infos = [];
3495
$dbi->each_table(sub {
3496
    my ($self, $table, $table_info) = @_;
3497
    
3498
    if ($table =~ /^table\d/i) {
3499
         my $info = [$table, $table_info->{TABLE_NAME}];
3500
         push @$infos, $info;
3501
    }
3502
});
3503
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3504
is_deeply($infos, 
3505
    [
3506
        [$table1, $table1],
3507
        [$table2, $table2],
3508
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3509
);
3510

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3511
$dbi = DBIx::Custom->connect;
3512
eval { $dbi->execute("drop table $table1") };
3513
eval { $dbi->execute("drop table $table2") };
3514
$dbi->execute($create_table2);
3515
$dbi->execute($create_table1_type);
3516

            
3517
$infos = [];
3518
$dbi->user_table_info($user_table_info);
3519
$dbi->each_table(sub {
3520
    my ($self, $table, $table_info) = @_;
3521
    
3522
    if ($table =~ /^table\d/i) {
3523
         my $info = [$table, $table_info->{TABLE_NAME}];
3524
         push @$infos, $info;
3525
    }
3526
});
3527
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3528
is_deeply($infos, 
3529
    [
3530
        [$table1, $table1],
3531
        [$table2, $table2],
3532
        [$table3, $table3],
3533
    ]
3534
);
3535

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3536
test 'type_rule into';
3537
eval { $dbi->execute("drop table $table1") };
3538
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3539
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3540

            
3541

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3542
$dbi = DBIx::Custom->connect;
3543
eval { $dbi->execute("drop table $table1") };
3544
$dbi->execute($create_table1_type);
3545

            
cleanup
Yuki Kimoto authored on 2011-08-16
3546
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3547
$dbi->type_rule(
3548
    into1 => {
3549
        $date_typename => sub { '2010-' . $_[0] }
3550
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3551
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3552
$dbi->insert({$key1 => '01-01'}, table => $table1);
3553
$result = $dbi->select(table => $table1);
3554
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3555

            
3556
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3557
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3558
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3559
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3560
$dbi->type_rule(
3561
    into1 => [
3562
         [$date_typename, $datetime_typename] => sub {
3563
            my $value = shift;
3564
            $value =~ s/02/03/g;
3565
            return $value;
3566
         }
3567
    ]
3568
);
3569
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3570
$result = $dbi->select(table => $table1);
3571
$row = $result->one;
3572
like($row->{$key1}, qr/^2010-01-03/);
3573
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3574

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3575
$dbi = DBIx::Custom->connect;
3576
eval { $dbi->execute("drop table $table1") };
3577
$dbi->execute($create_table1_type);
3578
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3579
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3580
$dbi->type_rule(
3581
    into1 => [
3582
        [$date_typename, $datetime_typename] => sub {
3583
            my $value = shift;
3584
            $value =~ s/02/03/g;
3585
            return $value;
3586
        }
3587
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3588
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3589
$result = $dbi->execute(
3590
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3591
    param => {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
3592
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3593
$row = $result->one;
3594
like($row->{$key1}, qr/^2010-01-03/);
3595
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3596

            
3597
$dbi = DBIx::Custom->connect;
3598
eval { $dbi->execute("drop table $table1") };
3599
$dbi->execute($create_table1_type);
3600
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3601
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3602
$dbi->type_rule(
3603
    into1 => [
3604
        [$date_typename, $datetime_typename] => sub {
3605
            my $value = shift;
3606
            $value =~ s/02/03/g;
3607
            return $value;
3608
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3609
    ]
3610
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3611
$result = $dbi->execute(
3612
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3613
    param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
3614
    table => $table1
3615
);
3616
$row = $result->one;
3617
like($row->{$key1}, qr/^2010-01-03/);
3618
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3619

            
3620
$dbi = DBIx::Custom->connect;
3621
eval { $dbi->execute("drop table $table1") };
3622
$dbi->execute($create_table1_type);
3623
$dbi->register_filter(convert => sub {
3624
    my $value = shift || '';
3625
    $value =~ s/02/03/;
3626
    return $value;
3627
});
cleanup
Yuki Kimoto authored on 2011-08-16
3628
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3629
$dbi->type_rule(
3630
    from1 => {
3631
        $date_datatype => 'convert',
3632
    },
3633
    into1 => {
3634
        $date_typename => 'convert',
3635
    }
3636
);
3637
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3638
$result = $dbi->select(table => $table1);
3639
like($result->fetch->[0], qr/^2010-03-03/);
3640

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

            
3666

            
3667
$dbi = DBIx::Custom->connect;
3668
eval { $dbi->execute("drop table $table1") };
3669
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3670
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3671
$dbi->type_rule(
3672
    from1 => {
3673
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3674
    },
3675
    from2 => {
3676
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3677
    },
3678
);
3679
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3680
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3681
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3682
$result->type_rule(
3683
    from1 => {
3684
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3685
    },
3686
    from2 => {
3687
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3688
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3689
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3690
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3691
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3692

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3693
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
3694
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
3695
eval { $dbi->execute("drop table $table1") };
3696
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3697
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3698
$dbi->type_rule(
3699
    from1 => {
3700
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3701
    },
3702
    into1 => {
3703
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3704
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3705
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3706
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3707
$result = $dbi->select(table => $table1, type_rule_off => 1);
3708
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3709

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

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

            
3742
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3743
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3744
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3745
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3746
$dbi->type_rule(
3747
    from1 => {
3748
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3749
    },
3750
    into1 => {
3751
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3752
    }
3753
);
3754
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3755
$result = $dbi->select(table => $table1);
3756
like($result->fetch->[0], qr/2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3757

            
3758
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3759
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3760
$dbi->execute($create_table1_type);
3761
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
3762
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3763
$dbi->type_rule(
3764
    into1 => {
3765
        $date_typename => 'ppp'
3766
    }
3767
);
3768
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3769
$result = $dbi->select(table => $table1);
3770
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3771

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3772
eval{$dbi->type_rule(
3773
    into1 => {
3774
        $date_typename => 'pp'
3775
    }
3776
)};
3777
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3778

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3779
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3780
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3781
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3782
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3783
    $dbi->type_rule(
3784
        from1 => {
3785
            Date => sub { $_[0] * 2 },
3786
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3787
    );
3788
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3789
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3790

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3791
eval {
3792
    $dbi->type_rule(
3793
        into1 => {
3794
            Date => sub { $_[0] * 2 },
3795
        }
3796
    );
3797
};
3798
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3799

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

            
3817
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3818
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3819
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3820
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3821
$dbi->type_rule(
3822
    from1 => {
3823
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3824
        $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3825
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3826
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3827
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3828
$result = $dbi->select(table => $table1);
3829
$result->type_rule(
3830
    from1 => {
3831
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3832
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3833
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3834
$row = $result->one;
3835
like($row->{$key1}, qr/^2010-01-05/);
3836
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3837

            
3838
$result = $dbi->select(table => $table1);
3839
$result->type_rule(
3840
    from1 => {
3841
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3842
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3843
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3844
$row = $result->one;
3845
like($row->{$key1}, qr/2010-01-05/);
3846
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3847

            
3848
$result = $dbi->select(table => $table1);
3849
$result->type_rule(
3850
    from1 => {
3851
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3852
    }
3853
);
3854
$row = $result->one;
3855
like($row->{$key1}, qr/2010-01-05/);
3856
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3857

            
3858
$result = $dbi->select(table => $table1);
3859
$result->type_rule(
3860
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
3861
);
3862
$row = $result->one;
3863
like($row->{$key1}, qr/2010-01-05/);
3864
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3865

            
3866
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
3867
$result = $dbi->select(table => $table1);
3868
$result->type_rule(
3869
    from1 => [$date_datatype => 'five']
3870
);
3871
$row = $result->one;
3872
like($row->{$key1}, qr/^2010-01-05/);
3873
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3874

            
3875
$result = $dbi->select(table => $table1);
3876
$result->type_rule(
3877
    from1 => [$date_datatype => undef]
3878
);
3879
$row = $result->one;
3880
like($row->{$key1}, qr/^2010-01-03/);
3881
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3882

            
3883
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3884
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3885
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3886
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3887
$dbi->type_rule(
3888
    from1 => {
3889
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3890
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3891
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3892
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3893
$result = $dbi->select(table => $table1);
3894
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3895
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3896

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3897
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3898
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3899
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3900
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3901
$dbi->type_rule(
3902
    from1 => {
3903
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3904
    },
3905
);
3906
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3907
$result = $dbi->select(table => $table1);
3908
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3909
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3910

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3911
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3912
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3913
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3914
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3915
$dbi->type_rule(
3916
    into1 => {
3917
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3918
    },
3919
    into2 => {
3920
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3921
    },
3922
    from1 => {
3923
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3924
    },
3925
    from2 => {
3926
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
3927
    }
3928
);
3929
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3930
$result = $dbi->select(table => $table1);
3931
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/);
3932
$result = $dbi->select(table => $table1);
3933
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3934

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3935
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3936
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3937
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3938
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3939
$dbi->type_rule(
3940
    into1 => {
3941
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3942
    },
3943
    into2 => {
3944
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3945
    },
3946
    from1 => {
3947
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
3948
    },
3949
    from2 => {
3950
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3951
    }
3952
);
3953
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
3954
$result = $dbi->select(table => $table1);
3955
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/);
3956
$result = $dbi->select(table => $table1);
3957
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3958

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3959
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3960
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3961
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3962
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3963
$dbi->type_rule(
3964
    into1 => {
3965
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3966
    },
3967
    into2 => {
3968
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3969
    },
3970
    from1 => {
3971
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3972
    },
3973
    from2 => {
3974
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
3975
    }
3976
);
3977
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
3978
$result = $dbi->select(table => $table1);
3979
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
3980
$result = $dbi->select(table => $table1);
3981
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3982

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
3983
test 'join';
3984
$dbi = DBIx::Custom->connect;
3985
eval { $dbi->execute("drop table $table1") };
3986
$dbi->execute($create_table1);
3987
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3988
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
3989
eval { $dbi->execute("drop table $table2") };
3990
$dbi->execute($create_table2);
3991
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3992
eval { $dbi->execute("drop table $table3") };
3993
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
3994
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
3995
$rows = $dbi->select(
3996
    table => $table1,
3997
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3998
    where   => {"$table1.$key2" => 2},
3999
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4000
)->all;
4001
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
4002

            
4003
$rows = $dbi->select(
4004
    table => $table1,
4005
    where   => {$key1 => 1},
4006
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4007
)->all;
4008
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4009

            
4010
eval {
4011
    $rows = $dbi->select(
4012
        table => $table1,
4013
        column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4014
        where   => {"$table1.$key2" => 2},
4015
        join  => {"$table1.$key1" => "$table2.$key1"}
4016
    );
4017
};
4018
like ($@, qr/array/);
4019

            
4020
$rows = $dbi->select(
4021
    table => $table1,
4022
    where   => {$key1 => 1},
4023
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4024
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4025
)->all;
4026
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4027

            
4028
$rows = $dbi->select(
4029
    column => "$table3.$key4 as ${table3}__$key4",
4030
    table => $table1,
4031
    where   => {"$table1.$key1" => 1},
4032
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4033
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4034
)->all;
4035
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4036

            
4037
$rows = $dbi->select(
4038
    column => "$table1.$key1 as ${table1}__$key1",
4039
    table => $table1,
4040
    where   => {"$table3.$key4" => 4},
4041
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4042
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4043
)->all;
4044
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4045

            
4046
$dbi = DBIx::Custom->connect;
4047
eval { $dbi->execute("drop table $table1") };
4048
$dbi->execute($create_table1);
4049
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4050
eval { $dbi->execute("drop table $table2") };
4051
$dbi->execute($create_table2);
4052
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4053
$rows = $dbi->select(
4054
    table => $table1,
4055
    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",
4056
    where   => {"$table1.$key2" => 2},
4057
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4058
)->all;
4059
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4060
          'quote');
4061

            
4062

            
4063
$dbi = DBIx::Custom->connect;
4064
eval { $dbi->execute("drop table $table1") };
4065
$dbi->execute($create_table1);
4066
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4067
$sql = <<"EOS";
4068
left outer join (
4069
  select * from $table1 t1
4070
  where t1.$key2 = (
4071
    select max(t2.$key2) from $table1 t2
4072
    where t1.$key1 = t2.$key1
4073
  )
4074
) $table3 on $table1.$key1 = $table3.$key1
4075
EOS
4076
$join = [$sql];
4077
$rows = $dbi->select(
4078
    table => $table1,
4079
    column => "$table3.$key1 as ${table3}__$key1",
4080
    join  => $join
4081
)->all;
4082
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4083

            
4084
$dbi = DBIx::Custom->connect;
4085
eval { $dbi->execute("drop table $table1") };
4086
eval { $dbi->execute("drop table $table2") };
4087
$dbi->execute($create_table1);
4088
$dbi->execute($create_table2);
4089
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4090
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4091
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4092
$result = $dbi->select(
4093
    table => $table1,
4094
    join => [
4095
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4096
    ]
4097
);
4098
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4099
$result = $dbi->select(
4100
    table => $table1,
4101
    column => [{$table2 => [$key3]}],
4102
    join => [
4103
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4104
    ]
4105
);
4106
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4107
$result = $dbi->select(
4108
    table => $table1,
4109
    column => [{$table2 => [$key3]}],
4110
    join => [
4111
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4112
    ]
4113
);
4114
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4115

            
4116
$dbi = DBIx::Custom->connect;
4117
eval { $dbi->execute("drop table $table1") };
4118
eval { $dbi->execute("drop table $table2") };
4119
$dbi->execute($create_table1);
4120
$dbi->execute($create_table2);
4121
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4122
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4123
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4124
$result = $dbi->select(
4125
    table => $table1,
4126
    column => [{$table2 => [$key3]}],
4127
    join => [
4128
        {
4129
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4130
            table => [$table1, $table2]
4131
        }
4132
    ]
4133
);
4134
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4135

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4136
$dbi = DBIx::Custom->connect;
4137
eval { $dbi->execute("drop table $table1") };
4138
eval { $dbi->execute("drop table $table2") };
4139
$dbi->execute($create_table1);
4140
$dbi->execute($create_table2);
4141
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4142
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4143
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4144
$result = $dbi->select(
4145
    table => $table1,
4146
    column => [{$table2 => [$key3]}],
4147
    join => [
4148
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4149
    ]
4150
);
4151
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4152

            
4153
$dbi = DBIx::Custom->connect;
4154
eval { $dbi->execute("drop table $table1") };
4155
eval { $dbi->execute("drop table $table2") };
4156
$dbi->execute($create_table1);
4157
$dbi->execute($create_table2);
4158
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4159
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4160
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4161
$result = $dbi->select(
4162
    table => $table1,
4163
    column => [{$table2 => [$key3]}],
4164
    join => [
4165
        "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4166
    ]
4167
);
4168
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4169

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4170
test 'columns';
4171
$dbi = MyDBI1->connect;
4172
$model = $dbi->model($table1);
4173

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4174
test 'count';
4175
$dbi = DBIx::Custom->connect;
4176
eval { $dbi->execute("drop table $table1") };
4177
$dbi->execute($create_table1);
4178
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4179
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 3});
4180
is($dbi->count(table => $table1), 2);
4181
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4182
$model = $dbi->create_model(table => $table1);
4183
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4184

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