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

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

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

            
14
plan 'no_plan';
15

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

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

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

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

            
88
    use strict;
89
    use warnings;
90

            
91
    use base 'DBIx::Custom';
92

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

            
104
    package MyModel2::Base1;
105

            
106
    use strict;
107
    use warnings;
108

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

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

            
113
    use strict;
114
    use warnings;
115

            
116
    use base 'MyModel2::Base1';
117

            
118
    sub insert {
119
        my ($self, $param) = @_;
120
        
cleanup
Yuki Kimoto authored on 2011-10-21
121
        return $self->SUPER::insert($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
122
    }
123

            
124
    sub list { shift->select; }
125

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

            
128
    use strict;
129
    use warnings;
130

            
131
    use base 'MyModel2::Base1';
132

            
133
    sub insert {
134
        my ($self, $param) = @_;
135
        
cleanup
Yuki Kimoto authored on 2011-10-21
136
        return $self->SUPER::insert($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
137
    }
138

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

            
141
    package MyModel2::TABLE1;
142

            
143
    use strict;
144
    use warnings;
145

            
146
    use base 'MyModel2::Base1';
147

            
148
    sub insert {
149
        my ($self, $param) = @_;
150
        
cleanup
Yuki Kimoto authored on 2011-10-21
151
        return $self->SUPER::insert($param);
test cleanup
Yuki Kimoto authored on 2011-08-15
152
    }
153

            
154
    sub list { shift->select; }
155

            
156
    package MyModel2::TABLE2;
157

            
158
    use strict;
159
    use warnings;
160

            
161
    use base 'MyModel2::Base1';
162

            
163
    sub insert {
164
        my ($self, $param) = @_;
165
        
cleanup
Yuki Kimoto authored on 2011-10-21
166
        return $self->SUPER::insert($param);
test cleanup
Yuki Kimoto authored on 2011-08-15
167
    }
168

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

            
174
    use strict;
175
    use warnings;
176

            
177
    use base 'DBIx::Custom';
178

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
569

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
773

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

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

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

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

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

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

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

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

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

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

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

            
866

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
998

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

            
1004
$dbi->begin_work;
1005

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

            
1012
$dbi->rollback if $@;
1013

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

            
1018
$dbi->begin_work;
1019

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

            
1025
$dbi->commit unless $@;
1026

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

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

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

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

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

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

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

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

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

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

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

            
1121
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1122
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1123
$dbi->execute($create_table1);
1124
$dbi->register_filter(twice => sub { $_[0] * 2 });
1125
$dbi->register_filter(three_times => sub { $_[0] * 3});
1126
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1127
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1128
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1129
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1130
    $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1131
); 
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1132
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1133
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1134
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1135
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1136

            
1137
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1138
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1139
$dbi->execute($create_table1);
1140
$dbi->register_filter(twice => sub { $_[0] * 2 });
1141
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1142
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1143
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1144
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => undef});
1145
$dbi->update(table => $table1, param => {$key1 => 2}, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1146
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1147
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1148
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
test cleanup
Yuki Kimoto authored on 2011-08-10
1149

            
1150
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1151
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1152
$dbi->execute($create_table1);
1153
$dbi->register_filter(twice => sub { $_[0] * 2 });
1154
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1155
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1156
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1157
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1=> undef});
1158
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1159
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1160
$rows   = $result->all;
1161
is_deeply($rows, [], "delete");
1162

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1473
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1474
             ->clause("$key1 = :$key1 $key2 = :$key2")
1475
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1476
eval{$where->to_string};
1477
like($@, qr/one column/);
1478

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1622

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

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

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

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

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

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

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

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

            
1678
$dbi->apply_filter(
1679

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

            
1691
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1692
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1693
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1694
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1695
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1696
$dbi->apply_filter($table1, $key2, {});
1697
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1698
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1699

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2012

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
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,
cleanup test
Yuki Kimoto authored on 2011-08-10
2200
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2201
        "$key1 = :$key1 and $key2 = :$key2",
2202
         {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2203
    ]
2204
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2205
$rows = $dbi->select(table => $table1)->all;
2206
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2207

            
2208

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

            
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},
cleanup test
Yuki Kimoto authored on 2011-08-10
2230
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2231
        "$key1 = :$key1 and $key2 = :$key2",
2232
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2233
    ]
2234
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2235
$rows = $dbi->select(table => $table1)->all;
2236
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2237

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

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

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

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

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

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

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

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

            
2345

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

            
2361

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

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

            
2382

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

            
2401

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

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

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

            
2441

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2511
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
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

            
2537

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

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

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

            
2564

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3019
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3020
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3021
$result->filter({$key1 => 'three_times'});
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 => 3, $key2 => 2}, {$key1 => 9, $key2 => 4}], "hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
3024

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3117

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3321

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

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

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

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

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

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

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

            
3383
$param = {$key2 => 11};
3384
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3385
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3386
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
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");
test cleanup
Yuki Kimoto authored on 2011-08-10
3395

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3542

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

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

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

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

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

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

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

            
3667

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4063

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

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

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

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

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

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

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

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