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

            
cleanup
Yuki Kimoto authored on 2011-10-21
663
eval{$dbi->update(table => $table1, param => {';' => 1}, where => {$key1 => 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

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

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

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

            
2221

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2265
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2266
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2267
    primary_key => $key1, 
2268
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2269
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2270
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2271
);
2272

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

            
2277
$dbi = DBIx::Custom->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);
2280
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2281
    {$key3 => 3},
2282
    primary_key => [$key1, $key2], 
2283
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2284
    id => [1, 2],
2285
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2286
is($dbi->select(table => $table1)->one->{$key1}, 1);
2287
is($dbi->select(table => $table1)->one->{$key2}, 2);
2288
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2289

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

            
2304
$dbi = MyDBI6->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->model($table1)->insert(
2308
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2309
    id => [1, 2]
2310
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2311
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2312
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2313
is($row->{$key1}, 1);
2314
is($row->{$key2}, 2);
2315
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2316

            
2317
test 'update and id option';
2318
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2319
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2320
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2321
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2322
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2323
    table => $table1,
2324
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2325
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2326
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2327
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2328
is($dbi->select(table => $table1)->one->{$key1}, 1);
2329
is($dbi->select(table => $table1)->one->{$key2}, 2);
2330
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2331

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2332
$dbi->delete_all(table => $table1);
2333
$dbi->insert(table => $table1, param => {$key1 => 0, $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
    table => $table1,
2336
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2337
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2338
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2339
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2340
is($dbi->select(table => $table1)->one->{$key1}, 0);
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
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2345
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2346
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2347
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2348
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2349
    {$key3 => 4},
2350
    table => $table1,
2351
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2352
    id => [1, 2]
2353
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2354
is($dbi->select(table => $table1)->one->{$key1}, 1);
2355
is($dbi->select(table => $table1)->one->{$key2}, 2);
2356
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2357

            
2358

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

            
2374

            
2375
test 'delete and id option';
2376
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2377
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2378
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2379
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2380
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2381
    table => $table1,
2382
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2383
    id => [1, 2],
2384
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2385
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2386

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2387
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2388
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2389
    table => $table1,
2390
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2391
    id => 0,
2392
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2393
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2394

            
2395

            
2396
test 'model delete and id option';
2397
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2398
eval { $dbi->execute("drop table $table1") };
2399
eval { $dbi->execute("drop table $table2") };
2400
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2401
$dbi->execute($create_table1_2);
2402
$dbi->execute($create_table2_2);
2403
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2404
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2405
$dbi->model($table1)->delete(id => [1, 2]);
2406
is_deeply($dbi->select(table => $table1)->all, []);
2407
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2408
$dbi->model($table1)->delete(id => [1, 2]);
2409
is_deeply($dbi->select(table => $table1)->all, []);
2410
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2411
$dbi->model($table3)->delete(id => [1, 2]);
2412
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2413

            
2414

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

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

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

            
2454

            
2455
test 'model select_at';
2456
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2457
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2458
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2459
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2460
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2461
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2462
is($row->{$key1}, 1);
2463
is($row->{$key2}, 2);
2464
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2465

            
2466
test 'column separator is default .';
2467
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2468
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2469
eval { $dbi->execute("drop table $table1") };
2470
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2471
$dbi->execute($create_table1);
2472
$dbi->execute($create_table2);
2473
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2474
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2475
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2476
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2477
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2478
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2479
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2480
);
2481
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2482
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2483

            
2484
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2485
    column => [$model->column($table2 => [$key1, $key3])],
2486
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2487
);
2488
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2489
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2490

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2491
test 'separator';
2492
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2493
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2494
eval { $dbi->execute("drop table $table1") };
2495
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2496
$dbi->execute($create_table1);
2497
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2498

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

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

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

            
2550

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2551
test 'filter_off';
2552
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2553
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2554
eval { $dbi->execute("drop table $table1") };
2555
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2556
$dbi->execute($create_table1);
2557
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2558

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2559
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2560
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2561
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2562
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2563
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2564
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2565
);
2566
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2567
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2568
$model = $dbi->model($table1);
2569
$result = $model->select(column => $key1);
2570
$result->filter($key1 => sub { $_[0] * 2 });
2571
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2572

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2573
test 'available_datetype';
2574
$dbi = DBIx::Custom->connect;
2575
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2576

            
2577

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2578
test 'select prefix option';
2579
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2580
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2581
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2582
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2583
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2584
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2585

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

            
added tests
Yuki Kimoto authored on 2011-08-26
2587
test 'mapper';
2588
$dbi = DBIx::Custom->connect;
2589
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2590
    id => {key => "$table1.id"},
2591
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2592
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
2593
);
2594
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2595
  "$table1.price" => 1900});
2596

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2597
$dbi = DBIx::Custom->connect;
2598
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2599
    id => {key => "$table1.id"},
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2600
    author => ["$table1.author" => $dbi->like_value],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2601
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2602
);
2603
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2604
  "$table1.price" => 1900});
2605

            
added tests
Yuki Kimoto authored on 2011-08-26
2606
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2607
    id => {key => "$table1.id"},
2608
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2609
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
2610
);
2611
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2612

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

            
2620
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2621
    id => {key => "$table1.id"},
2622
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2623
);
2624
is_deeply($param, {"$table1.price" => undef});
2625

            
2626
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2627
    id => {key => "$table1.id", condition => 'exists'},
2628
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
2629
);
2630
is_deeply($param, {"$table1.price" => '%a'});
2631

            
2632
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2633
    id => {key => "$table1.id"},
added tests
Yuki Kimoto authored on 2011-08-26
2634
    price => ["$table1.price", sub { '%' . $_[0] }]
2635
);
2636
is_deeply($param, {"$table1.price" => '%a'});
2637

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2638
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2639
    price => sub { '%' . $_[0] },
2640
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2641
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2642
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2643

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2644
eval { $dbi->execute("drop table $table1") };
2645
$dbi->execute($create_table1);
2646
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2647
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
2648

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

            
2657
$where = $dbi->where;
2658
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2659
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
2660
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2661
$row = $result->all;
2662
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2663
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2664
$row = $result->all;
2665
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2666

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

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2679
$where = $dbi->where;
2680
$where->clause(['and', ":${key1}{=}"]);
2681
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
2682
  ->pass([$key1, $key2])->map;
2683
$where->param($param);
2684
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2685
$row = $result->all;
2686
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2687

            
2688
$where = $dbi->where;
2689
$where->clause(['and', ":${key1}{=}"]);
2690
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
2691
$where->param($param);
2692
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2693
$row = $result->all;
2694
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2695

            
2696
$where = $dbi->where;
2697
$where->clause(['and', ":${key1}{=}"]);
2698
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
2699
  ->pass([$key1, $key2])->map;
2700
$where->param($param);
2701
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2702
$row = $result->all;
2703
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2704

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2706
$where = $dbi->where;
2707
$where->clause(['and', ":${key1}{=}"]);
2708
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
2709
$where->param($param);
2710
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2711
$row = $result->all;
2712
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2713

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

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

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

            
2742
$where = $dbi->where;
2743
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2744
    id => {key => "$table1.id"},
2745
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2746
);
2747
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
2748

            
2749
$where = $dbi->where;
2750
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2751
    id => {key => "$table1.id", condition => 'exists'},
2752
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2753
);
2754
is_deeply($param, {"$table1.price" => '%a'});
2755

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

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

            
2774
$where = $dbi->where;
2775
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2776
    id => {key => "$table1.id", condition => 'length'},
2777
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
2778
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2779
);
2780
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2781
  "$table1.price" => 1900});
2782

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2788
test 'order';
2789
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2790
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2791
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2792
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2793
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
2794
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
2795
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2796
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2797
$order->prepend($key1, "$key2 desc");
2798
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2799
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
2800
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2801
$order->prepend("$key1 desc");
2802
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2803
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
2804
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2805

            
2806
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2807
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2808
$result = $dbi->select(table => $table1,
2809
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2810
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2811
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
2812
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
2813
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
2814
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2815

            
2816
test 'tag_parse';
2817
$dbi = DBIx::Custom->connect;
2818
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2819
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2820
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2821
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2822
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2823
ok($@);
2824

            
2825
test 'last_sql';
2826
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2827
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2828
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2829
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
2830
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2831

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2853
$source = "select * from $table1 where :${key1}{ = } and :${key2}{=}";
2854
$result = $dbi->execute($source, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2863
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
2864
$result = $dbi->execute(
2865
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2866
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2867
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
2868
);
2869
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2870
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2871

            
2872
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2873
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2874
$dbi->execute($create_table1_highperformance);
2875
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2876
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2877
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2878
];
2879
{
2880
    my $query;
2881
    foreach my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2882
      $query ||= $dbi->insert($row, table => $table1, query => 1);
2883
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
2884
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2885
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2886
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2887
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2888
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2889
      ]
2890
    );
2891
}
2892

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2893
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2894
$dbi->execute($create_table1_highperformance);
2895
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2896
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2897
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2898
];
2899
{
2900
    my $query;
2901
    my $sth;
2902
    foreach my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2903
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2904
      $sth ||= $query->sth;
2905
      $sth->execute(map { $row->{$_} } sort keys %$row);
2906
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2907
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2908
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2909
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2910
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2911
      ]
2912
    );
2913
}
2914

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2915
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2916
$dbi->execute($create_table1_highperformance);
2917
$rows = [
2918
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
2919
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
2920
];
2921
{
2922
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
2923
    my $query;
2924
    foreach my $row (@$rows) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2925
      $query ||= $model->insert($row, query => 1);
2926
      $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2927
    }
2928
    is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
2929
      [
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2930
          {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
2931
          {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2932
      ]
2933
    );
2934
}
2935

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2936
test 'id option more';
2937
eval { $dbi->execute("drop table $table1") };
2938
$dbi->execute($create_table1_highperformance);
2939
$row = {
2940
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
2941
};
2942
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2943
$model->insert($row);
2944
$query = $model->update({$key7 => 11}, id => 1, query => 1);
2945
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
2946
is_deeply($dbi->select(table => $table1)->one,
2947
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
2948
);
2949

            
2950
eval { $dbi->execute("drop table $table1") };
2951
eval { $dbi->execute("drop table $table2") };
2952
$dbi->execute($create_table1);
2953
$dbi->execute($create_table2);
2954
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2955
$model->insert({$key1 => 1, $key2 => 2});
2956
$model = $dbi->create_model(table => $table2, primary_key => $key1,
2957
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
2958
$model->insert({$key1 => 1, $key3 => 3});
2959
$result = $model->select(
2960
    column => {$table1 => ["$key2"]},
2961
    id => 1
2962
);
2963
is_deeply($result->all, [{"$table1.$key2" => 2}]);
2964

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

            
2976
eval { $dbi->execute("drop table $table1") };
2977
eval { $dbi->execute($create_table1_highperformance) };
2978
$row = {
2979
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
2980
};
2981
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2982
$model->insert($row);
2983
$query = $model->select(id => 1, query => 1);
2984
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
2985
is_deeply($dbi->select(table => $table1)->one,
2986
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
2987
);
2988

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2989
test 'result';
2990
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2991
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2992
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2993
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2994
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2995

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2996
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2997
@rows = ();
2998
while (my $row = $result->fetch) {
2999
    push @rows, [@$row];
3000
}
3001
is_deeply(\@rows, [[1, 2], [3, 4]]);
3002

            
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 = ();
3005
while (my $row = $result->fetch_hash) {
3006
    push @rows, {%$row};
3007
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3008
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3009

            
3010
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3011
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3012
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3013
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3014
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3015

            
3016
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3017
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3018
$rows = $result->fetch_all;
3019
is_deeply($rows, [[1, 2], [3, 4]]);
3020

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

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

            
3029
$rows = $result->fetch_all;
3030
is_deeply($rows, [[3, 2], [9, 4]], "array");
3031

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

            
3038
test "query_builder";
3039
$datas = [
3040
    # Basic tests
3041
    {   name            => 'placeholder basic',
3042
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3043
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3044
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3045
    },
3046
    {
3047
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3048
        source            => "{in k1 3}",
3049
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3050
        columns_expected   => [qw/k1 k1 k1/]
3051
    },
3052
    
3053
    # Table name
3054
    {
3055
        name            => 'placeholder with table name',
3056
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3057
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3058
        columns_expected  => [qw/a.k1 a.k2/]
3059
    },
3060
    {   
3061
        name            => 'placeholder in with table name',
3062
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3063
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3064
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3065
    },
3066
    {
3067
        name            => 'not contain tag',
3068
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3069
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3070
        columns_expected  => [],
3071
    }
3072
];
3073

            
3074
for (my $i = 0; $i < @$datas; $i++) {
3075
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3076
    my $dbi = DBIx::Custom->new;
3077
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3078
    my $query = $builder->build_query($data->{source});
3079
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3080
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3081
}
3082

            
cleanup
Yuki Kimoto authored on 2011-08-13
3083
$dbi = DBIx::Custom->new;
3084
$builder = $dbi->query_builder;
3085
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3086
    p => sub {
3087
        my @args = @_;
3088
        
3089
        my $expand    = "? $args[0] $args[1]";
3090
        my $columns = [2];
3091
        return [$expand, $columns];
3092
    }
3093
);
3094

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3105
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3106
    q => 'string'
3107
});
3108

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3112
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3113
   r => sub {} 
3114
});
3115

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3119
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3120
   s => sub { return ["a", ""]} 
3121
});
3122

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3126
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3127
    t => sub {return ["a", []]}
3128
);
3129

            
3130

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

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

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

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

            
3146
test 'variouse source';
3147
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3148
$query = $builder->build_query($source);
3149
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3150

            
3151
$source = "abc";
3152
$query = $builder->build_query($source);
3153
is($query->sql, 'abc', "basic : 2");
3154

            
3155
$source = "{= a}";
3156
$query = $builder->build_query($source);
3157
is($query->sql, 'a = ?', "only tag");
3158

            
3159
$source = "000";
3160
$query = $builder->build_query($source);
3161
is($query->sql, '000', "contain 0 value");
3162

            
3163
$source = "a {= b} }";
3164
eval{$builder->build_query($source)};
3165
like($@, qr/unexpected "}"/, "error : 1");
3166

            
3167
$source = "a {= {}";
3168
eval{$builder->build_query($source)};
3169
like($@, qr/unexpected "{"/, "error : 2");
3170

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3189
test 'select() after_build_sql option';
3190
$dbi = DBIx::Custom->connect;
3191
$dbi->user_table_info($user_table_info);
3192
eval { $dbi->execute("drop table $table1") };
3193
$dbi->execute($create_table1);
3194
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3195
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3196
$rows = $dbi->select(
3197
    table => $table1,
3198
    column => $key1,
3199
    after_build_sql => sub {
3200
        my $sql = shift;
3201
        $sql = "select * from ( $sql ) t where $key1 = 1";
3202
        return $sql;
3203
    }
3204
)->all;
3205
is_deeply($rows, [{$key1 => 1}]);
3206

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3207
test 'dbi method from model';
3208
$dbi = MyDBI9->connect;
3209
eval { $dbi->execute("drop table $table1") };
3210
$dbi->execute($create_table1);
3211
$dbi->setup_model;
3212
$model = $dbi->model($table1);
3213
eval{$model->execute("select * from $table1")};
3214
ok(!$@);
3215

            
3216
test 'column table option';
3217
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3218
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3219
eval { $dbi->execute("drop table $table1") };
3220
$dbi->execute($create_table1);
3221
eval { $dbi->execute("drop table $table2") };
3222
$dbi->execute($create_table2);
3223
$dbi->setup_model;
3224
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3225
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3226
$model = $dbi->model($table1);
3227
$result = $model->select(
3228
    column => [
3229
        $model->column($table2, {alias => $table2_alias})
3230
    ],
3231
    where => {"$table2_alias.$key3" => 4}
3232
);
3233
is_deeply($result->one, 
3234
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3235

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

            
3246
$dbi->separator('-');
3247
$result = $model->select(
3248
    column => [
3249
        $model->column($table2, {alias => $table2_alias})
3250
    ],
3251
    where => {"$table2_alias.$key3" => 4}
3252
);
3253
is_deeply($result->one, 
3254
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3255

            
3256
test 'create_model';
3257
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3258
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3259
eval { $dbi->execute("drop table $table1") };
3260
eval { $dbi->execute("drop table $table2") };
3261
$dbi->execute($create_table1);
3262
$dbi->execute($create_table2);
3263

            
3264
$dbi->create_model(
3265
    table => $table1,
3266
    join => [
3267
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3268
    ],
3269
    primary_key => [$key1]
3270
);
3271
$model2 = $dbi->create_model(
3272
    table => $table2
3273
);
3274
$dbi->create_model(
3275
    table => $table3,
3276
    filter => [
3277
        $key1 => {in => sub { uc $_[0] }}
3278
    ]
3279
);
3280
$dbi->setup_model;
3281
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3282
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3283
$model = $dbi->model($table1);
3284
$result = $model->select(
3285
    column => [$model->mycolumn, $model->column($table2)],
3286
    where => {"$table1.$key1" => 1}
3287
);
3288
is_deeply($result->one,
3289
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3290
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3291

            
3292
test 'model method';
3293
$dbi = DBIx::Custom->connect;
3294
eval { $dbi->execute("drop table $table2") };
3295
$dbi->execute($create_table2);
3296
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3297
$model = $dbi->create_model(
3298
    table => $table2
3299
);
3300
$model->method(foo => sub { shift->select(@_) });
3301
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3302

            
3303
test 'model helper';
3304
$dbi = DBIx::Custom->connect;
3305
eval { $dbi->execute("drop table $table2") };
3306
$dbi->execute($create_table2);
3307
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3308
$model = $dbi->create_model(
3309
    table => $table2
3310
);
3311
$model->helper(foo => sub { shift->select(@_) });
3312
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3313

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3314
test 'assign_clause';
cleanup test
Yuki Kimoto authored on 2011-08-15
3315
$dbi = DBIx::Custom->connect;
3316
eval { $dbi->execute("drop table $table1") };
3317
$dbi->execute($create_table1_2);
3318
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3319
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3320

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

            
3334

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

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

            
3354
$dbi = DBIx::Custom->connect;
3355
eval { $dbi->execute("drop table $table1") };
3356
$dbi->execute($create_table1_2);
3357
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3358
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3359

            
3360
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3361
$assign_clause = $dbi->update_param($param, {no_set => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
3362
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3363
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3364
where $key1 = 1
3365
EOS
3366
$dbi->execute($sql, param => $param);
3367
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3368
$rows   = $result->all;
3369
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3370
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3371
                  "update param no_set");
3372

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

            
3377
$dbi = DBIx::Custom->connect;
3378
eval { $dbi->execute("drop table $table1") };
3379
$dbi->execute($create_table1_2);
3380
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3381
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3382

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

            
3396
$param = {$key2 => 11};
3397
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3398
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3399
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3400
where $key1 = 1
3401
EOS
3402
$dbi->execute($sql, param => $param, table => $table1);
3403
$result = $dbi->execute("select * from $table1 order by $key1");
3404
$rows   = $result->all;
3405
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3406
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3407
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3408

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3409
test 'Model class';
3410
$dbi = MyDBI1->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
is($dbi->models->{$table1}, $dbi->model($table1));
3422
is($dbi->models->{$table2}, $dbi->model($table2));
3423

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

            
3436
$dbi = MyDBI5->connect;
3437
eval { $dbi->execute("drop table $table1") };
3438
eval { $dbi->execute("drop table $table2") };
3439
$dbi->execute($create_table1);
3440
$dbi->execute($create_table2);
3441
$model = $dbi->model($table2);
3442
$model->insert({$key1 => 'a'});
3443
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3444
$dbi->insert(table => $table1, param => {$key1 => 1});
3445
$model = $dbi->model($table1);
3446
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3447

            
3448
test 'primary_key';
3449
$dbi = MyDBI1->connect;
3450
$model = $dbi->model($table1);
3451
$model->primary_key([$key1, $key2]);
3452
is_deeply($model->primary_key, [$key1, $key2]);
3453

            
3454
test 'columns';
3455
$dbi = MyDBI1->connect;
3456
$model = $dbi->model($table1);
3457
$model->columns([$key1, $key2]);
3458
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3459

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3460
test 'setup_model';
3461
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3462
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3463
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3464
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3465

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3466
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3467
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3468
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3469
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3470
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3471

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3472
test 'each_column';
3473
$dbi = DBIx::Custom->connect;
3474
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3475
eval { $dbi->execute("drop table $table1") };
3476
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3477
eval { $dbi->execute("drop table $table3") };
3478
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3479
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3480

            
3481
$infos = [];
3482
$dbi->each_column(sub {
3483
    my ($self, $table, $column, $cinfo) = @_;
3484
    
3485
    if ($table =~ /^table\d/i) {
3486
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3487
         push @$infos, $info;
3488
    }
3489
});
3490
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3491
is_deeply($infos, 
3492
    [
3493
        [$table1, $key1, $key1],
3494
        [$table1, $key2, $key2],
3495
        [$table2, $key1, $key1],
3496
        [$table2, $key3, $key3]
3497
    ]
3498
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3499
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3500

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3501
test 'each_table';
3502
$dbi = DBIx::Custom->connect;
3503
eval { $dbi->execute("drop table $table1") };
3504
eval { $dbi->execute("drop table $table2") };
3505
$dbi->execute($create_table2);
3506
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3507

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3508
$infos = [];
3509
$dbi->each_table(sub {
3510
    my ($self, $table, $table_info) = @_;
3511
    
3512
    if ($table =~ /^table\d/i) {
3513
         my $info = [$table, $table_info->{TABLE_NAME}];
3514
         push @$infos, $info;
3515
    }
3516
});
3517
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3518
is_deeply($infos, 
3519
    [
3520
        [$table1, $table1],
3521
        [$table2, $table2],
3522
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3523
);
3524

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3525
$dbi = DBIx::Custom->connect;
3526
eval { $dbi->execute("drop table $table1") };
3527
eval { $dbi->execute("drop table $table2") };
3528
$dbi->execute($create_table2);
3529
$dbi->execute($create_table1_type);
3530

            
3531
$infos = [];
3532
$dbi->user_table_info($user_table_info);
3533
$dbi->each_table(sub {
3534
    my ($self, $table, $table_info) = @_;
3535
    
3536
    if ($table =~ /^table\d/i) {
3537
         my $info = [$table, $table_info->{TABLE_NAME}];
3538
         push @$infos, $info;
3539
    }
3540
});
3541
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3542
is_deeply($infos, 
3543
    [
3544
        [$table1, $table1],
3545
        [$table2, $table2],
3546
        [$table3, $table3],
3547
    ]
3548
);
3549

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3550
test 'type_rule into';
3551
eval { $dbi->execute("drop table $table1") };
3552
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3553
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3554

            
3555

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3556
$dbi = DBIx::Custom->connect;
3557
eval { $dbi->execute("drop table $table1") };
3558
$dbi->execute($create_table1_type);
3559

            
cleanup
Yuki Kimoto authored on 2011-08-16
3560
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3561
$dbi->type_rule(
3562
    into1 => {
3563
        $date_typename => sub { '2010-' . $_[0] }
3564
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3565
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3566
$dbi->insert({$key1 => '01-01'}, table => $table1);
3567
$result = $dbi->select(table => $table1);
3568
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3569

            
3570
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3571
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3572
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3573
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3574
$dbi->type_rule(
3575
    into1 => [
3576
         [$date_typename, $datetime_typename] => sub {
3577
            my $value = shift;
3578
            $value =~ s/02/03/g;
3579
            return $value;
3580
         }
3581
    ]
3582
);
3583
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3584
$result = $dbi->select(table => $table1);
3585
$row = $result->one;
3586
like($row->{$key1}, qr/^2010-01-03/);
3587
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3588

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

            
3611
$dbi = DBIx::Custom->connect;
3612
eval { $dbi->execute("drop table $table1") };
3613
$dbi->execute($create_table1_type);
3614
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3615
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3616
$dbi->type_rule(
3617
    into1 => [
3618
        [$date_typename, $datetime_typename] => sub {
3619
            my $value = shift;
3620
            $value =~ s/02/03/g;
3621
            return $value;
3622
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3623
    ]
3624
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3625
$result = $dbi->execute(
3626
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3627
    param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
3628
    table => $table1
3629
);
3630
$row = $result->one;
3631
like($row->{$key1}, qr/^2010-01-03/);
3632
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3633

            
3634
$dbi = DBIx::Custom->connect;
3635
eval { $dbi->execute("drop table $table1") };
3636
$dbi->execute($create_table1_type);
3637
$dbi->register_filter(convert => sub {
3638
    my $value = shift || '';
3639
    $value =~ s/02/03/;
3640
    return $value;
3641
});
cleanup
Yuki Kimoto authored on 2011-08-16
3642
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3643
$dbi->type_rule(
3644
    from1 => {
3645
        $date_datatype => 'convert',
3646
    },
3647
    into1 => {
3648
        $date_typename => 'convert',
3649
    }
3650
);
3651
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3652
$result = $dbi->select(table => $table1);
3653
like($result->fetch->[0], qr/^2010-03-03/);
3654

            
3655
test 'type_rule and filter order';
3656
$dbi = DBIx::Custom->connect;
3657
eval { $dbi->execute("drop table $table1") };
3658
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3659
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3660
$dbi->type_rule(
3661
    into1 => {
3662
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3663
    },
3664
    into2 => {
3665
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3666
    },
3667
    from1 => {
3668
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3669
    },
3670
    from2 => {
3671
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
3672
    }
3673
);
3674
$dbi->insert({$key1 => '2010-01-03'}, 
3675
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
3676
$result = $dbi->select(table => $table1);
3677
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3678
like($result->fetch_first->[0], qr/^2010-01-09/);
3679

            
3680

            
3681
$dbi = DBIx::Custom->connect;
3682
eval { $dbi->execute("drop table $table1") };
3683
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3684
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3685
$dbi->type_rule(
3686
    from1 => {
3687
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3688
    },
3689
    from2 => {
3690
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3691
    },
3692
);
3693
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3694
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3695
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3696
$result->type_rule(
3697
    from1 => {
3698
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3699
    },
3700
    from2 => {
3701
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3702
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3703
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3704
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3705
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3706

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

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

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

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

            
3772
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3773
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3774
$dbi->execute($create_table1_type);
3775
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
3776
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3777
$dbi->type_rule(
3778
    into1 => {
3779
        $date_typename => 'ppp'
3780
    }
3781
);
3782
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3783
$result = $dbi->select(table => $table1);
3784
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3785

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3786
eval{$dbi->type_rule(
3787
    into1 => {
3788
        $date_typename => 'pp'
3789
    }
3790
)};
3791
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3792

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3793
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3794
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3795
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3796
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3797
    $dbi->type_rule(
3798
        from1 => {
3799
            Date => sub { $_[0] * 2 },
3800
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3801
    );
3802
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3803
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3804

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3805
eval {
3806
    $dbi->type_rule(
3807
        into1 => {
3808
            Date => sub { $_[0] * 2 },
3809
        }
3810
    );
3811
};
3812
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3813

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

            
3831
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3832
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3833
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3834
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3835
$dbi->type_rule(
3836
    from1 => {
3837
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3838
        $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3839
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3840
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3841
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3842
$result = $dbi->select(table => $table1);
3843
$result->type_rule(
3844
    from1 => {
3845
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3846
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3847
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3848
$row = $result->one;
3849
like($row->{$key1}, qr/^2010-01-05/);
3850
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3851

            
3852
$result = $dbi->select(table => $table1);
3853
$result->type_rule(
3854
    from1 => {
3855
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3856
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3857
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3858
$row = $result->one;
3859
like($row->{$key1}, qr/2010-01-05/);
3860
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3861

            
3862
$result = $dbi->select(table => $table1);
3863
$result->type_rule(
3864
    from1 => {
3865
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3866
    }
3867
);
3868
$row = $result->one;
3869
like($row->{$key1}, qr/2010-01-05/);
3870
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3871

            
3872
$result = $dbi->select(table => $table1);
3873
$result->type_rule(
3874
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
3875
);
3876
$row = $result->one;
3877
like($row->{$key1}, qr/2010-01-05/);
3878
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3879

            
3880
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
3881
$result = $dbi->select(table => $table1);
3882
$result->type_rule(
3883
    from1 => [$date_datatype => 'five']
3884
);
3885
$row = $result->one;
3886
like($row->{$key1}, qr/^2010-01-05/);
3887
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3888

            
3889
$result = $dbi->select(table => $table1);
3890
$result->type_rule(
3891
    from1 => [$date_datatype => undef]
3892
);
3893
$row = $result->one;
3894
like($row->{$key1}, qr/^2010-01-03/);
3895
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3896

            
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
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3905
);
cleanup test
Yuki Kimoto authored on 2011-08-15
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->one->{$key1}, qr/^2010-01-05/);
cleanup test
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
    from1 => {
3917
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3918
    },
3919
);
3920
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3921
$result = $dbi->select(table => $table1);
3922
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3923
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3924

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3925
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3926
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3927
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3928
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3929
$dbi->type_rule(
3930
    into1 => {
3931
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3932
    },
3933
    into2 => {
3934
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3935
    },
3936
    from1 => {
3937
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3938
    },
3939
    from2 => {
3940
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
3941
    }
3942
);
3943
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3944
$result = $dbi->select(table => $table1);
3945
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/);
3946
$result = $dbi->select(table => $table1);
3947
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3948

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3949
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3950
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3951
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3952
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3953
$dbi->type_rule(
3954
    into1 => {
3955
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3956
    },
3957
    into2 => {
3958
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3959
    },
3960
    from1 => {
3961
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
3962
    },
3963
    from2 => {
3964
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3965
    }
3966
);
3967
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
3968
$result = $dbi->select(table => $table1);
3969
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/);
3970
$result = $dbi->select(table => $table1);
3971
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3972

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3973
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3974
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3975
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3976
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3977
$dbi->type_rule(
3978
    into1 => {
3979
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3980
    },
3981
    into2 => {
3982
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3983
    },
3984
    from1 => {
3985
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3986
    },
3987
    from2 => {
3988
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
3989
    }
3990
);
3991
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
3992
$result = $dbi->select(table => $table1);
3993
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
3994
$result = $dbi->select(table => $table1);
3995
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3996

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
3997
test 'join';
3998
$dbi = DBIx::Custom->connect;
3999
eval { $dbi->execute("drop table $table1") };
4000
$dbi->execute($create_table1);
4001
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4002
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
4003
eval { $dbi->execute("drop table $table2") };
4004
$dbi->execute($create_table2);
4005
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4006
eval { $dbi->execute("drop table $table3") };
4007
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
4008
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
4009
$rows = $dbi->select(
4010
    table => $table1,
4011
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4012
    where   => {"$table1.$key2" => 2},
4013
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4014
)->all;
4015
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
4016

            
4017
$rows = $dbi->select(
4018
    table => $table1,
4019
    where   => {$key1 => 1},
4020
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4021
)->all;
4022
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4023

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

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

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

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

            
4066

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

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

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4174
test 'columns';
4175
$dbi = MyDBI1->connect;
4176
$model = $dbi->model($table1);
4177

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

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