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

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

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

            
14
plan 'no_plan';
15

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

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

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

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

            
88
    use strict;
89
    use warnings;
90

            
91
    use base 'DBIx::Custom';
92

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

            
104
    package MyModel2::Base1;
105

            
106
    use strict;
107
    use warnings;
108

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

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

            
113
    use strict;
114
    use warnings;
115

            
116
    use base 'MyModel2::Base1';
117

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

            
124
    sub list { shift->select; }
125

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

            
128
    use strict;
129
    use warnings;
130

            
131
    use base 'MyModel2::Base1';
132

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

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

            
141
    package MyModel2::TABLE1;
142

            
143
    use strict;
144
    use warnings;
145

            
146
    use base 'MyModel2::Base1';
147

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

            
154
    sub list { shift->select; }
155

            
156
    package MyModel2::TABLE2;
157

            
158
    use strict;
159
    use warnings;
160

            
161
    use base 'MyModel2::Base1';
162

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

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

            
174
    use strict;
175
    use warnings;
176

            
177
    use base 'DBIx::Custom';
178

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
569

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
773

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

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

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

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

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

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

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

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

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

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

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

            
865

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

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

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

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

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

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

            
900
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
901
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
902
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
903
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
904
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
905
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], "relation : no exists where");
test cleanup
Yuki Kimoto authored on 2011-08-10
906

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

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

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

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

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

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

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

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

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

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

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

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

            
997

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

            
1003
$dbi->begin_work;
1004

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

            
1011
$dbi->rollback if $@;
1012

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

            
1017
$dbi->begin_work;
1018

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

            
1024
$dbi->commit unless $@;
1025

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1621

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

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

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

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

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

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

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

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

            
1677
$dbi->apply_filter(
1678

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2011

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
2151
$rows = $dbi->select(
2152
    table => $table1,
2153
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2154
    where   => {"$table1.$key2" => 3},
2155
    join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2156
             " $table2 on $table1.$key1 = $table2.$key1",
2157
    param => {"$table2.$key3" => 5}
2158
)->all;
2159
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2160

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
2188
$dbi = DBIx::Custom->connect;
2189
eval { $dbi->execute("drop table $table1") };
2190
$dbi->execute($create_table1);
2191
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2192
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
2193
$rows = $dbi->select(
2194
    table => $table1,
2195
    where => [
2196
        "$key1 = :$key1 and $key2 = :$key2",
2197
        {$key1 => 1, $key2 => 2}
2198
    ]
2199
)->all;
2200
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2201

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

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

            
2231

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2275
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2276
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2277
    primary_key => $key1, 
2278
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2279
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2280
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2281
);
2282

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2300
test 'model insert id and primary_key option';
2301
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2302
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2303
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2304
$dbi->model($table1)->insert(
cleanup test
Yuki Kimoto authored on 2011-08-10
2305
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2306
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2307
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2308
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2309
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2310
is($row->{$key1}, 1);
2311
is($row->{$key2}, 2);
2312
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2313

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2342
$dbi->delete_all(table => $table1);
2343
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2344
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2345
    table => $table1,
2346
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2347
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2348
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2349
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2350
is($dbi->select(table => $table1)->one->{$key1}, 0);
2351
is($dbi->select(table => $table1)->one->{$key2}, 2);
2352
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2353

            
2354
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2355
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2356
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2357
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2358
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2359
    {$key3 => 4},
2360
    table => $table1,
2361
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2362
    id => [1, 2]
2363
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2364
is($dbi->select(table => $table1)->one->{$key1}, 1);
2365
is($dbi->select(table => $table1)->one->{$key2}, 2);
2366
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2367

            
2368

            
2369
test 'model update and id option';
2370
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2371
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2372
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2373
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2374
$dbi->model($table1)->update(
cleanup test
Yuki Kimoto authored on 2011-08-10
2375
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2376
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2377
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2378
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2379
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2380
is($row->{$key1}, 1);
2381
is($row->{$key2}, 2);
2382
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2383

            
2384

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2397
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2398
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2399
    table => $table1,
2400
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2401
    id => 0,
2402
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2403
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2404

            
2405

            
2406
test 'model delete and id option';
2407
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2408
eval { $dbi->execute("drop table $table1") };
2409
eval { $dbi->execute("drop table $table2") };
2410
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2411
$dbi->execute($create_table1_2);
2412
$dbi->execute($create_table2_2);
2413
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2414
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2415
$dbi->model($table1)->delete(id => [1, 2]);
2416
is_deeply($dbi->select(table => $table1)->all, []);
2417
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2418
$dbi->model($table1)->delete(id => [1, 2]);
2419
is_deeply($dbi->select(table => $table1)->all, []);
2420
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2421
$dbi->model($table3)->delete(id => [1, 2]);
2422
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2423

            
2424

            
2425
test 'select and id option';
2426
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2427
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2428
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2429
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2430
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2431
    table => $table1,
2432
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2433
    id => [1, 2]
2434
);
2435
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2436
is($row->{$key1}, 1);
2437
is($row->{$key2}, 2);
2438
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2439

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

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

            
2464

            
2465
test 'model select_at';
2466
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2467
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2468
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2469
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2470
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2471
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2472
is($row->{$key1}, 1);
2473
is($row->{$key2}, 2);
2474
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2475

            
2476
test 'column separator is default .';
2477
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2478
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2479
eval { $dbi->execute("drop table $table1") };
2480
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2481
$dbi->execute($create_table1);
2482
$dbi->execute($create_table2);
2483
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2484
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2485
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2486
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2487
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2488
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2489
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2490
);
2491
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2492
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2493

            
2494
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2495
    column => [$model->column($table2 => [$key1, $key3])],
2496
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2497
);
2498
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2499
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2500

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2501
test 'separator';
2502
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2503
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2504
eval { $dbi->execute("drop table $table1") };
2505
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2506
$dbi->execute($create_table1);
2507
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2508

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2509
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2510
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2511
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2512
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2513
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2514
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2515
);
2516
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2517
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2518
);
2519
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2520
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2521
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2522
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2523
$result = $model->select(
2524
    column => [
2525
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2526
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2527
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2528
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2529
);
2530
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2531
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2532
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2533

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

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

            
2560

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2561
test 'filter_off';
2562
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2563
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2564
eval { $dbi->execute("drop table $table1") };
2565
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2566
$dbi->execute($create_table1);
2567
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2568

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2569
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2570
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2571
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2572
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2573
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2574
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2575
);
2576
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2577
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2578
$model = $dbi->model($table1);
2579
$result = $model->select(column => $key1);
2580
$result->filter($key1 => sub { $_[0] * 2 });
2581
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2582

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2583
test 'available_datetype';
2584
$dbi = DBIx::Custom->connect;
2585
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2586

            
2587

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2588
test 'select prefix option';
2589
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2590
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2591
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2592
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2593
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2594
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2595

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

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

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

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

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

            
2630
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2631
    id => {key => "$table1.id"},
2632
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2633
);
2634
is_deeply($param, {"$table1.price" => undef});
2635

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

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

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2648
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2649
    price => sub { '%' . $_[0] },
2650
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2651
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2652
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2653

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2654
eval { $dbi->execute("drop table $table1") };
2655
$dbi->execute($create_table1);
2656
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2657
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
2658

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

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

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

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2689
$where = $dbi->where;
2690
$where->clause(['and', ":${key1}{=}"]);
2691
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
2692
  ->pass([$key1, $key2])->map;
2693
$where->param($param);
2694
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2695
$row = $result->all;
2696
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2697

            
2698
$where = $dbi->where;
2699
$where->clause(['and', ":${key1}{=}"]);
2700
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
2701
$where->param($param);
2702
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2703
$row = $result->all;
2704
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2705

            
2706
$where = $dbi->where;
2707
$where->clause(['and', ":${key1}{=}"]);
2708
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
2709
  ->pass([$key1, $key2])->map;
2710
$where->param($param);
2711
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2712
$row = $result->all;
2713
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2714

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2716
$where = $dbi->where;
2717
$where->clause(['and', ":${key1}{=}"]);
2718
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
2719
$where->param($param);
2720
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2721
$row = $result->all;
2722
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2723

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

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

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

            
2752
$where = $dbi->where;
2753
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2754
    id => {key => "$table1.id"},
2755
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2756
);
2757
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
2758

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

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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2798
test 'order';
2799
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2800
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2801
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2802
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2803
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
2804
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
2805
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2806
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2807
$order->prepend($key1, "$key2 desc");
2808
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2809
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
2810
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2811
$order->prepend("$key1 desc");
2812
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2813
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
2814
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2815

            
2816
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2817
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2818
$result = $dbi->select(table => $table1,
2819
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2820
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2821
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
2822
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
2823
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
2824
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2825

            
2826
test 'tag_parse';
2827
$dbi = DBIx::Custom->connect;
2828
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2829
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2830
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2831
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2832
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2833
ok($@);
2834

            
2835
test 'last_sql';
2836
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2837
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2838
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2839
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
2840
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2841

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

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

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

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

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

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

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

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

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2903
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2904
$dbi->execute($create_table1_highperformance);
2905
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2906
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2907
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2908
];
2909
{
2910
    my $query;
2911
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
2912
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2913
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2914
      $sth ||= $query->sth;
2915
      $sth->execute(map { $row->{$_} } sort keys %$row);
2916
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2917
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2918
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2919
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2920
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2921
      ]
2922
    );
2923
}
2924

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

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2946
test 'id option more';
2947
eval { $dbi->execute("drop table $table1") };
2948
$dbi->execute($create_table1_highperformance);
2949
$row = {
2950
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
2951
};
2952
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2953
$model->insert($row);
2954
$query = $model->update({$key7 => 11}, id => 1, query => 1);
2955
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
2956
is_deeply($dbi->select(table => $table1)->one,
2957
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
2958
);
2959

            
2960
eval { $dbi->execute("drop table $table1") };
2961
eval { $dbi->execute("drop table $table2") };
2962
$dbi->execute($create_table1);
2963
$dbi->execute($create_table2);
2964
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2965
$model->insert({$key1 => 1, $key2 => 2});
2966
$model = $dbi->create_model(table => $table2, primary_key => $key1,
2967
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
2968
$model->insert({$key1 => 1, $key3 => 3});
2969
$result = $model->select(
2970
    column => {$table1 => ["$key2"]},
2971
    id => 1
2972
);
2973
is_deeply($result->all, [{"$table1.$key2" => 2}]);
2974

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

            
2986
eval { $dbi->execute("drop table $table1") };
2987
eval { $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->select(id => 1, query => 1);
2994
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
2995
is_deeply($dbi->select(table => $table1)->one,
2996
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
2997
);
2998

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3006
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3007
@rows = ();
3008
while (my $row = $result->fetch) {
3009
    push @rows, [@$row];
3010
}
3011
is_deeply(\@rows, [[1, 2], [3, 4]]);
3012

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3013
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3014
@rows = ();
3015
while (my $row = $result->fetch_hash) {
3016
    push @rows, {%$row};
3017
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3018
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3019

            
3020
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3021
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3022
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3023
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3024
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3025

            
3026
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3027
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3028
$rows = $result->fetch_all;
3029
is_deeply($rows, [[1, 2], [3, 4]]);
3030

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

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

            
3039
$rows = $result->fetch_all;
3040
is_deeply($rows, [[3, 2], [9, 4]], "array");
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
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3044
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3045
$rows = $result->fetch_hash_all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3046
is_deeply($rows, [{$key1 => 3, $key2 => 2}, {$key1 => 9, $key2 => 4}], "hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
3047

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

            
3084
for (my $i = 0; $i < @$datas; $i++) {
3085
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3086
    my $dbi = DBIx::Custom->new;
3087
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3088
    my $query = $builder->build_query($data->{source});
3089
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3090
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3091
}
3092

            
cleanup
Yuki Kimoto authored on 2011-08-13
3093
$dbi = DBIx::Custom->new;
3094
$builder = $dbi->query_builder;
3095
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3096
    p => sub {
3097
        my @args = @_;
3098
        
3099
        my $expand    = "? $args[0] $args[1]";
3100
        my $columns = [2];
3101
        return [$expand, $columns];
3102
    }
3103
);
3104

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3115
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3116
    q => 'string'
3117
});
3118

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3122
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3123
   r => sub {} 
3124
});
3125

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3129
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3130
   s => sub { return ["a", ""]} 
3131
});
3132

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3136
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3137
    t => sub {return ["a", []]}
3138
);
3139

            
3140

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

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

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

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

            
3156
test 'variouse source';
3157
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3158
$query = $builder->build_query($source);
3159
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3160

            
3161
$source = "abc";
3162
$query = $builder->build_query($source);
3163
is($query->sql, 'abc', "basic : 2");
3164

            
3165
$source = "{= a}";
3166
$query = $builder->build_query($source);
3167
is($query->sql, 'a = ?', "only tag");
3168

            
3169
$source = "000";
3170
$query = $builder->build_query($source);
3171
is($query->sql, '000', "contain 0 value");
3172

            
3173
$source = "a {= b} }";
3174
eval{$builder->build_query($source)};
3175
like($@, qr/unexpected "}"/, "error : 1");
3176

            
3177
$source = "a {= {}";
3178
eval{$builder->build_query($source)};
3179
like($@, qr/unexpected "{"/, "error : 2");
3180

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3199
test 'select() after_build_sql option';
3200
$dbi = DBIx::Custom->connect;
3201
$dbi->user_table_info($user_table_info);
3202
eval { $dbi->execute("drop table $table1") };
3203
$dbi->execute($create_table1);
3204
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3205
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3206
$rows = $dbi->select(
3207
    table => $table1,
3208
    column => $key1,
3209
    after_build_sql => sub {
3210
        my $sql = shift;
3211
        $sql = "select * from ( $sql ) t where $key1 = 1";
3212
        return $sql;
3213
    }
3214
)->all;
3215
is_deeply($rows, [{$key1 => 1}]);
3216

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3217
test 'dbi method from model';
3218
$dbi = MyDBI9->connect;
3219
eval { $dbi->execute("drop table $table1") };
3220
$dbi->execute($create_table1);
3221
$dbi->setup_model;
3222
$model = $dbi->model($table1);
3223
eval{$model->execute("select * from $table1")};
3224
ok(!$@);
3225

            
3226
test 'column table option';
3227
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3228
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3229
eval { $dbi->execute("drop table $table1") };
3230
$dbi->execute($create_table1);
3231
eval { $dbi->execute("drop table $table2") };
3232
$dbi->execute($create_table2);
3233
$dbi->setup_model;
3234
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3235
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3236
$model = $dbi->model($table1);
3237
$result = $model->select(
3238
    column => [
3239
        $model->column($table2, {alias => $table2_alias})
3240
    ],
3241
    where => {"$table2_alias.$key3" => 4}
3242
);
3243
is_deeply($result->one, 
3244
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3245

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

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

            
3266
test 'create_model';
3267
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3268
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3269
eval { $dbi->execute("drop table $table1") };
3270
eval { $dbi->execute("drop table $table2") };
3271
$dbi->execute($create_table1);
3272
$dbi->execute($create_table2);
3273

            
3274
$dbi->create_model(
3275
    table => $table1,
3276
    join => [
3277
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3278
    ],
3279
    primary_key => [$key1]
3280
);
3281
$model2 = $dbi->create_model(
3282
    table => $table2
3283
);
3284
$dbi->create_model(
3285
    table => $table3,
3286
    filter => [
3287
        $key1 => {in => sub { uc $_[0] }}
3288
    ]
3289
);
3290
$dbi->setup_model;
3291
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3292
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3293
$model = $dbi->model($table1);
3294
$result = $model->select(
3295
    column => [$model->mycolumn, $model->column($table2)],
3296
    where => {"$table1.$key1" => 1}
3297
);
3298
is_deeply($result->one,
3299
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3300
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3301

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

            
3313
test 'model helper';
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->helper(foo => sub { shift->select(@_) });
3322
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3323

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3324
test 'assign_clause';
cleanup test
Yuki Kimoto authored on 2011-08-15
3325
$dbi = DBIx::Custom->connect;
3326
eval { $dbi->execute("drop table $table1") };
3327
$dbi->execute($create_table1_2);
3328
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3329
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3330

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

            
3344

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

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

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

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

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

            
3387
$dbi = DBIx::Custom->connect;
3388
eval { $dbi->execute("drop table $table1") };
3389
$dbi->execute($create_table1_2);
3390
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3391
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3392

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3419
test 'Model class';
3420
$dbi = MyDBI1->connect;
3421
eval { $dbi->execute("drop table $table1") };
3422
$dbi->execute($create_table1);
3423
$model = $dbi->model($table1);
3424
$model->insert({$key1 => 'a', $key2 => 'b'});
3425
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3426
eval { $dbi->execute("drop table $table2") };
3427
$dbi->execute($create_table2);
3428
$model = $dbi->model($table2);
3429
$model->insert({$key1 => 'a'});
3430
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3431
is($dbi->models->{$table1}, $dbi->model($table1));
3432
is($dbi->models->{$table2}, $dbi->model($table2));
3433

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

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

            
3458
test 'primary_key';
3459
$dbi = MyDBI1->connect;
3460
$model = $dbi->model($table1);
3461
$model->primary_key([$key1, $key2]);
3462
is_deeply($model->primary_key, [$key1, $key2]);
3463

            
3464
test 'columns';
3465
$dbi = MyDBI1->connect;
3466
$model = $dbi->model($table1);
3467
$model->columns([$key1, $key2]);
3468
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3469

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3470
test 'setup_model';
3471
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3472
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3473
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3474
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3475

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3476
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3477
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3478
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3479
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3480
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3481

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3482
test 'each_column';
3483
$dbi = DBIx::Custom->connect;
3484
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3485
eval { $dbi->execute("drop table $table1") };
3486
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3487
eval { $dbi->execute("drop table $table3") };
3488
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3489
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3490

            
3491
$infos = [];
3492
$dbi->each_column(sub {
3493
    my ($self, $table, $column, $cinfo) = @_;
3494
    
3495
    if ($table =~ /^table\d/i) {
3496
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3497
         push @$infos, $info;
3498
    }
3499
});
3500
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3501
is_deeply($infos, 
3502
    [
3503
        [$table1, $key1, $key1],
3504
        [$table1, $key2, $key2],
3505
        [$table2, $key1, $key1],
3506
        [$table2, $key3, $key3]
3507
    ]
3508
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3509
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3510

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3535
$dbi = DBIx::Custom->connect;
3536
eval { $dbi->execute("drop table $table1") };
3537
eval { $dbi->execute("drop table $table2") };
3538
$dbi->execute($create_table2);
3539
$dbi->execute($create_table1_type);
3540

            
3541
$infos = [];
3542
$dbi->user_table_info($user_table_info);
3543
$dbi->each_table(sub {
3544
    my ($self, $table, $table_info) = @_;
3545
    
3546
    if ($table =~ /^table\d/i) {
3547
         my $info = [$table, $table_info->{TABLE_NAME}];
3548
         push @$infos, $info;
3549
    }
3550
});
3551
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3552
is_deeply($infos, 
3553
    [
3554
        [$table1, $table1],
3555
        [$table2, $table2],
3556
        [$table3, $table3],
3557
    ]
3558
);
3559

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3560
test 'type_rule into';
3561
eval { $dbi->execute("drop table $table1") };
3562
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3563
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3564

            
3565

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3566
$dbi = DBIx::Custom->connect;
3567
eval { $dbi->execute("drop table $table1") };
3568
$dbi->execute($create_table1_type);
3569

            
cleanup
Yuki Kimoto authored on 2011-08-16
3570
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3571
$dbi->type_rule(
3572
    into1 => {
3573
        $date_typename => sub { '2010-' . $_[0] }
3574
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3575
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3576
$dbi->insert({$key1 => '01-01'}, table => $table1);
3577
$result = $dbi->select(table => $table1);
3578
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3579

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

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

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

            
3644
$dbi = DBIx::Custom->connect;
3645
eval { $dbi->execute("drop table $table1") };
3646
$dbi->execute($create_table1_type);
3647
$dbi->register_filter(convert => sub {
3648
    my $value = shift || '';
3649
    $value =~ s/02/03/;
3650
    return $value;
3651
});
cleanup
Yuki Kimoto authored on 2011-08-16
3652
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3653
$dbi->type_rule(
3654
    from1 => {
3655
        $date_datatype => 'convert',
3656
    },
3657
    into1 => {
3658
        $date_typename => 'convert',
3659
    }
3660
);
3661
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3662
$result = $dbi->select(table => $table1);
3663
like($result->fetch->[0], qr/^2010-03-03/);
3664

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

            
3690

            
3691
$dbi = DBIx::Custom->connect;
3692
eval { $dbi->execute("drop table $table1") };
3693
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3694
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3695
$dbi->type_rule(
3696
    from1 => {
3697
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3698
    },
3699
    from2 => {
3700
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3701
    },
3702
);
3703
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3704
$result = $dbi->select(table => $table1);
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
$result->type_rule(
3707
    from1 => {
3708
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3709
    },
3710
    from2 => {
3711
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3712
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3713
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3714
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3715
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3716

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3796
eval{$dbi->type_rule(
3797
    into1 => {
3798
        $date_typename => 'pp'
3799
    }
3800
)};
3801
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3802

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3803
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3804
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3805
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3806
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3807
    $dbi->type_rule(
3808
        from1 => {
3809
            Date => sub { $_[0] * 2 },
3810
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3811
    );
3812
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3813
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3814

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3815
eval {
3816
    $dbi->type_rule(
3817
        into1 => {
3818
            Date => sub { $_[0] * 2 },
3819
        }
3820
    );
3821
};
3822
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3823

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

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

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

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

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

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

            
3899
$result = $dbi->select(table => $table1);
3900
$result->type_rule(
3901
    from1 => [$date_datatype => undef]
3902
);
3903
$row = $result->one;
3904
like($row->{$key1}, qr/^2010-01-03/);
3905
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3906

            
3907
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3908
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3909
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3910
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3911
$dbi->type_rule(
3912
    from1 => {
3913
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3914
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3915
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3916
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3917
$result = $dbi->select(table => $table1);
3918
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3919
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3920

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

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4007
test 'join';
4008
$dbi = DBIx::Custom->connect;
4009
eval { $dbi->execute("drop table $table1") };
4010
$dbi->execute($create_table1);
4011
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4012
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
4013
eval { $dbi->execute("drop table $table2") };
4014
$dbi->execute($create_table2);
4015
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4016
eval { $dbi->execute("drop table $table3") };
4017
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
4018
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
4019
$rows = $dbi->select(
4020
    table => $table1,
4021
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4022
    where   => {"$table1.$key2" => 2},
4023
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4024
)->all;
4025
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
4026

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

            
4034
$rows = $dbi->select(
4035
    table => $table1,
4036
    where   => {$key1 => 1},
4037
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4038
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4039
)->all;
4040
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4041

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

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

            
4060
$dbi = DBIx::Custom->connect;
4061
eval { $dbi->execute("drop table $table1") };
4062
$dbi->execute($create_table1);
4063
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4064
eval { $dbi->execute("drop table $table2") };
4065
$dbi->execute($create_table2);
4066
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4067
$rows = $dbi->select(
4068
    table => $table1,
4069
    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",
4070
    where   => {"$table1.$key2" => 2},
4071
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4072
)->all;
4073
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4074
          'quote');
4075

            
4076

            
4077
$dbi = DBIx::Custom->connect;
4078
eval { $dbi->execute("drop table $table1") };
4079
$dbi->execute($create_table1);
4080
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4081
$sql = <<"EOS";
4082
left outer join (
4083
  select * from $table1 t1
4084
  where t1.$key2 = (
4085
    select max(t2.$key2) from $table1 t2
4086
    where t1.$key1 = t2.$key1
4087
  )
4088
) $table3 on $table1.$key1 = $table3.$key1
4089
EOS
4090
$join = [$sql];
4091
$rows = $dbi->select(
4092
    table => $table1,
4093
    column => "$table3.$key1 as ${table3}__$key1",
4094
    join  => $join
4095
)->all;
4096
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4097

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

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

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4150
$dbi = DBIx::Custom->connect;
4151
eval { $dbi->execute("drop table $table1") };
4152
eval { $dbi->execute("drop table $table2") };
4153
$dbi->execute($create_table1);
4154
$dbi->execute($create_table2);
4155
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4156
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4157
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4158
$result = $dbi->select(
4159
    table => $table1,
4160
    column => [{$table2 => [$key3]}],
4161
    join => [
4162
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4163
    ]
4164
);
4165
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4166

            
4167
$dbi = DBIx::Custom->connect;
4168
eval { $dbi->execute("drop table $table1") };
4169
eval { $dbi->execute("drop table $table2") };
4170
$dbi->execute($create_table1);
4171
$dbi->execute($create_table2);
4172
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4173
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4174
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4175
$result = $dbi->select(
4176
    table => $table1,
4177
    column => [{$table2 => [$key3]}],
4178
    join => [
4179
        "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4180
    ]
4181
);
4182
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4183

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4184
test 'columns';
4185
$dbi = MyDBI1->connect;
4186
$model = $dbi->model($table1);
4187

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4188
test 'count';
4189
$dbi = DBIx::Custom->connect;
4190
eval { $dbi->execute("drop table $table1") };
4191
$dbi->execute($create_table1);
4192
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4193
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 3});
4194
is($dbi->count(table => $table1), 2);
4195
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4196
$model = $dbi->create_model(table => $table1);
4197
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4198

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