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

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

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

            
14
plan 'no_plan';
15

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

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

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

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

            
88
    use strict;
89
    use warnings;
90

            
91
    use base 'DBIx::Custom';
92

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

            
104
    package MyModel2::Base1;
105

            
106
    use strict;
107
    use warnings;
108

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

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

            
113
    use strict;
114
    use warnings;
115

            
116
    use base 'MyModel2::Base1';
117

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

            
124
    sub list { shift->select; }
125

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

            
128
    use strict;
129
    use warnings;
130

            
131
    use base 'MyModel2::Base1';
132

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

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

            
141
    package MyModel2::TABLE1;
142

            
143
    use strict;
144
    use warnings;
145

            
146
    use base 'MyModel2::Base1';
147

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

            
154
    sub list { shift->select; }
155

            
156
    package MyModel2::TABLE2;
157

            
158
    use strict;
159
    use warnings;
160

            
161
    use base 'MyModel2::Base1';
162

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

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

            
174
    use strict;
175
    use warnings;
176

            
177
    use base 'DBIx::Custom';
178

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
569

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
773

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

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

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

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

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

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

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

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

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

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

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

            
866

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
998

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

            
1004
$dbi->begin_work;
1005

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

            
1012
$dbi->rollback if $@;
1013

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

            
1018
$dbi->begin_work;
1019

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

            
1025
$dbi->commit unless $@;
1026

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1622

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

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

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

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

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

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

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

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

            
1682
$dbi->apply_filter(
1683

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

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

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

            
1712
eval{DBIx::Custom->connect(dsn => undef)};
1713
like($@, qr/_connect/);
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);
1718
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1719
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1720
             filter => {$key1 => 'twice'});
1721
$row = $dbi->select(table => $table1)->one;
1722
is_deeply($row, {$key1 => 2, $key2 => 2});
1723
eval {$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1724
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
1725
like($@, qr//);
1726

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

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

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

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

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

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

            
1791
test 'insert_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);
1795
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1796
    primary_key => [$key1, $key2], 
1797
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1798
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1799
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1800
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1801
is($dbi->select(table => $table1)->one->{$key1}, 1);
1802
is($dbi->select(table => $table1)->one->{$key2}, 2);
1803
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1804

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

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

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

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

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

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

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

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

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

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

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

            
1930
eval {
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],
1935
    );
1936
};
1937
like($@, qr/same/);
1938

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

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

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

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

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

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

            
2016

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

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

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

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

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

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

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

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

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

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

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

            
2156
test 'select() string where';
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});
cleanup test
Yuki Kimoto authored on 2011-08-10
2162
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2163
    table => $table1,
2164
    where => "$key1 = :$key1 and $key2 = :$key2",
2165
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2166
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2167
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2168

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

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

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

            
2212

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

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

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

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

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

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

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

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

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

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

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

            
2349

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

            
2365

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

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

            
2386

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

            
2405

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

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

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

            
2445

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

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

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

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

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

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

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

            
2541

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

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

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

            
2568

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
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
    my $sth;
2893
    foreach my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2894
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2895
      $sth ||= $query->sth;
2896
      $sth->execute(map { $row->{$_} } sort keys %$row);
2897
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2898
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2899
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2900
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2901
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2902
      ]
2903
    );
2904
}
2905

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

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

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

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

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

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

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

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

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

            
3007
test 'fetch_all';
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 = $result->fetch_all;
3010
is_deeply($rows, [[1, 2], [3, 4]]);
3011

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3121

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3325

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3546

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

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

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

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

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

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

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

            
3671

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

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
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);
cleanup test
Yuki Kimoto authored on 2011-08-10
3787
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3788
    $dbi->type_rule(
3789
        from1 => {
3790
            Date => sub { $_[0] * 2 },
3791
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3792
    );
3793
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3794
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3795

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

            
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
Yuki Kimoto authored on 2011-08-16
3808
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3809
$dbi->type_rule(
3810
    from1 => {
3811
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3812
    },
3813
    into1 => {
3814
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3815
    }
3816
);
3817
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3818
$result = $dbi->select(table => $table1);
3819
$result->type_rule_off;
3820
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3821

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4067

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

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

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

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

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

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

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

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