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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
734

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

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

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

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

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

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

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

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

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

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

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

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

            
830

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

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

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

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

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

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

            
865
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
866
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
867
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
868
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
869
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
870
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], "relation : no exists where");
test cleanup
Yuki Kimoto authored on 2011-08-10
871

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
968

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

            
974
$dbi->begin_work;
975

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

            
982
$dbi->rollback if $@;
983

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

            
988
$dbi->begin_work;
989

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

            
995
$dbi->commit unless $@;
996

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

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

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

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

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

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

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

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

            
1056
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1057
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1058
    one => sub { 1 }
1059
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1060
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1061
    two => sub { 2 }
1062
);
1063
$dbi->method({
1064
    twice => sub {
1065
        my $self = shift;
1066
        return $_[0] * 2;
1067
    }
1068
});
1069

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1216
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1217
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1218
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1219
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1220
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1221
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1222

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1595

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

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

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

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

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

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

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

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

            
1657
$dbi->apply_filter(
1658

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

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

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

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

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

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

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

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1732
test 'option';
1733
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
1734
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
1735
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
1736
ok($dbi->dbh->{PrintError});
1737
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
1738
ok($dbi->dbh->{PrintError});
1739

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

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

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

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

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

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

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

            
1803
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1804
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1805
$dbi->execute($create_table1_2);
1806
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1807
    {$key3 => 3},
1808
    primary_key => [$key1, $key2], 
1809
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1810
    where => [1, 2],
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
test 'update_at';
1817
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1818
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1819
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1820
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1821
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1822
    table => $table1,
1823
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1824
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1825
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
1826
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1827
is($dbi->select(table => $table1)->one->{$key1}, 1);
1828
is($dbi->select(table => $table1)->one->{$key2}, 2);
1829
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1830

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1991

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2187

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

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

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

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

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

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

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

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

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

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

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

            
2324

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

            
2340

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

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

            
2361

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

            
2380

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

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

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

            
2420

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

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

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

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

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

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

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

            
2516

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

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

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

            
2543

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

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

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

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

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

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

            
2586
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2587
    id => {key => "$table1.id"},
2588
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2589
);
2590
is_deeply($param, {"$table1.price" => undef});
2591

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

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

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

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

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

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

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

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2645
$where = $dbi->where;
2646
$where->clause(['and', ":${key1}{=}"]);
2647
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
2648
  ->pass([$key1, $key2])->map;
2649
$where->param($param);
2650
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2651
$row = $result->all;
2652
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2653

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

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

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2672
$where = $dbi->where;
2673
$where->clause(['and', ":${key1}{=}"]);
2674
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
2675
$where->param($param);
2676
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2677
$row = $result->all;
2678
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2679

            
2680
$where = $dbi->where;
2681
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2682
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2683
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2684
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2685
);
2686
$where->param($param);
2687
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2688
  "$table1.price" => 1900});
2689

            
2690
$where = $dbi->where;
2691
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2692
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2693
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2694
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2695
);
2696
$where->param($param);
2697
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2698

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

            
2708
$where = $dbi->where;
2709
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2710
    id => {key => "$table1.id"},
2711
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2712
);
2713
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
2714

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

            
2722
$where = $dbi->where;
2723
$param = $dbi->mapper(param => {id => [1, 2], author => 'Ken', price => 1900})->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 => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2727
);
2728
is_deeply($param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
2729
  "$table1.price" => 1900});
2730

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2902
test 'id option more';
2903
eval { $dbi->execute("drop table $table1") };
2904
$dbi->execute($create_table1_highperformance);
2905
$row = {
2906
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
2907
};
2908
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2909
$model->insert($row);
2910
$query = $model->update({$key7 => 11}, id => 1, query => 1);
2911
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
2912
is_deeply($dbi->select(table => $table1)->one,
2913
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
2914
);
2915

            
2916
eval { $dbi->execute("drop table $table1") };
2917
eval { $dbi->execute("drop table $table2") };
2918
$dbi->execute($create_table1);
2919
$dbi->execute($create_table2);
2920
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2921
$model->insert({$key1 => 1, $key2 => 2});
2922
$model = $dbi->create_model(table => $table2, primary_key => $key1,
2923
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
2924
$model->insert({$key1 => 1, $key3 => 3});
2925
$result = $model->select(
2926
    column => {$table1 => ["$key2"]},
2927
    id => 1
2928
);
2929
$DB::single = 1;
2930
is_deeply($result->all, [{"$table1.$key2" => 2}]);
2931

            
2932
eval { $dbi->execute("drop table $table1") };
2933
$dbi->execute($create_table1_highperformance);
2934
$row = {
2935
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
2936
};
2937
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2938
$model->insert($row);
2939
$query = $model->delete(id => 1, query => 1);
2940
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
2941
is_deeply($dbi->select(table => $table1)->all, []);
2942

            
2943
eval { $dbi->execute("drop table $table1") };
2944
eval { $dbi->execute($create_table1_highperformance) };
2945
$row = {
2946
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
2947
};
2948
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2949
$model->insert($row);
2950
$query = $model->select(id => 1, query => 1);
2951
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
2952
is_deeply($dbi->select(table => $table1)->one,
2953
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
2954
);
2955

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2956
test 'result';
2957
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2958
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2959
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2960
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2961
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2962

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2963
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2964
@rows = ();
2965
while (my $row = $result->fetch) {
2966
    push @rows, [@$row];
2967
}
2968
is_deeply(\@rows, [[1, 2], [3, 4]]);
2969

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2970
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2971
@rows = ();
2972
while (my $row = $result->fetch_hash) {
2973
    push @rows, {%$row};
2974
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2975
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2976

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

            
2983
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2984
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2985
$rows = $result->fetch_all;
2986
is_deeply($rows, [[1, 2], [3, 4]]);
2987

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2988
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2989
$rows = $result->fetch_hash_all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2990
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
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
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2994
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
2995

            
2996
$rows = $result->fetch_all;
2997
is_deeply($rows, [[3, 2], [9, 4]], "array");
2998

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

            
3005
test "query_builder";
3006
$datas = [
3007
    # Basic tests
3008
    {   name            => 'placeholder basic',
3009
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3010
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3011
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3012
    },
3013
    {
3014
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3015
        source            => "{in k1 3}",
3016
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3017
        columns_expected   => [qw/k1 k1 k1/]
3018
    },
3019
    
3020
    # Table name
3021
    {
3022
        name            => 'placeholder with table name',
3023
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3024
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3025
        columns_expected  => [qw/a.k1 a.k2/]
3026
    },
3027
    {   
3028
        name            => 'placeholder in with table name',
3029
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3030
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3031
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3032
    },
3033
    {
3034
        name            => 'not contain tag',
3035
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3036
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3037
        columns_expected  => [],
3038
    }
3039
];
3040

            
3041
for (my $i = 0; $i < @$datas; $i++) {
3042
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3043
    my $dbi = DBIx::Custom->new;
3044
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3045
    my $query = $builder->build_query($data->{source});
3046
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3047
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3048
}
3049

            
cleanup
Yuki Kimoto authored on 2011-08-13
3050
$dbi = DBIx::Custom->new;
3051
$builder = $dbi->query_builder;
3052
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3053
    p => sub {
3054
        my @args = @_;
3055
        
3056
        my $expand    = "? $args[0] $args[1]";
3057
        my $columns = [2];
3058
        return [$expand, $columns];
3059
    }
3060
);
3061

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3072
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3073
    q => 'string'
3074
});
3075

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3079
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3080
   r => sub {} 
3081
});
3082

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3086
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3087
   s => sub { return ["a", ""]} 
3088
});
3089

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3093
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3094
    t => sub {return ["a", []]}
3095
);
3096

            
3097

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

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

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

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

            
3113
test 'variouse source';
3114
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3115
$query = $builder->build_query($source);
3116
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3117

            
3118
$source = "abc";
3119
$query = $builder->build_query($source);
3120
is($query->sql, 'abc', "basic : 2");
3121

            
3122
$source = "{= a}";
3123
$query = $builder->build_query($source);
3124
is($query->sql, 'a = ?', "only tag");
3125

            
3126
$source = "000";
3127
$query = $builder->build_query($source);
3128
is($query->sql, '000', "contain 0 value");
3129

            
3130
$source = "a {= b} }";
3131
eval{$builder->build_query($source)};
3132
like($@, qr/unexpected "}"/, "error : 1");
3133

            
3134
$source = "a {= {}";
3135
eval{$builder->build_query($source)};
3136
like($@, qr/unexpected "{"/, "error : 2");
3137

            
3138
test 'select() sqlfilter option';
3139
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3140
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3141
eval { $dbi->execute("drop table $table1") };
3142
$dbi->execute($create_table1);
3143
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3144
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3145
$rows = $dbi->select(
3146
    table => $table1,
3147
    column => $key1,
3148
    sqlfilter => sub {
3149
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
3150
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
3151
        return $sql;
3152
    }
3153
)->all;
3154
is_deeply($rows, [{$key1 => 1}]);
3155

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3174
test 'dbi method from model';
3175
$dbi = MyDBI9->connect;
3176
eval { $dbi->execute("drop table $table1") };
3177
$dbi->execute($create_table1);
3178
$dbi->setup_model;
3179
$model = $dbi->model($table1);
3180
eval{$model->execute("select * from $table1")};
3181
ok(!$@);
3182

            
3183
test 'column table option';
3184
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3185
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3186
eval { $dbi->execute("drop table $table1") };
3187
$dbi->execute($create_table1);
3188
eval { $dbi->execute("drop table $table2") };
3189
$dbi->execute($create_table2);
3190
$dbi->setup_model;
3191
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3192
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3193
$model = $dbi->model($table1);
3194
$result = $model->select(
3195
    column => [
3196
        $model->column($table2, {alias => $table2_alias})
3197
    ],
3198
    where => {"$table2_alias.$key3" => 4}
3199
);
3200
is_deeply($result->one, 
3201
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3202

            
3203
$dbi->separator('__');
3204
$result = $model->select(
3205
    column => [
3206
        $model->column($table2, {alias => $table2_alias})
3207
    ],
3208
    where => {"$table2_alias.$key3" => 4}
3209
);
3210
is_deeply($result->one, 
3211
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3212

            
3213
$dbi->separator('-');
3214
$result = $model->select(
3215
    column => [
3216
        $model->column($table2, {alias => $table2_alias})
3217
    ],
3218
    where => {"$table2_alias.$key3" => 4}
3219
);
3220
is_deeply($result->one, 
3221
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3222

            
3223
test 'create_model';
3224
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3225
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3226
eval { $dbi->execute("drop table $table1") };
3227
eval { $dbi->execute("drop table $table2") };
3228
$dbi->execute($create_table1);
3229
$dbi->execute($create_table2);
3230

            
3231
$dbi->create_model(
3232
    table => $table1,
3233
    join => [
3234
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3235
    ],
3236
    primary_key => [$key1]
3237
);
3238
$model2 = $dbi->create_model(
3239
    table => $table2
3240
);
3241
$dbi->create_model(
3242
    table => $table3,
3243
    filter => [
3244
        $key1 => {in => sub { uc $_[0] }}
3245
    ]
3246
);
3247
$dbi->setup_model;
3248
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3249
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3250
$model = $dbi->model($table1);
3251
$result = $model->select(
3252
    column => [$model->mycolumn, $model->column($table2)],
3253
    where => {"$table1.$key1" => 1}
3254
);
3255
is_deeply($result->one,
3256
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3257
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3258

            
3259
test 'model method';
3260
$dbi = DBIx::Custom->connect;
3261
eval { $dbi->execute("drop table $table2") };
3262
$dbi->execute($create_table2);
3263
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3264
$model = $dbi->create_model(
3265
    table => $table2
3266
);
3267
$model->method(foo => sub { shift->select(@_) });
3268
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3269

            
3270
test 'model helper';
3271
$dbi = DBIx::Custom->connect;
3272
eval { $dbi->execute("drop table $table2") };
3273
$dbi->execute($create_table2);
3274
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3275
$model = $dbi->create_model(
3276
    table => $table2
3277
);
3278
$model->helper(foo => sub { shift->select(@_) });
3279
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3280

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3281
test 'assign_clause';
cleanup test
Yuki Kimoto authored on 2011-08-15
3282
$dbi = DBIx::Custom->connect;
3283
eval { $dbi->execute("drop table $table1") };
3284
$dbi->execute($create_table1_2);
3285
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3286
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3287

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

            
3301

            
3302
$dbi = DBIx::Custom->connect;
3303
eval { $dbi->execute("drop table $table1") };
3304
$dbi->execute($create_table1_2);
3305
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3306
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3307

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

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3376
test 'Model class';
3377
$dbi = MyDBI1->connect;
3378
eval { $dbi->execute("drop table $table1") };
3379
$dbi->execute($create_table1);
3380
$model = $dbi->model($table1);
3381
$model->insert({$key1 => 'a', $key2 => 'b'});
3382
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3383
eval { $dbi->execute("drop table $table2") };
3384
$dbi->execute($create_table2);
3385
$model = $dbi->model($table2);
3386
$model->insert({$key1 => 'a'});
3387
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3388
is($dbi->models->{$table1}, $dbi->model($table1));
3389
is($dbi->models->{$table2}, $dbi->model($table2));
3390

            
3391
$dbi = MyDBI4->connect;
3392
eval { $dbi->execute("drop table $table1") };
3393
$dbi->execute($create_table1);
3394
$model = $dbi->model($table1);
3395
$model->insert({$key1 => 'a', $key2 => 'b'});
3396
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3397
eval { $dbi->execute("drop table $table2") };
3398
$dbi->execute($create_table2);
3399
$model = $dbi->model($table2);
3400
$model->insert({$key1 => 'a'});
3401
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3402

            
3403
$dbi = MyDBI5->connect;
3404
eval { $dbi->execute("drop table $table1") };
3405
eval { $dbi->execute("drop table $table2") };
3406
$dbi->execute($create_table1);
3407
$dbi->execute($create_table2);
3408
$model = $dbi->model($table2);
3409
$model->insert({$key1 => 'a'});
3410
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3411
$dbi->insert(table => $table1, param => {$key1 => 1});
3412
$model = $dbi->model($table1);
3413
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3414

            
3415
test 'primary_key';
3416
$dbi = MyDBI1->connect;
3417
$model = $dbi->model($table1);
3418
$model->primary_key([$key1, $key2]);
3419
is_deeply($model->primary_key, [$key1, $key2]);
3420

            
3421
test 'columns';
3422
$dbi = MyDBI1->connect;
3423
$model = $dbi->model($table1);
3424
$model->columns([$key1, $key2]);
3425
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3426

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3427
test 'setup_model';
3428
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3429
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3430
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3431
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3432

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3433
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3434
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3435
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3436
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3437
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3438

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3439
test 'each_column';
3440
$dbi = DBIx::Custom->connect;
3441
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3442
eval { $dbi->execute("drop table $table1") };
3443
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3444
eval { $dbi->execute("drop table $table3") };
3445
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3446
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3447

            
3448
$infos = [];
3449
$dbi->each_column(sub {
3450
    my ($self, $table, $column, $cinfo) = @_;
3451
    
3452
    if ($table =~ /^table\d/i) {
3453
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3454
         push @$infos, $info;
3455
    }
3456
});
3457
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3458
is_deeply($infos, 
3459
    [
3460
        [$table1, $key1, $key1],
3461
        [$table1, $key2, $key2],
3462
        [$table2, $key1, $key1],
3463
        [$table2, $key3, $key3]
3464
    ]
3465
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3466
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3467

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3468
test 'each_table';
3469
$dbi = DBIx::Custom->connect;
3470
eval { $dbi->execute("drop table $table1") };
3471
eval { $dbi->execute("drop table $table2") };
3472
$dbi->execute($create_table2);
3473
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3474

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3475
$infos = [];
3476
$dbi->each_table(sub {
3477
    my ($self, $table, $table_info) = @_;
3478
    
3479
    if ($table =~ /^table\d/i) {
3480
         my $info = [$table, $table_info->{TABLE_NAME}];
3481
         push @$infos, $info;
3482
    }
3483
});
3484
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3485
is_deeply($infos, 
3486
    [
3487
        [$table1, $table1],
3488
        [$table2, $table2],
3489
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3490
);
3491

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

            
3498
$infos = [];
3499
$dbi->user_table_info($user_table_info);
3500
$dbi->each_table(sub {
3501
    my ($self, $table, $table_info) = @_;
3502
    
3503
    if ($table =~ /^table\d/i) {
3504
         my $info = [$table, $table_info->{TABLE_NAME}];
3505
         push @$infos, $info;
3506
    }
3507
});
3508
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3509
is_deeply($infos, 
3510
    [
3511
        [$table1, $table1],
3512
        [$table2, $table2],
3513
        [$table3, $table3],
3514
    ]
3515
);
3516

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3517
test 'type_rule into';
3518
eval { $dbi->execute("drop table $table1") };
3519
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3520
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3521

            
3522

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3523
$dbi = DBIx::Custom->connect;
3524
eval { $dbi->execute("drop table $table1") };
3525
$dbi->execute($create_table1_type);
3526

            
cleanup
Yuki Kimoto authored on 2011-08-16
3527
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3528
$dbi->type_rule(
3529
    into1 => {
3530
        $date_typename => sub { '2010-' . $_[0] }
3531
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3532
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3533
$dbi->insert({$key1 => '01-01'}, table => $table1);
3534
$result = $dbi->select(table => $table1);
3535
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3536

            
3537
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3538
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3539
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3540
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3541
$dbi->type_rule(
3542
    into1 => [
3543
         [$date_typename, $datetime_typename] => sub {
3544
            my $value = shift;
3545
            $value =~ s/02/03/g;
3546
            return $value;
3547
         }
3548
    ]
3549
);
3550
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3551
$result = $dbi->select(table => $table1);
3552
$row = $result->one;
3553
like($row->{$key1}, qr/^2010-01-03/);
3554
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3555

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

            
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
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3590
    ]
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-02', "$table1.$key2" => '2010-01-01 01:01:02'},
3595
    table => $table1
3596
);
3597
$row = $result->one;
3598
like($row->{$key1}, qr/^2010-01-03/);
3599
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3600

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

            
3622
test 'type_rule and filter order';
3623
$dbi = DBIx::Custom->connect;
3624
eval { $dbi->execute("drop table $table1") };
3625
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3626
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3627
$dbi->type_rule(
3628
    into1 => {
3629
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3630
    },
3631
    into2 => {
3632
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3633
    },
3634
    from1 => {
3635
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3636
    },
3637
    from2 => {
3638
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
3639
    }
3640
);
3641
$dbi->insert({$key1 => '2010-01-03'}, 
3642
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
3643
$result = $dbi->select(table => $table1);
3644
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3645
like($result->fetch_first->[0], qr/^2010-01-09/);
3646

            
3647

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3674
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
3675
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
3676
eval { $dbi->execute("drop table $table1") };
3677
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3678
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3679
$dbi->type_rule(
3680
    from1 => {
3681
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3682
    },
3683
    into1 => {
3684
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3685
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3686
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3687
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3688
$result = $dbi->select(table => $table1, type_rule_off => 1);
3689
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3690

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3753
eval{$dbi->type_rule(
3754
    into1 => {
3755
        $date_typename => 'pp'
3756
    }
3757
)};
3758
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3759

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3760
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3761
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3762
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3763
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3764
    $dbi->type_rule(
3765
        from1 => {
3766
            Date => sub { $_[0] * 2 },
3767
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3768
    );
3769
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3770
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3771

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3772
eval {
3773
    $dbi->type_rule(
3774
        into1 => {
3775
            Date => sub { $_[0] * 2 },
3776
        }
3777
    );
3778
};
3779
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3780

            
3781
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3782
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3783
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3784
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3785
$dbi->type_rule(
3786
    from1 => {
3787
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3788
    },
3789
    into1 => {
3790
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3791
    }
3792
);
3793
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3794
$result = $dbi->select(table => $table1);
3795
$result->type_rule_off;
3796
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3797

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

            
3819
$result = $dbi->select(table => $table1);
3820
$result->type_rule(
3821
    from1 => {
3822
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3823
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3824
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3825
$row = $result->one;
3826
like($row->{$key1}, qr/2010-01-05/);
3827
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3828

            
3829
$result = $dbi->select(table => $table1);
3830
$result->type_rule(
3831
    from1 => {
3832
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3833
    }
3834
);
3835
$row = $result->one;
3836
like($row->{$key1}, qr/2010-01-05/);
3837
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3838

            
3839
$result = $dbi->select(table => $table1);
3840
$result->type_rule(
3841
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
3842
);
3843
$row = $result->one;
3844
like($row->{$key1}, qr/2010-01-05/);
3845
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3846

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

            
3856
$result = $dbi->select(table => $table1);
3857
$result->type_rule(
3858
    from1 => [$date_datatype => undef]
3859
);
3860
$row = $result->one;
3861
like($row->{$key1}, qr/^2010-01-03/);
3862
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3863

            
3864
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3865
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3866
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3867
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3868
$dbi->type_rule(
3869
    from1 => {
3870
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3871
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3872
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3873
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3874
$result = $dbi->select(table => $table1);
3875
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3876
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3877

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3892
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3893
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3894
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3895
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3896
$dbi->type_rule(
3897
    into1 => {
3898
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3899
    },
3900
    into2 => {
3901
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3902
    },
3903
    from1 => {
3904
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3905
    },
3906
    from2 => {
3907
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
3908
    }
3909
);
3910
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3911
$result = $dbi->select(table => $table1);
3912
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/);
3913
$result = $dbi->select(table => $table1);
3914
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3915

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
3964
test 'join';
3965
$dbi = DBIx::Custom->connect;
3966
eval { $dbi->execute("drop table $table1") };
3967
$dbi->execute($create_table1);
3968
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3969
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
3970
eval { $dbi->execute("drop table $table2") };
3971
$dbi->execute($create_table2);
3972
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3973
eval { $dbi->execute("drop table $table3") };
3974
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
3975
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
3976
$rows = $dbi->select(
3977
    table => $table1,
3978
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3979
    where   => {"$table1.$key2" => 2},
3980
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
3981
)->all;
3982
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
3983

            
3984
$rows = $dbi->select(
3985
    table => $table1,
3986
    where   => {$key1 => 1},
3987
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
3988
)->all;
3989
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
3990

            
3991
eval {
3992
    $rows = $dbi->select(
3993
        table => $table1,
3994
        column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3995
        where   => {"$table1.$key2" => 2},
3996
        join  => {"$table1.$key1" => "$table2.$key1"}
3997
    );
3998
};
3999
like ($@, qr/array/);
4000

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

            
4009
$rows = $dbi->select(
4010
    column => "$table3.$key4 as ${table3}__$key4",
4011
    table => $table1,
4012
    where   => {"$table1.$key1" => 1},
4013
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4014
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4015
)->all;
4016
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4017

            
4018
$rows = $dbi->select(
4019
    column => "$table1.$key1 as ${table1}__$key1",
4020
    table => $table1,
4021
    where   => {"$table3.$key4" => 4},
4022
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4023
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4024
)->all;
4025
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4026

            
4027
$dbi = DBIx::Custom->connect;
4028
eval { $dbi->execute("drop table $table1") };
4029
$dbi->execute($create_table1);
4030
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4031
eval { $dbi->execute("drop table $table2") };
4032
$dbi->execute($create_table2);
4033
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4034
$rows = $dbi->select(
4035
    table => $table1,
4036
    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",
4037
    where   => {"$table1.$key2" => 2},
4038
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4039
)->all;
4040
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4041
          'quote');
4042

            
4043

            
4044
$dbi = DBIx::Custom->connect;
4045
eval { $dbi->execute("drop table $table1") };
4046
$dbi->execute($create_table1);
4047
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4048
$sql = <<"EOS";
4049
left outer join (
4050
  select * from $table1 t1
4051
  where t1.$key2 = (
4052
    select max(t2.$key2) from $table1 t2
4053
    where t1.$key1 = t2.$key1
4054
  )
4055
) $table3 on $table1.$key1 = $table3.$key1
4056
EOS
4057
$join = [$sql];
4058
$rows = $dbi->select(
4059
    table => $table1,
4060
    column => "$table3.$key1 as ${table3}__$key1",
4061
    join  => $join
4062
)->all;
4063
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4064

            
4065
$dbi = DBIx::Custom->connect;
4066
eval { $dbi->execute("drop table $table1") };
4067
eval { $dbi->execute("drop table $table2") };
4068
$dbi->execute($create_table1);
4069
$dbi->execute($create_table2);
4070
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4071
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4072
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4073
$result = $dbi->select(
4074
    table => $table1,
4075
    join => [
4076
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4077
    ]
4078
);
4079
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4080
$result = $dbi->select(
4081
    table => $table1,
4082
    column => [{$table2 => [$key3]}],
4083
    join => [
4084
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4085
    ]
4086
);
4087
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4088
$result = $dbi->select(
4089
    table => $table1,
4090
    column => [{$table2 => [$key3]}],
4091
    join => [
4092
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4093
    ]
4094
);
4095
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4096

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4151
test 'columns';
4152
$dbi = MyDBI1->connect;
4153
$model = $dbi->model($table1);
4154

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4155
test 'count';
4156
$dbi = DBIx::Custom->connect;
4157
eval { $dbi->execute("drop table $table1") };
4158
$dbi->execute($create_table1);
4159
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4160
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 3});
4161
is($dbi->count(table => $table1), 2);
4162
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4163
$model = $dbi->create_model(table => $table1);
4164
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4165

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