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

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

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

            
14
plan 'no_plan';
15

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

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

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

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

            
88
    use strict;
89
    use warnings;
90

            
91
    use base 'DBIx::Custom';
92

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

            
104
    package MyModel2::Base1;
105

            
106
    use strict;
107
    use warnings;
108

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

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

            
113
    use strict;
114
    use warnings;
115

            
116
    use base 'MyModel2::Base1';
117

            
118
    sub insert {
119
        my ($self, $param) = @_;
120
        
121
        return $self->SUPER::insert(param => $param);
122
    }
123

            
124
    sub list { shift->select; }
125

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

            
128
    use strict;
129
    use warnings;
130

            
131
    use base 'MyModel2::Base1';
132

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

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

            
141
    package MyModel2::TABLE1;
142

            
143
    use strict;
144
    use warnings;
145

            
146
    use base 'MyModel2::Base1';
147

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

            
154
    sub list { shift->select; }
155

            
156
    package MyModel2::TABLE2;
157

            
158
    use strict;
159
    use warnings;
160

            
161
    use base 'MyModel2::Base1';
162

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

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

            
174
    use strict;
175
    use warnings;
176

            
177
    use base 'DBIx::Custom';
178

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
572

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

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

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

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

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

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

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

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

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

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

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

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

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

            
686
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
687
like($@, qr/safety/);
688

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

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

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

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

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

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

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

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

            
779

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

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

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

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

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

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

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

            
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
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
839
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
840
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
841
$rows   = $result->all;
842
is_deeply($rows, [], "basic");
843

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

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

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

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

            
875

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

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

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

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

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

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

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

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

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

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

            
943
test 'filters';
944
$dbi = DBIx::Custom->new;
945

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
952
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
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});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
959
$dbi->rollback;
960
$dbi->dbh->{AutoCommit} = 1;
961

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

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

            
966
$dbi = DBIx::Custom->connect;
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);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
969
$dbi->begin_work;
970
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
971
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
972
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
973
$dbi->commit;
974
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
975
$result = $dbi->select(table => $table1);
976
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
977
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
978

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

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

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

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

            
1013

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1014
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1015
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1016
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1017
$dbi->execute($create_table1);
1018

            
1019
$dbi->begin_work;
1020

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

            
1027
$dbi->rollback if $@;
1028

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

            
1033
$dbi->begin_work;
1034

            
1035
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1036
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1037
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1038
};
1039

            
1040
$dbi->commit unless $@;
1041

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

            
1046
$dbi->dbh->{AutoCommit} = 0;
1047
eval{ $dbi->begin_work };
1048
ok($@, "exception");
1049
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1050

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1051
test 'cache';
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->cache(1);
1054
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1055
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1056
$dbi->execute($source, {}, query => 1);
1057
is_deeply($dbi->{_cached}->{$source}, 
cleanup test
Yuki Kimoto authored on 2011-08-15
1058
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1059

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

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

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

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

            
1090
{
1091
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1092
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1093
    like($@, qr/\Q.t /, "caller spec : not vebose");
1094
}
1095
{
1096
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1097
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1098
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1099
}
1100

            
1101
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1102
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1103
    one => sub { 1 }
1104
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1105
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1106
    two => sub { 2 }
1107
);
1108
$dbi->method({
1109
    twice => sub {
1110
        my $self = shift;
1111
        return $_[0] * 2;
1112
    }
1113
});
1114

            
1115
is($dbi->one, 1, "first");
1116
is($dbi->two, 2, "second");
1117
is($dbi->twice(5), 10 , "second");
1118

            
1119
eval {$dbi->XXXXXX};
1120
ok($@, "not exists");
1121

            
1122
test 'out filter';
1123
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1124
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1125
$dbi->execute($create_table1);
1126
$dbi->register_filter(twice => sub { $_[0] * 2 });
1127
$dbi->register_filter(three_times => sub { $_[0] * 3});
1128
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1129
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1130
              $key2 => {out => 'three_times', in => 'twice'});
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->fetch_hash_first;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1134
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1135
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1136
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1137
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1138

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

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

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

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

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

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

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

            
1241
$result->filter({$key2 => 'twice'});
1242
$rows   = $result->all;
1243
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1244

            
1245
$result = $dbi->select(
1246
     table => [$table1, $table2],
1247
     column => [$key2, $key3],
1248
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1249

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1268
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1269
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1270
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1271
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1272
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1273

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

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

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

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

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

            
1322
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1323
$dbi->apply_filter($table1,
1324
    $key1 => {end => sub { $_[0] * 3 } },
1325
    $key2 => {end => 'five_times'}
1326
);
1327
$result = $dbi->select(table => $table1);
1328
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1329
$result->filter($key1 => undef);
1330
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1331
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1332
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1333

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

            
1348
test 'empty where select';
1349
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1350
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1351
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1352
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1353
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1354
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1355
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1356

            
1357
test 'select query option';
1358
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1359
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1360
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1361
$query = $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1362
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1363
$query = $dbi->update(table => $table1, where => {$key1 => 1}, param => {$key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1364
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1365
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1366
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1367
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1368
is(ref $query, 'DBIx::Custom::Query');
1369

            
1370
test 'where';
1371
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1372
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1373
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1374
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1375
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1376
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1377
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1378

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

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

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

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

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

            
1420
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1421
             ->clause(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"])
1422
             ->param({$key1 => [0, 3], $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1423
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1424
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1425
    where => $where,
1426
); 
1427
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1428
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1429

            
1430
$where = $dbi->where;
1431
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1432
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1433
    where => $where
1434
);
1435
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1436
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1437

            
1438
eval {
1439
$where = $dbi->where
1440
             ->clause(['uuu']);
1441
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1442
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1443
    where => $where
1444
);
1445
};
1446
ok($@);
1447

            
1448
$where = $dbi->where;
1449
is("$where", '');
1450

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

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

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

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

            
1491
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1492
             ->clause("$key1 = :$key1 $key2 = :$key2")
1493
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1494
eval{$where->to_string};
1495
like($@, qr/one column/);
1496

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

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

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

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

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

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

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

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

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

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

            
1597
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1598
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1599
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists]});
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
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1608
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1609
             ->param({$key1 => [0, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1610
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1611
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1612
    where => $where,
1613
);
1614
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1615
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1616

            
1617
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1618
             ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1619
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1620
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1621
    where => $where,
1622
);
1623
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1624
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1625

            
1626
eval {$dbi->where(ppp => 1) };
1627
like($@, qr/invalid/);
1628

            
1629
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1630
    clause => ['and', ['or'], ['and', "$key1 = :$key1", "$key2 = :$key2"]],
1631
    param => {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
1632
);
1633
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1634
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1635
    where => $where,
1636
);
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

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

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

            
1659
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1660
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1661
$where->param({$key1 => [undef, undef]});
1662
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1663
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1664
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1665
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1666
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1667
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1668

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

            
1676
test 'register_tag';
1677
$dbi = DBIx::Custom->connect;
1678
$dbi->register_tag(
1679
    b => sub { 2 }
1680
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1681
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1682

            
1683
test 'table not specify exception';
1684
$dbi = DBIx::Custom->connect;
1685
eval {$dbi->insert};
1686
like($@, qr/table/);
1687
eval {$dbi->update};
1688
like($@, qr/table/);
1689
eval {$dbi->delete};
1690
like($@, qr/table/);
1691
eval {$dbi->select};
1692
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1693

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1694
test 'more tests';
1695
$dbi = DBIx::Custom->connect;
1696
eval{$dbi->apply_filter('table', 'column', [])};
1697
like($@, qr/apply_filter/);
1698

            
1699
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1700
like($@, qr/apply_filter/);
1701

            
1702
$dbi->apply_filter(
1703

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

            
1715
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1716
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1717
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1718
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1719
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1720
$dbi->apply_filter($table1, $key2, {});
1721
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1722
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1723

            
1724
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1725
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1726
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1727
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1728
like($@, qr/not registered/);
1729
$dbi->method({one => sub { 1 }});
1730
is($dbi->one, 1);
1731

            
1732
eval{DBIx::Custom->connect(dsn => undef)};
1733
like($@, qr/_connect/);
1734

            
1735
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1736
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1737
$dbi->execute($create_table1);
1738
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1739
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1740
             filter => {$key1 => 'twice'});
1741
$row = $dbi->select(table => $table1)->one;
1742
is_deeply($row, {$key1 => 2, $key2 => 2});
1743
eval {$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1744
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
1745
like($@, qr//);
1746

            
1747
$dbi->register_filter(one => sub { });
1748
$dbi->default_fetch_filter('one');
1749
ok($dbi->default_fetch_filter);
1750
$dbi->default_bind_filter('one');
1751
ok($dbi->default_bind_filter);
1752
eval{$dbi->default_fetch_filter('no')};
1753
like($@, qr/not registered/);
1754
eval{$dbi->default_bind_filter('no')};
1755
like($@, qr/not registered/);
1756
$dbi->default_bind_filter(undef);
1757
ok(!defined $dbi->default_bind_filter);
1758
$dbi->default_fetch_filter(undef);
1759
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1760
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1761
like($@, qr/Tag not finished/);
1762

            
1763
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1764
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1765
$dbi->execute($create_table1);
1766
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1767
$result = $dbi->select(table => $table1);
1768
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1769
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1770
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1771
like($@, qr/not registered/);
1772
$result->default_filter(undef);
1773
ok(!defined $result->default_filter);
1774
$result->default_filter('one');
1775
is($result->default_filter->(), 1);
1776

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1777
test 'option';
1778
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
1779
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
1780
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
1781
ok($dbi->dbh->{PrintError});
1782
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
1783
ok($dbi->dbh->{PrintError});
1784

            
1785
test 'DBIx::Custom::Result stash()';
1786
$result = DBIx::Custom::Result->new;
1787
is_deeply($result->stash, {}, 'default');
1788
$result->stash->{foo} = 1;
1789
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
1790

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

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

            
1811
test 'insert_at';
1812
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1813
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1814
$dbi->execute($create_table1_2);
1815
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1816
    primary_key => [$key1, $key2], 
1817
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1818
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1819
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1820
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1821
is($dbi->select(table => $table1)->one->{$key1}, 1);
1822
is($dbi->select(table => $table1)->one->{$key2}, 2);
1823
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1824

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1825
$dbi->delete_all(table => $table1);
1826
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1827
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1828
    primary_key => $key1, 
1829
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1830
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1831
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1832
);
1833

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

            
1838
eval {
1839
    $dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1840
        table => $table1,
1841
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1842
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1843
        param => {$key1 => 1, $key2 => 2, $key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
1844
    );
1845
};
1846
like($@, qr/must be/);
1847

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1876
$dbi->delete_all(table => $table1);
1877
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1878
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1879
    table => $table1,
1880
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1881
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1882
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
1883
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1884
is($dbi->select(table => $table1)->one->{$key1}, 1);
1885
is($dbi->select(table => $table1)->one->{$key2}, 2);
1886
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1887

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

            
1902
test 'select_at';
1903
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1904
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1905
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1906
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1907
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1908
    table => $table1,
1909
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1910
    where => [1, 2]
1911
);
1912
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1913
is($row->{$key1}, 1);
1914
is($row->{$key2}, 2);
1915
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1916

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1929
$dbi->delete_all(table => $table1);
1930
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1931
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1932
    table => $table1,
1933
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1934
    where => [1, 2]
1935
);
1936
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1937
is($row->{$key1}, 1);
1938
is($row->{$key2}, 2);
1939
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1940

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

            
1950
eval {
1951
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1952
        table => $table1,
1953
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1954
        where => [1],
1955
    );
1956
};
1957
like($@, qr/same/);
1958

            
1959
eval {
1960
    $result = $dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1961
        table => $table1,
1962
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1963
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1964
        param => {$key1 => 1, $key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-10
1965
    );
1966
};
1967
like($@, qr/must be/);
1968

            
1969
eval {
1970
    $result = $dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1971
        table => $table1,
1972
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1973
        where => {},
1974
    );
1975
};
1976
like($@, qr/must be/);
1977

            
1978
test 'model delete_at';
1979
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1980
eval { $dbi->execute("drop table $table1") };
1981
eval { $dbi->execute("drop table $table2") };
1982
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1983
$dbi->execute($create_table1_2);
1984
$dbi->execute($create_table2_2);
1985
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1986
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1987
$dbi->model($table1)->delete_at(where => [1, 2]);
1988
is_deeply($dbi->select(table => $table1)->all, []);
1989
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1990
$dbi->model($table1)->delete_at(where => [1, 2]);
1991
is_deeply($dbi->select(table => $table1)->all, []);
1992
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1993
$dbi->model($table3)->delete_at(where => [1, 2]);
1994
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1995

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

            
2010
test 'model update_at';
2011
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2012
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2013
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2014
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2015
$dbi->model($table1)->update_at(
cleanup test
Yuki Kimoto authored on 2011-08-10
2016
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2017
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2018
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2019
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2020
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2021
is($row->{$key1}, 1);
2022
is($row->{$key2}, 2);
2023
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2024

            
2025
test 'model select_at';
2026
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2027
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2028
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2029
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2030
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2031
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2032
is($row->{$key1}, 1);
2033
is($row->{$key2}, 2);
2034
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2035

            
2036

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

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

            
2069
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2070
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2071
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2072
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2073
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2074
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2075
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2076
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2077
$dbi->execute($sql, param => $param, table => $table1);
2078
is($dbi->select(table => $table1)->one->{$key1}, 1);
2079
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2080

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2084
test 'mycolumn';
2085
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2086
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2087
eval { $dbi->execute("drop table $table1") };
2088
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2089
$dbi->execute($create_table1);
2090
$dbi->execute($create_table2);
2091
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2092
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2093
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2094
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2095
$result = $model->select_at(
2096
    column => [
2097
        $model->mycolumn,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2098
        $model->column($table2)
cleanup test
Yuki Kimoto authored on 2011-08-10
2099
    ]
2100
);
2101
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2102
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2103

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

            
2121
$result = $model->select_at(
2122
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2123
        $model->mycolumn([$key1]),
2124
        ["$table2.$key1", as => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2125
    ]
2126
);
2127
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2128
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2129

            
2130
$result = $model->select_at(
2131
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2132
        $model->mycolumn([$key1]),
2133
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2134
    ]
2135
);
2136
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2137
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2138

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2139
test 'merge_param';
2140
$dbi = DBIx::Custom->new;
2141
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2142
    {$key1 => 1, $key2 => 2, $key3 => 3},
2143
    {$key1 => 1, $key2 => 2},
2144
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2145
];
2146
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2147
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2148

            
2149
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2150
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2151
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2152
];
2153
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2154
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
2155

            
2156
test 'select() param option';
2157
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2158
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2159
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2160
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2161
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2162
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2163
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2164
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
2165
$dbi->insert(table => $table2, param => {$key1 => 2, $key3 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-10
2166
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2167
    table => $table1,
2168
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2169
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2170
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
test cleanup
Yuki Kimoto authored on 2011-08-15
2171
              " $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2172
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2173
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2174
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2175

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

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

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

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

            
2232

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

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

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

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

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

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

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

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

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

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

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

            
2369

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

            
2385

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

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

            
2406

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

            
2425

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

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

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

            
2465

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

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

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

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

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

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

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

            
2561

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

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

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

            
2588

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3041
$rows = $result->fetch_all;
3042
is_deeply($rows, [[3, 2], [9, 4]], "array");
3043

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3142

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3346

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3567

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

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

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

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

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

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

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

            
3692

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4036
eval {
4037
    $rows = $dbi->select(
4038
        table => $table1,
4039
        column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4040
        where   => {"$table1.$key2" => 2},
4041
        join  => {"$table1.$key1" => "$table2.$key1"}
4042
    );
4043
};
4044
like ($@, qr/array/);
4045

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

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

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

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

            
4088

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

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

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

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

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

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

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

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