DBIx-Custom / t / common.t /
Newer Older
4210 lines | 141.683kb
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;
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
83
my $reuse_sth;
cleanup test
Yuki Kimoto authored on 2011-08-15
84

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

            
89
    use strict;
90
    use warnings;
91

            
92
    use base 'DBIx::Custom';
93

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

            
105
    package MyModel2::Base1;
106

            
107
    use strict;
108
    use warnings;
109

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

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

            
114
    use strict;
115
    use warnings;
116

            
117
    use base 'MyModel2::Base1';
118

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

            
125
    sub list { shift->select; }
126

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

            
129
    use strict;
130
    use warnings;
131

            
132
    use base 'MyModel2::Base1';
133

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

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

            
142
    package MyModel2::TABLE1;
143

            
144
    use strict;
145
    use warnings;
146

            
147
    use base 'MyModel2::Base1';
148

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

            
155
    sub list { shift->select; }
156

            
157
    package MyModel2::TABLE2;
158

            
159
    use strict;
160
    use warnings;
161

            
162
    use base 'MyModel2::Base1';
163

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

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

            
175
    use strict;
176
    use warnings;
177

            
178
    use base 'DBIx::Custom';
179

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

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

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
241
test 'execute reuse_sth option';
242
eval { $dbi->execute("drop table $table1") };
243
$dbi->execute($create_table1);
244
$reuse_sth = {};
245
for my $i (1 .. 2) {
246
  $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, reuse_sth => $reuse_sth);
247
}
248
$rows = $dbi->select(table => $table1)->all;
249
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 1, $key2 => 2}]);
250

            
added test
Yuki Kimoto authored on 2011-08-16
251
# Get user table info
252
$dbi = DBIx::Custom->connect;
253
eval { $dbi->execute("drop table $table1") };
254
eval { $dbi->execute("drop table $table2") };
255
eval { $dbi->execute("drop table $table3") };
256
$dbi->execute($create_table1);
257
$dbi->execute($create_table2);
258
$dbi->execute($create_table3);
259
$user_table_info = $dbi->get_table_info(exclude => $dbi->exclude_table);
260

            
cleanup test
Yuki Kimoto authored on 2011-08-15
261
# Create table
test cleanup
Yuki Kimoto authored on 2011-08-10
262
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
263
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
264
$dbi->execute($create_table1);
265
$model = $dbi->create_model(table => $table1);
266
$model->insert({$key1 => 1, $key2 => 2});
267
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-08-15
268

            
cleanup test
Yuki Kimoto authored on 2011-08-15
269
test 'DBIx::Custom::Result test';
270
$dbi->delete_all(table => $table1);
271
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-10-21
272
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
273
$source = "select $key1, $key2 from $table1";
274
$query = $dbi->create_query($source);
275
$result = $dbi->execute($query);
cleanup
Yuki Kimoto authored on 2011-08-15
276

            
cleanup test
Yuki Kimoto authored on 2011-08-15
277
@rows = ();
278
while (my $row = $result->fetch) {
279
    push @rows, [@$row];
280
}
281
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
cleanup
Yuki Kimoto authored on 2011-08-15
282

            
cleanup test
Yuki Kimoto authored on 2011-08-15
283
$result = $dbi->execute($query);
284
@rows = ();
285
while (my $row = $result->fetch_hash) {
286
    push @rows, {%$row};
287
}
288
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
289

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
298
test 'Insert query return value';
299
$source = "insert into $table1 {insert_param $key1 $key2}";
300
$query = $dbi->execute($source, {}, query => 1);
301
$ret_val = $dbi->execute($query, param => {$key1 => 1, $key2 => 2});
302
ok($ret_val);
test cleanup
Yuki Kimoto authored on 2011-08-10
303

            
cleanup test
Yuki Kimoto authored on 2011-08-15
304
test 'Direct query';
305
$dbi->delete_all(table => $table1);
306
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
307
$dbi->execute($insert_source, param => {$key1 => 1, $key2 => 2});
308
$result = $dbi->execute("select * from $table1");
309
$rows = $result->all;
310
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
311

            
312
test 'Filter basic';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
313
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-08
314
$dbi->register_filter(twice       => sub { $_[0] * 2}, 
315
                    three_times => sub { $_[0] * 3});
316

            
cleanup test
Yuki Kimoto authored on 2011-08-15
317
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
318
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
319
$insert_query->filter({$key1 => 'twice'});
320
$dbi->execute($insert_query, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
321
$result = $dbi->execute("select * from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
322
$rows = $result->filter({$key2 => 'three_times'})->all;
323
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
324

            
325
test 'Filter in';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
326
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
327
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
328
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
329
$dbi->execute($insert_query, param => {$key1 => 2, $key2 => 4});
330
$select_source = "select * from $table1 where {in $table1.$key1 2} and {in $table1.$key2 2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
331
$select_query = $dbi->execute($select_source,{}, query => 1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
332
$select_query->filter({"$table1.$key1" => 'twice'});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
333
$result = $dbi->execute($select_query, param => {"$table1.$key1" => [1,5], "$table1.$key2" => [2,4]});
cleanup test
Yuki Kimoto authored on 2011-08-08
334
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
335
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
336

            
cleanup test
Yuki Kimoto authored on 2011-08-08
337
test 'DBIx::Custom::SQLTemplate basic tag';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
338
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
339
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
340
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
341
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
342

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

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

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

            
361
test 'DIB::Custom::SQLTemplate in tag';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
362
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
363
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
364
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
365
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
366

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-08
396
test 'Named placeholder';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
397
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
398
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
399
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
400
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
401

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
417
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
418
$result = $dbi->execute(
419
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
420
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
421
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
cleanup test
Yuki Kimoto authored on 2011-08-08
422
);
423
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
424
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
425

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
426
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
427
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
428
$dbi->insert(table => $table1, param => {$key1 => '2011-10-14 12:19:18', $key2 => 2});
429
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
430
$result = $dbi->execute(
431
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
432
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
433
);
434

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
439
$dbi->delete_all(table => $table1);
440
$dbi->insert(table => $table1, param => {$key1 => 'a:b c:d', $key2 => 2});
441
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
442
$result = $dbi->execute(
443
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
444
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
445
);
446
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
447
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
448

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
456
test 'insert';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
457
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
458
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
459
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
460
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
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 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
464

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
465
$dbi->execute("delete from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
466
$dbi->register_filter(
467
    twice       => sub { $_[0] * 2 },
468
    three_times => sub { $_[0] * 3 }
469
);
470
$dbi->default_bind_filter('twice');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
471
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => 'three_times'});
cleanup test
Yuki Kimoto authored on 2011-08-15
472
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
473
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
474
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-10
475
$dbi->default_bind_filter(undef);
476

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
477
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
478
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
479
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, append => '   ');
480
$rows = $dbi->select(table => $table1)->all;
481
is_deeply($rows, [{$key1 => 1, $key2 => 2}], 'insert append');
cleanup test
Yuki Kimoto authored on 2011-08-10
482

            
483
eval{$dbi->insert(table => 'table', param => {';' => 1})};
484
like($@, qr/safety/);
485

            
cleanup test
Yuki Kimoto authored on 2011-08-10
486
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
487
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
488
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
489
$dbi->insert(table => 'table', param => {select => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
490
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
491
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
492
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
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({$key1 => 1, $key2 => 2}, table => $table1);
497
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
502
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
503
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
504
$dbi->insert(table => $table1, param => {$key1 => \"'1'", $key2 => 2});
505
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
506
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
507
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
508
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
509

            
updated pod
Yuki Kimoto authored on 2011-09-02
510
eval { $dbi->execute("drop table $table1") };
511
$dbi->execute($create_table1);
512
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
513
  wrap => {$key1 => sub { "$_[0] - 1" }});
514
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
515
$result = $dbi->execute("select * from $table1");
516
$rows   = $result->all;
517
is_deeply($rows, [{$key1 => 0, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
518

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
529
eval { $dbi->execute("drop table $table1") };
530
$dbi->execute($create_table1);
531
$dbi->insert_timestamp(
532
    [$key1, $key2] => sub { 5 }
533
);
534
$dbi->insert(table => $table1, timestamp => 1);
535
$result = $dbi->execute("select * from $table1");
536
$rows   = $result->all;
537
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
538

            
539
eval { $dbi->execute("drop table $table1") };
540
$dbi->execute($create_table1);
541
$dbi->insert_timestamp(
542
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
543
);
544
$dbi->insert(table => $table1, timestamp => 1);
545
$result = $dbi->execute("select * from $table1");
546
$rows   = $result->all;
547
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
548

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
549
test 'update_or_insert';
550
eval { $dbi->execute("drop table $table1") };
551
$dbi->execute($create_table1);
552
$dbi->update_or_insert(
553
    {$key2 => 2},
554
    table => $table1,
555
    primary_key => $key1,
556
    id => 1
557
);
558
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
559
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
560

            
561
$dbi->update_or_insert(
562
    {$key2 => 3},
563
    table => $table1,
564
    primary_key => $key1,
565
    id => 1
566
);
567
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
568
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
569

            
570
eval { $dbi->execute("drop table $table1") };
571
$dbi->execute($create_table1);
572
$dbi->update_or_insert(
573
    {$key1 => 1, $key2 => 2},
574
    table => $table1,
575
    where => {$key1 => 1}
576
);
577
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
578
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
579

            
580

            
581
test 'default_bind_filter';
582
$dbi->execute("delete from $table1");
583
$dbi->register_filter(
584
    twice       => sub { $_[0] * 2 },
585
    three_times => sub { $_[0] * 3 }
586
);
587
$dbi->default_bind_filter('twice');
588
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => 'three_times'});
589
$result = $dbi->execute("select * from $table1");
590
$rows   = $result->all;
591
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
592
$dbi->default_bind_filter(undef);
593

            
test cleanup
Yuki Kimoto authored on 2011-08-10
594
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
595
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
596
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
597
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
598
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
599
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
600
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
601
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
602
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
603
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
604
                  "basic");
605
                  
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
606
$dbi->execute("delete from $table1");
607
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
608
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
609
$dbi->update(table => $table1, param => {$key2 => 12}, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
610
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
611
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
612
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
613
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
614
                  "update key same as search key");
615

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
623
$dbi->execute("delete from $table1");
624
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
625
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
626
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
627
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1},
628
              filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
629
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
630
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
631
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
632
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
633
                  "filter");
634

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

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
664
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
665
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
666
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
667
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
668
$where->clause(['and', "$key2 = :$key2"]);
669
$where->param({$key2 => 2});
670
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
671
$result = $dbi->select(table => $table1);
672
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
673

            
cleanup
Yuki Kimoto authored on 2011-10-21
674
eval{$dbi->update(table => $table1, param => {';' => 1}, where => {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
675
like($@, qr/safety/);
676

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

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

            
691
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
692
like($@, qr/safety/);
693

            
694
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
695
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
696
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
697
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
698
$dbi->insert(table => 'table', param => {select => 1});
699
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
700
$result = $dbi->execute("select * from ${q}table$p");
701
$rows   = $result->all;
702
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
703

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
704
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
705
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
706
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
707
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
708
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
709
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
710
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
711
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
712
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
713
                  "basic");
714

            
updated pod
Yuki Kimoto authored on 2011-09-02
715
eval { $dbi->execute("drop table $table1") };
716
$dbi->execute($create_table1_2);
717
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
718
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
719
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1},
720
wrap => {$key2 => sub { "$_[0] - 1" }});
721
$result = $dbi->execute("select * from $table1 order by $key1");
722
$rows   = $result->all;
723
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5},
724
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
725
                  "basic");
726

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
727
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
728
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
729
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
730
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
731
$dbi->update(table => $table1, param => {$key2 => \"'11'"}, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
732
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
733
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
734
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
735
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
736
                  "basic");
737

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
749
eval { $dbi->execute("drop table $table1") };
750
$dbi->execute($create_table1);
751
$dbi->update_timestamp(
752
    [$key1, $key2] => sub { '5' }
753
);
754
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
755
$dbi->update_all(table => $table1, timestamp => 1);
756
$result = $dbi->execute("select * from $table1");
757
$rows   = $result->all;
758
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
759

            
760
eval { $dbi->execute("drop table $table1") };
761
$dbi->execute($create_table1);
762
$dbi->update_timestamp(
763
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
764
);
765
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
766
$dbi->update_all(table => $table1, timestamp => 1);
767
$result = $dbi->execute("select * from $table1");
768
$rows   = $result->all;
769
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
770

            
test cleanup
Yuki Kimoto authored on 2011-08-10
771
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
772
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
773
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
774
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
775
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
776
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
777
$dbi->update_all(table => $table1, param => {$key2 => 10}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
778
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
779
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
780
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
781
                  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
782
                  "filter");
783

            
784

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
795
$dbi->execute("delete from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
796
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
797
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
798
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
799
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
800
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
801
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
802
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
803

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
806
$dbi->delete_all(table => $table1);
807
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
808
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
809
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
810
$rows = $dbi->select(table => $table1)->all;
811
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
812

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
824
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
825
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
826
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
827
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
828
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
829
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
830
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
831
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
832
        {ke1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
833
    ]
834
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
835
$result = $dbi->select(table => $table1);
836
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
837

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
838
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
839
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
840
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
841
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
842
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
843
$rows   = $result->all;
844
is_deeply($rows, [], "basic");
845

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
855
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
856
$dbi = DBIx::Custom->connect;
857
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
858
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
859
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
860
$dbi->insert(table => 'table', param => {select => 1});
861
$dbi->delete(table => 'table', where => {select => 1});
862
$result = $dbi->execute("select * from ${q}table$p");
863
$rows   = $result->all;
864
is_deeply($rows, [], "reserved word");
865

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

            
876

            
877
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
878
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
879
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
880
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
881
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
882
$rows = $dbi->select(table => $table1)->all;
883
is_deeply($rows, [{$key1 => 1, $key2 => 2},
884
                  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
885

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
900
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
901
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
902
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
test cleanup
Yuki Kimoto authored on 2011-08-10
903
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
904
    table => [$table1, $table2],
905
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
906
    where   => {"$table1.$key2" => 2},
907
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
908
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
909
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
910

            
911
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
912
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
913
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
914
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
915
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
916
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
917

            
918
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
919
eval { $dbi->execute("drop table ${q}table$p") };
920
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
921
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
922
$dbi->insert(table => 'table', param => {select => 1, update => 2});
923
$result = $dbi->select(table => 'table', where => {select => 1});
924
$rows   = $result->all;
925
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
926

            
927
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
928
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
929
$dbi->register_filter(
930
    twice       => sub { $_[0] * 2 },
931
    three_times => sub { $_[0] * 3 }
932
);
933
$dbi->default_fetch_filter('twice');
934
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
935
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
936
$result = $dbi->select(table => $table1);
937
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
938
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
939
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
940

            
941
test 'filters';
942
$dbi = DBIx::Custom->new;
943

            
944
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
945
   'あ', "decode_utf8");
946

            
947
is($dbi->filters->{encode_utf8}->('あ'),
948
   encode_utf8('あ'), "encode_utf8");
949

            
cleanup test
Yuki Kimoto authored on 2011-08-10
950
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
951
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
952
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
953
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
954
$dbi->begin_work;
955
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
956
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
957
$dbi->rollback;
958
$dbi->dbh->{AutoCommit} = 1;
959

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

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

            
964
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
965
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
966
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
967
$dbi->begin_work;
968
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
969
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
970
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
971
$dbi->commit;
972
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
973
$result = $dbi->select(table => $table1);
974
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
975
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
976

            
977
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
978
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
979
$dbi->execute($create_table1);
980
{
981
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
982
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
983
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
984
    like($@, qr/\.t /, "fail : not verbose");
985
}
986
{
987
    local $Carp::Verbose = 1;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
988
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
989
    like($@, qr/Custom.*\.t /s, "fail : verbose");
990
}
991

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

            
997
{
998
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
999
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1000
    like($@, qr/\Q.t /, "caller spec : not vebose");
1001
}
1002
{
1003
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1004
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1005
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1006
}
1007

            
1008

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1009
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1010
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1011
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1012
$dbi->execute($create_table1);
1013

            
1014
$dbi->begin_work;
1015

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

            
1022
$dbi->rollback if $@;
1023

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

            
1028
$dbi->begin_work;
1029

            
1030
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1031
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1032
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1033
};
1034

            
1035
$dbi->commit unless $@;
1036

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

            
1041
$dbi->dbh->{AutoCommit} = 0;
1042
eval{ $dbi->begin_work };
1043
ok($@, "exception");
1044
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1045

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1046
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1047
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1048
$dbi->cache(1);
1049
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1050
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1051
$dbi->execute($source, {}, query => 1);
1052
is_deeply($dbi->{_cached}->{$source}, 
cleanup test
Yuki Kimoto authored on 2011-08-15
1053
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1054

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1055
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1056
$dbi->execute($create_table1);
1057
$dbi->{_cached} = {};
1058
$dbi->cache(0);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1059
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1060
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1061

            
1062
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1063
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1064
$dbi->execute($create_table1);
1065
{
1066
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1067
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1068
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1069
    like($@, qr/\.t /, "fail : not verbose");
1070
}
1071
{
1072
    local $Carp::Verbose = 1;
- removed argument checking ...
Yuki Kimoto authored on 2011-10-21
1073
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1074
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1075
}
1076

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

            
1082
{
1083
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1084
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1085
    like($@, qr/\Q.t /, "caller spec : not vebose");
1086
}
1087
{
1088
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1089
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1090
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1091
}
1092

            
1093
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1094
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1095
    one => sub { 1 }
1096
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1097
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1098
    two => sub { 2 }
1099
);
1100
$dbi->method({
1101
    twice => sub {
1102
        my $self = shift;
1103
        return $_[0] * 2;
1104
    }
1105
});
1106

            
1107
is($dbi->one, 1, "first");
1108
is($dbi->two, 2, "second");
1109
is($dbi->twice(5), 10 , "second");
1110

            
1111
eval {$dbi->XXXXXX};
1112
ok($@, "not exists");
1113

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

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

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

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

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

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

            
1200
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1201
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1202
$dbi->execute($create_table1);
1203
$dbi->register_filter(twice => sub { $_[0] * 2 });
1204
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1205
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1206
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1207
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1208
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1209
                        param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1210
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1211
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1212

            
1213
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1214
eval { $dbi->execute("drop table $table1") };
1215
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1216
$dbi->execute($create_table1);
1217
$dbi->execute($create_table2);
1218
$dbi->register_filter(twice => sub { $_[0] * 2 });
1219
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1220
$dbi->apply_filter(
cleanup test
Yuki Kimoto authored on 2011-08-15
1221
    $table1, $key2 => {out => 'twice', in => 'twice'}
1222
);
1223
$dbi->apply_filter(
1224
    $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1225
);
cleanup test
Yuki Kimoto authored on 2011-08-15
1226
$dbi->insert(table => $table1, param => {$key1 => 5, $key2 => 2}, filter => {$key2 => undef});
1227
$dbi->insert(table => $table2, param => {$key1 => 5, $key3 => 6}, filter => {$key3 => undef});
1228
$result = $dbi->select(
1229
     table => [$table1, $table2],
1230
     column => [$key2, $key3],
1231
     where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1232

            
1233
$result->filter({$key2 => 'twice'});
1234
$rows   = $result->all;
1235
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1236

            
1237
$result = $dbi->select(
1238
     table => [$table1, $table2],
1239
     column => [$key2, $key3],
1240
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1241

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1260
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1261
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1262
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1263
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1264
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1265

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

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

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

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

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

            
1314
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1315
$dbi->apply_filter($table1,
1316
    $key1 => {end => sub { $_[0] * 3 } },
1317
    $key2 => {end => 'five_times'}
1318
);
1319
$result = $dbi->select(table => $table1);
1320
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1321
$result->filter($key1 => undef);
1322
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1323
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1324
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1325

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1326
test 'remove_end_filter and remove_filter';
1327
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1328
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1329
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1330
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1331
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1332
$row = $result
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1333
       ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1334
       ->remove_filter
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1335
       ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1336
       ->remove_end_filter
1337
       ->fetch_first;
1338
is_deeply($row, [1, 2]);
1339

            
1340
test 'empty where select';
1341
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1342
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1343
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1344
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1345
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1346
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1347
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1348

            
1349
test 'select query option';
1350
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1351
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1352
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1353
$query = $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1354
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1355
$query = $dbi->update(table => $table1, where => {$key1 => 1}, param => {$key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1356
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1357
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1358
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1359
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1360
is(ref $query, 'DBIx::Custom::Query');
1361

            
1362
test 'where';
1363
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1364
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1365
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1366
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1367
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1368
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1369
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1370

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

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

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

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

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

            
1412
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1413
             ->clause(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"])
1414
             ->param({$key1 => [0, 3], $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1415
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1416
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1417
    where => $where,
1418
); 
1419
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1420
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1421

            
1422
$where = $dbi->where;
1423
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1424
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1425
    where => $where
1426
);
1427
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1428
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1429

            
1430
eval {
1431
$where = $dbi->where
1432
             ->clause(['uuu']);
1433
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1434
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1435
    where => $where
1436
);
1437
};
1438
ok($@);
1439

            
1440
$where = $dbi->where;
1441
is("$where", '');
1442

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

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

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

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

            
1483
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1484
             ->clause("$key1 = :$key1 $key2 = :$key2")
1485
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1486
eval{$where->to_string};
1487
like($@, qr/one column/);
1488

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

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

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

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

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

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

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

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

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

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

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

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

            
1609
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1610
             ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1611
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1612
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1613
    where => $where,
1614
);
1615
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1616
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1617

            
1618
eval {$dbi->where(ppp => 1) };
1619
like($@, qr/invalid/);
1620

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

            
1632

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

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

            
1651
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1652
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1653
$where->param({$key1 => [undef, undef]});
1654
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1655
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1656
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1657
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1658
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1659
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1660

            
1661
test 'register_tag_processor';
1662
$dbi = DBIx::Custom->connect;
1663
$dbi->register_tag_processor(
1664
    a => sub { 1 }
1665
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1666
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1667

            
1668
test 'register_tag';
1669
$dbi = DBIx::Custom->connect;
1670
$dbi->register_tag(
1671
    b => sub { 2 }
1672
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1673
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1674

            
1675
test 'table not specify exception';
1676
$dbi = DBIx::Custom->connect;
1677
eval {$dbi->select};
1678
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1679

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1680
test 'more tests';
1681
$dbi = DBIx::Custom->connect;
1682
eval{$dbi->apply_filter('table', 'column', [])};
1683
like($@, qr/apply_filter/);
1684

            
1685
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1686
like($@, qr/apply_filter/);
1687

            
1688
$dbi->apply_filter(
1689

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

            
1701
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1702
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1703
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1704
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1705
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1706
$dbi->apply_filter($table1, $key2, {});
1707
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1708
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1709

            
1710
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1711
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1712
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1713
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1714
like($@, qr/not registered/);
1715
$dbi->method({one => sub { 1 }});
1716
is($dbi->one, 1);
1717

            
1718
eval{DBIx::Custom->connect(dsn => undef)};
1719
like($@, qr/_connect/);
1720

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

            
1733
$dbi->register_filter(one => sub { });
1734
$dbi->default_fetch_filter('one');
1735
ok($dbi->default_fetch_filter);
1736
$dbi->default_bind_filter('one');
1737
ok($dbi->default_bind_filter);
1738
eval{$dbi->default_fetch_filter('no')};
1739
like($@, qr/not registered/);
1740
eval{$dbi->default_bind_filter('no')};
1741
like($@, qr/not registered/);
1742
$dbi->default_bind_filter(undef);
1743
ok(!defined $dbi->default_bind_filter);
1744
$dbi->default_fetch_filter(undef);
1745
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1746
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1747
like($@, qr/Tag not finished/);
1748

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

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1763
test 'option';
1764
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
1765
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
1766
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
1767
ok($dbi->dbh->{PrintError});
1768
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
1769
ok($dbi->dbh->{PrintError});
1770

            
1771
test 'DBIx::Custom::Result stash()';
1772
$result = DBIx::Custom::Result->new;
1773
is_deeply($result->stash, {}, 'default');
1774
$result->stash->{foo} = 1;
1775
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
1776

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1777
test 'delete_at';
1778
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1779
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1780
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1781
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1782
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1783
    table => $table1,
1784
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1785
    where => [1, 2],
1786
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1787
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1788

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1789
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1790
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1791
    table => $table1,
1792
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1793
    where => 1,
1794
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1795
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1796

            
1797
test 'insert_at';
1798
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1799
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1800
$dbi->execute($create_table1_2);
1801
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1802
    primary_key => [$key1, $key2], 
1803
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1804
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1805
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1806
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1807
is($dbi->select(table => $table1)->one->{$key1}, 1);
1808
is($dbi->select(table => $table1)->one->{$key2}, 2);
1809
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1810

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1811
$dbi->delete_all(table => $table1);
1812
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1813
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1814
    primary_key => $key1, 
1815
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1816
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1817
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1818
);
1819

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

            
1824
eval {
1825
    $dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1826
        table => $table1,
1827
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1828
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1829
        param => {$key1 => 1, $key2 => 2, $key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
1830
    );
1831
};
1832
like($@, qr/must be/);
1833

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1862
$dbi->delete_all(table => $table1);
1863
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1864
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1865
    table => $table1,
1866
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1867
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1868
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
1869
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1870
is($dbi->select(table => $table1)->one->{$key1}, 1);
1871
is($dbi->select(table => $table1)->one->{$key2}, 2);
1872
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1873

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

            
1888
test 'select_at';
1889
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1890
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1891
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1892
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1893
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1894
    table => $table1,
1895
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1896
    where => [1, 2]
1897
);
1898
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1899
is($row->{$key1}, 1);
1900
is($row->{$key2}, 2);
1901
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1902

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1915
$dbi->delete_all(table => $table1);
1916
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1917
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1918
    table => $table1,
1919
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1920
    where => [1, 2]
1921
);
1922
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1923
is($row->{$key1}, 1);
1924
is($row->{$key2}, 2);
1925
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1926

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

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

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

            
1955
eval {
1956
    $result = $dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1957
        table => $table1,
1958
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1959
        where => {},
1960
    );
1961
};
1962
like($@, qr/must be/);
1963

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

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

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

            
2011
test 'model select_at';
2012
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2013
eval { $dbi->execute("drop table $table1") };
cleanup test
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
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2016
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2017
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2018
is($row->{$key1}, 1);
2019
is($row->{$key2}, 2);
2020
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2021

            
2022

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

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

            
2055
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2056
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2057
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2058
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2059
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2060
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2061
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2062
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2063
$dbi->execute($sql, param => $param, table => $table1);
2064
is($dbi->select(table => $table1)->one->{$key1}, 1);
2065
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2066

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

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

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

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

            
2116
$result = $model->select_at(
2117
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2118
        $model->mycolumn([$key1]),
2119
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2120
    ]
2121
);
2122
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2123
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2124

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2125
test 'merge_param';
2126
$dbi = DBIx::Custom->new;
2127
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2128
    {$key1 => 1, $key2 => 2, $key3 => 3},
2129
    {$key1 => 1, $key2 => 2},
2130
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2131
];
2132
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2133
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2134

            
2135
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2136
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2137
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2138
];
2139
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2140
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
2141

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
2162
$rows = $dbi->select(
2163
    table => $table1,
2164
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2165
    where   => {"$table1.$key2" => 3},
2166
    join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2167
             " $table2 on $table1.$key1 = $table2.$key1",
2168
    param => {"$table2.$key3" => 5}
2169
)->all;
2170
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2171

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
2199
$dbi = DBIx::Custom->connect;
2200
eval { $dbi->execute("drop table $table1") };
2201
$dbi->execute($create_table1);
2202
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2203
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
2204
$rows = $dbi->select(
2205
    table => $table1,
2206
    where => [
2207
        "$key1 = :$key1 and $key2 = :$key2",
2208
        {$key1 => 1, $key2 => 2}
2209
    ]
2210
)->all;
2211
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2212

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

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

            
2242

            
2243
test 'update() string where';
2244
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2245
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2246
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2247
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2248
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2249
    table => $table1,
2250
    param => {$key1 => 5},
2251
    where => "$key1 = :$key1 and $key2 = :$key2",
2252
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2253
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2254
$rows = $dbi->select(table => $table1)->all;
2255
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2256

            
2257
$dbi = DBIx::Custom->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);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2260
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2261
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2262
    table => $table1,
2263
    param => {$key1 => 5},
cleanup test
Yuki Kimoto authored on 2011-08-10
2264
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2265
        "$key1 = :$key1 and $key2 = :$key2",
2266
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2267
    ]
2268
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2269
$rows = $dbi->select(table => $table1)->all;
2270
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2271

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2286
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2287
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2288
    primary_key => $key1, 
2289
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2290
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2291
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2292
);
2293

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

            
2298
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2299
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2300
$dbi->execute($create_table1_2);
2301
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2302
    {$key3 => 3},
2303
    primary_key => [$key1, $key2], 
2304
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2305
    id => [1, 2],
2306
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2307
is($dbi->select(table => $table1)->one->{$key1}, 1);
2308
is($dbi->select(table => $table1)->one->{$key2}, 2);
2309
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2310

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2353
$dbi->delete_all(table => $table1);
2354
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2355
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2356
    table => $table1,
2357
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2358
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2359
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2360
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2361
is($dbi->select(table => $table1)->one->{$key1}, 0);
2362
is($dbi->select(table => $table1)->one->{$key2}, 2);
2363
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2364

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

            
2379

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

            
2395

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2408
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2409
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2410
    table => $table1,
2411
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2412
    id => 0,
2413
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2414
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2415

            
2416

            
2417
test 'model delete and id option';
2418
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2419
eval { $dbi->execute("drop table $table1") };
2420
eval { $dbi->execute("drop table $table2") };
2421
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2422
$dbi->execute($create_table1_2);
2423
$dbi->execute($create_table2_2);
2424
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2425
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2426
$dbi->model($table1)->delete(id => [1, 2]);
2427
is_deeply($dbi->select(table => $table1)->all, []);
2428
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2429
$dbi->model($table1)->delete(id => [1, 2]);
2430
is_deeply($dbi->select(table => $table1)->all, []);
2431
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2432
$dbi->model($table3)->delete(id => [1, 2]);
2433
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2434

            
2435

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2451
$dbi->delete_all(table => $table1);
2452
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2453
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2454
    table => $table1,
2455
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2456
    id => 0,
2457
);
2458
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2459
is($row->{$key1}, 0);
2460
is($row->{$key2}, 2);
2461
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2462

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2463
$dbi->delete_all(table => $table1);
2464
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2465
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2466
    table => $table1,
2467
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2468
    id => [1, 2]
2469
);
2470
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2471
is($row->{$key1}, 1);
2472
is($row->{$key2}, 2);
2473
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2474

            
2475

            
2476
test 'model select_at';
2477
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2478
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2479
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2480
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2481
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2482
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2483
is($row->{$key1}, 1);
2484
is($row->{$key2}, 2);
2485
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2486

            
2487
test 'column separator is default .';
2488
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2489
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2490
eval { $dbi->execute("drop table $table1") };
2491
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2492
$dbi->execute($create_table1);
2493
$dbi->execute($create_table2);
2494
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2495
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2496
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2497
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2498
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2499
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2500
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2501
);
2502
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2503
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2504

            
2505
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2506
    column => [$model->column($table2 => [$key1, $key3])],
2507
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2508
);
2509
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2510
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2511

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2512
test 'separator';
2513
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2514
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2515
eval { $dbi->execute("drop table $table1") };
2516
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2517
$dbi->execute($create_table1);
2518
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2519

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2520
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2521
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2522
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2523
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2524
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2525
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2526
);
2527
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2528
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2529
);
2530
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2531
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2532
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2533
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2534
$result = $model->select(
2535
    column => [
2536
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2537
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2538
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2539
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2540
);
2541
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2542
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2543
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2544

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2545
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2546
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2547
$result = $model->select(
2548
    column => [
2549
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2550
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2551
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2552
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2553
);
2554
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2555
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
2556
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2557

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2558
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2559
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2560
$result = $model->select(
2561
    column => [
2562
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2563
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2564
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2565
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2566
);
2567
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2568
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2569
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2570

            
2571

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2572
test 'filter_off';
2573
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2574
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2575
eval { $dbi->execute("drop table $table1") };
2576
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2577
$dbi->execute($create_table1);
2578
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2579

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2580
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2581
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2582
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2583
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2584
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2585
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2586
);
2587
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2588
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2589
$model = $dbi->model($table1);
2590
$result = $model->select(column => $key1);
2591
$result->filter($key1 => sub { $_[0] * 2 });
2592
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2593

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2594
test 'available_datetype';
2595
$dbi = DBIx::Custom->connect;
2596
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2597

            
2598

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2599
test 'select prefix option';
2600
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2601
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2602
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2603
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2604
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2605
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2606

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

            
added tests
Yuki Kimoto authored on 2011-08-26
2608
test 'mapper';
2609
$dbi = DBIx::Custom->connect;
2610
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2611
    id => {key => "$table1.id"},
2612
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2613
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
2614
);
2615
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2616
  "$table1.price" => 1900});
2617

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2618
$dbi = DBIx::Custom->connect;
2619
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2620
    id => {key => "$table1.id"},
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2621
    author => ["$table1.author" => $dbi->like_value],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2622
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2623
);
2624
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2625
  "$table1.price" => 1900});
2626

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

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

            
2641
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2642
    id => {key => "$table1.id"},
2643
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2644
);
2645
is_deeply($param, {"$table1.price" => undef});
2646

            
2647
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2648
    id => {key => "$table1.id", condition => 'exists'},
2649
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
2650
);
2651
is_deeply($param, {"$table1.price" => '%a'});
2652

            
2653
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2654
    id => {key => "$table1.id"},
added tests
Yuki Kimoto authored on 2011-08-26
2655
    price => ["$table1.price", sub { '%' . $_[0] }]
2656
);
2657
is_deeply($param, {"$table1.price" => '%a'});
2658

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2659
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2660
    price => sub { '%' . $_[0] },
2661
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2662
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2663
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2664

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2665
eval { $dbi->execute("drop table $table1") };
2666
$dbi->execute($create_table1);
2667
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2668
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
2669

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

            
2678
$where = $dbi->where;
2679
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2680
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
2681
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2682
$row = $result->all;
2683
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2684
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2685
$row = $result->all;
2686
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2687

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

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2700
$where = $dbi->where;
2701
$where->clause(['and', ":${key1}{=}"]);
2702
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
2703
  ->pass([$key1, $key2])->map;
2704
$where->param($param);
2705
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2706
$row = $result->all;
2707
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2708

            
2709
$where = $dbi->where;
2710
$where->clause(['and', ":${key1}{=}"]);
2711
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
2712
$where->param($param);
2713
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2714
$row = $result->all;
2715
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2716

            
2717
$where = $dbi->where;
2718
$where->clause(['and', ":${key1}{=}"]);
2719
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
2720
  ->pass([$key1, $key2])->map;
2721
$where->param($param);
2722
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2723
$row = $result->all;
2724
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2725

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2727
$where = $dbi->where;
2728
$where->clause(['and', ":${key1}{=}"]);
2729
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
2730
$where->param($param);
2731
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2732
$row = $result->all;
2733
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2734

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

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

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

            
2763
$where = $dbi->where;
2764
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2765
    id => {key => "$table1.id"},
2766
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2767
);
2768
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
2769

            
2770
$where = $dbi->where;
2771
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2772
    id => {key => "$table1.id", condition => 'exists'},
2773
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2774
);
2775
is_deeply($param, {"$table1.price" => '%a'});
2776

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

            
2786
$where = $dbi->where;
2787
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900}, condition => 'length')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2788
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2789
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2790
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2791
);
2792
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2793
  "$table1.price" => 1900});
2794

            
2795
$where = $dbi->where;
2796
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2797
    id => {key => "$table1.id", condition => 'length'},
2798
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
2799
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2800
);
2801
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2802
  "$table1.price" => 1900});
2803

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2809
test 'order';
2810
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2811
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2812
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2813
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2814
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
2815
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
2816
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2817
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2818
$order->prepend($key1, "$key2 desc");
2819
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2820
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
2821
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2822
$order->prepend("$key1 desc");
2823
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2824
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
2825
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2826

            
2827
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2828
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2829
$result = $dbi->select(table => $table1,
2830
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2831
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2832
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
2833
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
2834
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
2835
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2836

            
2837
test 'tag_parse';
2838
$dbi = DBIx::Custom->connect;
2839
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2840
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2841
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2842
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2843
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2844
ok($@);
2845

            
2846
test 'last_sql';
2847
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2848
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2849
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2850
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
2851
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2852

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2884
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
2885
$result = $dbi->execute(
2886
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2887
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2888
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
2889
);
2890
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2891
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2892

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

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2914
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2915
$dbi->execute($create_table1_highperformance);
2916
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2917
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2918
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2919
];
2920
{
2921
    my $query;
2922
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
2923
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2924
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2925
      $sth ||= $query->sth;
2926
      $sth->execute(map { $row->{$_} } sort keys %$row);
2927
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2928
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2929
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2930
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2931
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2932
      ]
2933
    );
2934
}
2935

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2936
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2937
$dbi->execute($create_table1_highperformance);
2938
$rows = [
2939
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
2940
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
2941
];
2942
{
2943
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
2944
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
2945
    for my $row (@$rows) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2946
      $query ||= $model->insert($row, query => 1);
2947
      $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2948
    }
2949
    is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
2950
      [
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2951
          {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
2952
          {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2953
      ]
2954
    );
2955
}
2956

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2957
test 'id option more';
2958
eval { $dbi->execute("drop table $table1") };
2959
$dbi->execute($create_table1_highperformance);
2960
$row = {
2961
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
2962
};
2963
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2964
$model->insert($row);
2965
$query = $model->update({$key7 => 11}, id => 1, query => 1);
2966
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
2967
is_deeply($dbi->select(table => $table1)->one,
2968
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
2969
);
2970

            
2971
eval { $dbi->execute("drop table $table1") };
2972
eval { $dbi->execute("drop table $table2") };
2973
$dbi->execute($create_table1);
2974
$dbi->execute($create_table2);
2975
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2976
$model->insert({$key1 => 1, $key2 => 2});
2977
$model = $dbi->create_model(table => $table2, primary_key => $key1,
2978
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
2979
$model->insert({$key1 => 1, $key3 => 3});
2980
$result = $model->select(
2981
    column => {$table1 => ["$key2"]},
2982
    id => 1
2983
);
2984
is_deeply($result->all, [{"$table1.$key2" => 2}]);
2985

            
2986
eval { $dbi->execute("drop table $table1") };
2987
$dbi->execute($create_table1_highperformance);
2988
$row = {
2989
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
2990
};
2991
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2992
$model->insert($row);
2993
$query = $model->delete(id => 1, query => 1);
2994
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
2995
is_deeply($dbi->select(table => $table1)->all, []);
2996

            
2997
eval { $dbi->execute("drop table $table1") };
2998
eval { $dbi->execute($create_table1_highperformance) };
2999
$row = {
3000
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3001
};
3002
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3003
$model->insert($row);
3004
$query = $model->select(id => 1, query => 1);
3005
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3006
is_deeply($dbi->select(table => $table1)->one,
3007
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3008
);
3009

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3017
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3018
@rows = ();
3019
while (my $row = $result->fetch) {
3020
    push @rows, [@$row];
3021
}
3022
is_deeply(\@rows, [[1, 2], [3, 4]]);
3023

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3024
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3025
@rows = ();
3026
while (my $row = $result->fetch_hash) {
3027
    push @rows, {%$row};
3028
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3029
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3030

            
3031
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3032
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3033
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3034
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3035
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3036

            
3037
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3038
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3039
$rows = $result->fetch_all;
3040
is_deeply($rows, [[1, 2], [3, 4]]);
3041

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

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

            
3050
$rows = $result->fetch_all;
3051
is_deeply($rows, [[3, 2], [9, 4]], "array");
3052

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

            
3059
test "query_builder";
3060
$datas = [
3061
    # Basic tests
3062
    {   name            => 'placeholder basic',
3063
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3064
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3065
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3066
    },
3067
    {
3068
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3069
        source            => "{in k1 3}",
3070
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3071
        columns_expected   => [qw/k1 k1 k1/]
3072
    },
3073
    
3074
    # Table name
3075
    {
3076
        name            => 'placeholder with table name',
3077
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3078
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3079
        columns_expected  => [qw/a.k1 a.k2/]
3080
    },
3081
    {   
3082
        name            => 'placeholder in with table name',
3083
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3084
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3085
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3086
    },
3087
    {
3088
        name            => 'not contain tag',
3089
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3090
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3091
        columns_expected  => [],
3092
    }
3093
];
3094

            
3095
for (my $i = 0; $i < @$datas; $i++) {
3096
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3097
    my $dbi = DBIx::Custom->new;
3098
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3099
    my $query = $builder->build_query($data->{source});
3100
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3101
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3102
}
3103

            
cleanup
Yuki Kimoto authored on 2011-08-13
3104
$dbi = DBIx::Custom->new;
3105
$builder = $dbi->query_builder;
3106
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3107
    p => sub {
3108
        my @args = @_;
3109
        
3110
        my $expand    = "? $args[0] $args[1]";
3111
        my $columns = [2];
3112
        return [$expand, $columns];
3113
    }
3114
);
3115

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3126
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3127
    q => 'string'
3128
});
3129

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3133
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3134
   r => sub {} 
3135
});
3136

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3140
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3141
   s => sub { return ["a", ""]} 
3142
});
3143

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3147
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3148
    t => sub {return ["a", []]}
3149
);
3150

            
3151

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

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

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

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

            
3167
test 'variouse source';
3168
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3169
$query = $builder->build_query($source);
3170
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3171

            
3172
$source = "abc";
3173
$query = $builder->build_query($source);
3174
is($query->sql, 'abc', "basic : 2");
3175

            
3176
$source = "{= a}";
3177
$query = $builder->build_query($source);
3178
is($query->sql, 'a = ?', "only tag");
3179

            
3180
$source = "000";
3181
$query = $builder->build_query($source);
3182
is($query->sql, '000', "contain 0 value");
3183

            
3184
$source = "a {= b} }";
3185
eval{$builder->build_query($source)};
3186
like($@, qr/unexpected "}"/, "error : 1");
3187

            
3188
$source = "a {= {}";
3189
eval{$builder->build_query($source)};
3190
like($@, qr/unexpected "{"/, "error : 2");
3191

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3210
test 'select() after_build_sql option';
3211
$dbi = DBIx::Custom->connect;
3212
$dbi->user_table_info($user_table_info);
3213
eval { $dbi->execute("drop table $table1") };
3214
$dbi->execute($create_table1);
3215
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3216
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3217
$rows = $dbi->select(
3218
    table => $table1,
3219
    column => $key1,
3220
    after_build_sql => sub {
3221
        my $sql = shift;
3222
        $sql = "select * from ( $sql ) t where $key1 = 1";
3223
        return $sql;
3224
    }
3225
)->all;
3226
is_deeply($rows, [{$key1 => 1}]);
3227

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3228
test 'dbi method from model';
3229
$dbi = MyDBI9->connect;
3230
eval { $dbi->execute("drop table $table1") };
3231
$dbi->execute($create_table1);
3232
$dbi->setup_model;
3233
$model = $dbi->model($table1);
3234
eval{$model->execute("select * from $table1")};
3235
ok(!$@);
3236

            
3237
test 'column table option';
3238
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3239
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3240
eval { $dbi->execute("drop table $table1") };
3241
$dbi->execute($create_table1);
3242
eval { $dbi->execute("drop table $table2") };
3243
$dbi->execute($create_table2);
3244
$dbi->setup_model;
3245
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3246
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3247
$model = $dbi->model($table1);
3248
$result = $model->select(
3249
    column => [
3250
        $model->column($table2, {alias => $table2_alias})
3251
    ],
3252
    where => {"$table2_alias.$key3" => 4}
3253
);
3254
is_deeply($result->one, 
3255
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3256

            
3257
$dbi->separator('__');
3258
$result = $model->select(
3259
    column => [
3260
        $model->column($table2, {alias => $table2_alias})
3261
    ],
3262
    where => {"$table2_alias.$key3" => 4}
3263
);
3264
is_deeply($result->one, 
3265
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3266

            
3267
$dbi->separator('-');
3268
$result = $model->select(
3269
    column => [
3270
        $model->column($table2, {alias => $table2_alias})
3271
    ],
3272
    where => {"$table2_alias.$key3" => 4}
3273
);
3274
is_deeply($result->one, 
3275
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3276

            
3277
test 'create_model';
3278
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3279
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3280
eval { $dbi->execute("drop table $table1") };
3281
eval { $dbi->execute("drop table $table2") };
3282
$dbi->execute($create_table1);
3283
$dbi->execute($create_table2);
3284

            
3285
$dbi->create_model(
3286
    table => $table1,
3287
    join => [
3288
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3289
    ],
3290
    primary_key => [$key1]
3291
);
3292
$model2 = $dbi->create_model(
3293
    table => $table2
3294
);
3295
$dbi->create_model(
3296
    table => $table3,
3297
    filter => [
3298
        $key1 => {in => sub { uc $_[0] }}
3299
    ]
3300
);
3301
$dbi->setup_model;
3302
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3303
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3304
$model = $dbi->model($table1);
3305
$result = $model->select(
3306
    column => [$model->mycolumn, $model->column($table2)],
3307
    where => {"$table1.$key1" => 1}
3308
);
3309
is_deeply($result->one,
3310
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3311
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3312

            
3313
test 'model method';
3314
$dbi = DBIx::Custom->connect;
3315
eval { $dbi->execute("drop table $table2") };
3316
$dbi->execute($create_table2);
3317
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3318
$model = $dbi->create_model(
3319
    table => $table2
3320
);
3321
$model->method(foo => sub { shift->select(@_) });
3322
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3323

            
3324
test 'model helper';
3325
$dbi = DBIx::Custom->connect;
3326
eval { $dbi->execute("drop table $table2") };
3327
$dbi->execute($create_table2);
3328
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3329
$model = $dbi->create_model(
3330
    table => $table2
3331
);
3332
$model->helper(foo => sub { shift->select(@_) });
3333
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3334

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3335
test 'assign_clause';
cleanup test
Yuki Kimoto authored on 2011-08-15
3336
$dbi = DBIx::Custom->connect;
3337
eval { $dbi->execute("drop table $table1") };
3338
$dbi->execute($create_table1_2);
3339
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3340
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3341

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

            
3355

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

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

            
3375
$dbi = DBIx::Custom->connect;
3376
eval { $dbi->execute("drop table $table1") };
3377
$dbi->execute($create_table1_2);
3378
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3379
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3380

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

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

            
3398
$dbi = DBIx::Custom->connect;
3399
eval { $dbi->execute("drop table $table1") };
3400
$dbi->execute($create_table1_2);
3401
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3402
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3403

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

            
3417
$param = {$key2 => 11};
3418
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3419
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3420
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3421
where $key1 = 1
3422
EOS
3423
$dbi->execute($sql, param => $param, table => $table1);
3424
$result = $dbi->execute("select * from $table1 order by $key1");
3425
$rows   = $result->all;
3426
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3427
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3428
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3429

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3430
test 'Model class';
3431
$dbi = MyDBI1->connect;
3432
eval { $dbi->execute("drop table $table1") };
3433
$dbi->execute($create_table1);
3434
$model = $dbi->model($table1);
3435
$model->insert({$key1 => 'a', $key2 => 'b'});
3436
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3437
eval { $dbi->execute("drop table $table2") };
3438
$dbi->execute($create_table2);
3439
$model = $dbi->model($table2);
3440
$model->insert({$key1 => 'a'});
3441
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3442
is($dbi->models->{$table1}, $dbi->model($table1));
3443
is($dbi->models->{$table2}, $dbi->model($table2));
3444

            
3445
$dbi = MyDBI4->connect;
3446
eval { $dbi->execute("drop table $table1") };
3447
$dbi->execute($create_table1);
3448
$model = $dbi->model($table1);
3449
$model->insert({$key1 => 'a', $key2 => 'b'});
3450
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3451
eval { $dbi->execute("drop table $table2") };
3452
$dbi->execute($create_table2);
3453
$model = $dbi->model($table2);
3454
$model->insert({$key1 => 'a'});
3455
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3456

            
3457
$dbi = MyDBI5->connect;
3458
eval { $dbi->execute("drop table $table1") };
3459
eval { $dbi->execute("drop table $table2") };
3460
$dbi->execute($create_table1);
3461
$dbi->execute($create_table2);
3462
$model = $dbi->model($table2);
3463
$model->insert({$key1 => 'a'});
3464
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3465
$dbi->insert(table => $table1, param => {$key1 => 1});
3466
$model = $dbi->model($table1);
3467
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3468

            
3469
test 'primary_key';
3470
$dbi = MyDBI1->connect;
3471
$model = $dbi->model($table1);
3472
$model->primary_key([$key1, $key2]);
3473
is_deeply($model->primary_key, [$key1, $key2]);
3474

            
3475
test 'columns';
3476
$dbi = MyDBI1->connect;
3477
$model = $dbi->model($table1);
3478
$model->columns([$key1, $key2]);
3479
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3480

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3481
test 'setup_model';
3482
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3483
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3484
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3485
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3486

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3487
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3488
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3489
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3490
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3491
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3492

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3493
test 'each_column';
3494
$dbi = DBIx::Custom->connect;
3495
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3496
eval { $dbi->execute("drop table $table1") };
3497
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3498
eval { $dbi->execute("drop table $table3") };
3499
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3500
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3501

            
3502
$infos = [];
3503
$dbi->each_column(sub {
3504
    my ($self, $table, $column, $cinfo) = @_;
3505
    
3506
    if ($table =~ /^table\d/i) {
3507
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3508
         push @$infos, $info;
3509
    }
3510
});
3511
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3512
is_deeply($infos, 
3513
    [
3514
        [$table1, $key1, $key1],
3515
        [$table1, $key2, $key2],
3516
        [$table2, $key1, $key1],
3517
        [$table2, $key3, $key3]
3518
    ]
3519
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3520
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3521

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3529
$infos = [];
3530
$dbi->each_table(sub {
3531
    my ($self, $table, $table_info) = @_;
3532
    
3533
    if ($table =~ /^table\d/i) {
3534
         my $info = [$table, $table_info->{TABLE_NAME}];
3535
         push @$infos, $info;
3536
    }
3537
});
3538
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3539
is_deeply($infos, 
3540
    [
3541
        [$table1, $table1],
3542
        [$table2, $table2],
3543
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3544
);
3545

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

            
3552
$infos = [];
3553
$dbi->user_table_info($user_table_info);
3554
$dbi->each_table(sub {
3555
    my ($self, $table, $table_info) = @_;
3556
    
3557
    if ($table =~ /^table\d/i) {
3558
         my $info = [$table, $table_info->{TABLE_NAME}];
3559
         push @$infos, $info;
3560
    }
3561
});
3562
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3563
is_deeply($infos, 
3564
    [
3565
        [$table1, $table1],
3566
        [$table2, $table2],
3567
        [$table3, $table3],
3568
    ]
3569
);
3570

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3571
test 'type_rule into';
3572
eval { $dbi->execute("drop table $table1") };
3573
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3574
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3575

            
3576

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3577
$dbi = DBIx::Custom->connect;
3578
eval { $dbi->execute("drop table $table1") };
3579
$dbi->execute($create_table1_type);
3580

            
cleanup
Yuki Kimoto authored on 2011-08-16
3581
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3582
$dbi->type_rule(
3583
    into1 => {
3584
        $date_typename => sub { '2010-' . $_[0] }
3585
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3586
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3587
$dbi->insert({$key1 => '01-01'}, table => $table1);
3588
$result = $dbi->select(table => $table1);
3589
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3590

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

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

            
3632
$dbi = DBIx::Custom->connect;
3633
eval { $dbi->execute("drop table $table1") };
3634
$dbi->execute($create_table1_type);
3635
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3636
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3637
$dbi->type_rule(
3638
    into1 => [
3639
        [$date_typename, $datetime_typename] => sub {
3640
            my $value = shift;
3641
            $value =~ s/02/03/g;
3642
            return $value;
3643
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3644
    ]
3645
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3646
$result = $dbi->execute(
3647
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3648
    param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
3649
    table => $table1
3650
);
3651
$row = $result->one;
3652
like($row->{$key1}, qr/^2010-01-03/);
3653
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3654

            
3655
$dbi = DBIx::Custom->connect;
3656
eval { $dbi->execute("drop table $table1") };
3657
$dbi->execute($create_table1_type);
3658
$dbi->register_filter(convert => sub {
3659
    my $value = shift || '';
3660
    $value =~ s/02/03/;
3661
    return $value;
3662
});
cleanup
Yuki Kimoto authored on 2011-08-16
3663
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3664
$dbi->type_rule(
3665
    from1 => {
3666
        $date_datatype => 'convert',
3667
    },
3668
    into1 => {
3669
        $date_typename => 'convert',
3670
    }
3671
);
3672
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3673
$result = $dbi->select(table => $table1);
3674
like($result->fetch->[0], qr/^2010-03-03/);
3675

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

            
3701

            
3702
$dbi = DBIx::Custom->connect;
3703
eval { $dbi->execute("drop table $table1") };
3704
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3705
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3706
$dbi->type_rule(
3707
    from1 => {
3708
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3709
    },
3710
    from2 => {
3711
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3712
    },
3713
);
3714
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3715
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3716
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3717
$result->type_rule(
3718
    from1 => {
3719
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3720
    },
3721
    from2 => {
3722
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3723
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3724
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3725
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3726
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3727

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

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

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

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

            
3793
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3794
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3795
$dbi->execute($create_table1_type);
3796
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
3797
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3798
$dbi->type_rule(
3799
    into1 => {
3800
        $date_typename => 'ppp'
3801
    }
3802
);
3803
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3804
$result = $dbi->select(table => $table1);
3805
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3806

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3807
eval{$dbi->type_rule(
3808
    into1 => {
3809
        $date_typename => 'pp'
3810
    }
3811
)};
3812
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3813

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3814
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3815
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3816
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3817
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3818
    $dbi->type_rule(
3819
        from1 => {
3820
            Date => sub { $_[0] * 2 },
3821
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3822
    );
3823
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3824
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3825

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3826
eval {
3827
    $dbi->type_rule(
3828
        into1 => {
3829
            Date => sub { $_[0] * 2 },
3830
        }
3831
    );
3832
};
3833
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3834

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

            
3852
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3853
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3854
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3855
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3856
$dbi->type_rule(
3857
    from1 => {
3858
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3859
        $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3860
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3861
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3862
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3863
$result = $dbi->select(table => $table1);
3864
$result->type_rule(
3865
    from1 => {
3866
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3867
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3868
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3869
$row = $result->one;
3870
like($row->{$key1}, qr/^2010-01-05/);
3871
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3872

            
3873
$result = $dbi->select(table => $table1);
3874
$result->type_rule(
3875
    from1 => {
3876
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3877
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3878
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3879
$row = $result->one;
3880
like($row->{$key1}, qr/2010-01-05/);
3881
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3882

            
3883
$result = $dbi->select(table => $table1);
3884
$result->type_rule(
3885
    from1 => {
3886
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3887
    }
3888
);
3889
$row = $result->one;
3890
like($row->{$key1}, qr/2010-01-05/);
3891
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3892

            
3893
$result = $dbi->select(table => $table1);
3894
$result->type_rule(
3895
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
3896
);
3897
$row = $result->one;
3898
like($row->{$key1}, qr/2010-01-05/);
3899
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3900

            
3901
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
3902
$result = $dbi->select(table => $table1);
3903
$result->type_rule(
3904
    from1 => [$date_datatype => 'five']
3905
);
3906
$row = $result->one;
3907
like($row->{$key1}, qr/^2010-01-05/);
3908
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3909

            
3910
$result = $dbi->select(table => $table1);
3911
$result->type_rule(
3912
    from1 => [$date_datatype => undef]
3913
);
3914
$row = $result->one;
3915
like($row->{$key1}, qr/^2010-01-03/);
3916
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3917

            
3918
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3919
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3920
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3921
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3922
$dbi->type_rule(
3923
    from1 => {
3924
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3925
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3926
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3927
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3928
$result = $dbi->select(table => $table1);
3929
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3930
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3931

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3932
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3933
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3934
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3935
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3936
$dbi->type_rule(
3937
    from1 => {
3938
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3939
    },
3940
);
3941
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3942
$result = $dbi->select(table => $table1);
3943
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3944
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3945

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3994
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3995
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3996
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3997
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3998
$dbi->type_rule(
3999
    into1 => {
4000
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4001
    },
4002
    into2 => {
4003
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4004
    },
4005
    from1 => {
4006
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4007
    },
4008
    from2 => {
4009
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4010
    }
4011
);
4012
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4013
$result = $dbi->select(table => $table1);
4014
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
4015
$result = $dbi->select(table => $table1);
4016
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4017

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4018
test 'join';
4019
$dbi = DBIx::Custom->connect;
4020
eval { $dbi->execute("drop table $table1") };
4021
$dbi->execute($create_table1);
4022
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4023
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
4024
eval { $dbi->execute("drop table $table2") };
4025
$dbi->execute($create_table2);
4026
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4027
eval { $dbi->execute("drop table $table3") };
4028
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
4029
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
4030
$rows = $dbi->select(
4031
    table => $table1,
4032
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4033
    where   => {"$table1.$key2" => 2},
4034
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4035
)->all;
4036
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
4037

            
4038
$rows = $dbi->select(
4039
    table => $table1,
4040
    where   => {$key1 => 1},
4041
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4042
)->all;
4043
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4044

            
4045
$rows = $dbi->select(
4046
    table => $table1,
4047
    where   => {$key1 => 1},
4048
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4049
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4050
)->all;
4051
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4052

            
4053
$rows = $dbi->select(
4054
    column => "$table3.$key4 as ${table3}__$key4",
4055
    table => $table1,
4056
    where   => {"$table1.$key1" => 1},
4057
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4058
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4059
)->all;
4060
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4061

            
4062
$rows = $dbi->select(
4063
    column => "$table1.$key1 as ${table1}__$key1",
4064
    table => $table1,
4065
    where   => {"$table3.$key4" => 4},
4066
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4067
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4068
)->all;
4069
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4070

            
4071
$dbi = DBIx::Custom->connect;
4072
eval { $dbi->execute("drop table $table1") };
4073
$dbi->execute($create_table1);
4074
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4075
eval { $dbi->execute("drop table $table2") };
4076
$dbi->execute($create_table2);
4077
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4078
$rows = $dbi->select(
4079
    table => $table1,
4080
    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",
4081
    where   => {"$table1.$key2" => 2},
4082
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4083
)->all;
4084
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4085
          'quote');
4086

            
4087

            
4088
$dbi = DBIx::Custom->connect;
4089
eval { $dbi->execute("drop table $table1") };
4090
$dbi->execute($create_table1);
4091
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4092
$sql = <<"EOS";
4093
left outer join (
4094
  select * from $table1 t1
4095
  where t1.$key2 = (
4096
    select max(t2.$key2) from $table1 t2
4097
    where t1.$key1 = t2.$key1
4098
  )
4099
) $table3 on $table1.$key1 = $table3.$key1
4100
EOS
4101
$join = [$sql];
4102
$rows = $dbi->select(
4103
    table => $table1,
4104
    column => "$table3.$key1 as ${table3}__$key1",
4105
    join  => $join
4106
)->all;
4107
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4108

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

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

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4161
$dbi = DBIx::Custom->connect;
4162
eval { $dbi->execute("drop table $table1") };
4163
eval { $dbi->execute("drop table $table2") };
4164
$dbi->execute($create_table1);
4165
$dbi->execute($create_table2);
4166
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4167
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4168
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4169
$result = $dbi->select(
4170
    table => $table1,
4171
    column => [{$table2 => [$key3]}],
4172
    join => [
4173
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4174
    ]
4175
);
4176
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4177

            
4178
$dbi = DBIx::Custom->connect;
4179
eval { $dbi->execute("drop table $table1") };
4180
eval { $dbi->execute("drop table $table2") };
4181
$dbi->execute($create_table1);
4182
$dbi->execute($create_table2);
4183
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4184
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4185
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4186
$result = $dbi->select(
4187
    table => $table1,
4188
    column => [{$table2 => [$key3]}],
4189
    join => [
4190
        "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4191
    ]
4192
);
4193
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4194

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4195
test 'columns';
4196
$dbi = MyDBI1->connect;
4197
$model = $dbi->model($table1);
4198

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4199
test 'count';
4200
$dbi = DBIx::Custom->connect;
4201
eval { $dbi->execute("drop table $table1") };
4202
$dbi->execute($create_table1);
4203
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4204
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 3});
4205
is($dbi->count(table => $table1), 2);
4206
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4207
$model = $dbi->create_model(table => $table1);
4208
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4209

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