DBIx-Custom / t / common.t /
Newer Older
4188 lines | 140.821kb
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
        
121
        return $self->SUPER::insert(param => $param);
122
    }
123

            
124
    sub list { shift->select; }
125

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

            
128
    use strict;
129
    use warnings;
130

            
131
    use base 'MyModel2::Base1';
132

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

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

            
141
    package MyModel2::TABLE1;
142

            
143
    use strict;
144
    use warnings;
145

            
146
    use base 'MyModel2::Base1';
147

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

            
154
    sub list { shift->select; }
155

            
156
    package MyModel2::TABLE2;
157

            
158
    use strict;
159
    use warnings;
160

            
161
    use base 'MyModel2::Base1';
162

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

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

            
174
    use strict;
175
    use warnings;
176

            
177
    use base 'DBIx::Custom';
178

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
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->delete};
1668
like($@, qr/table/);
1669
eval {$dbi->select};
1670
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1671

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

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

            
1680
$dbi->apply_filter(
1681

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2014

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2210

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

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

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

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

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

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

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

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

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

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

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

            
2347

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

            
2363

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

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

            
2384

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

            
2403

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

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

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

            
2443

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

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

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

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

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

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

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

            
2539

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

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

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

            
2566

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3119

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3323

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3544

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

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

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

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

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

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

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

            
3669

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4065

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

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

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

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

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

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

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

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