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

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

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

            
14
plan 'no_plan';
15

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

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

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

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

            
88
    use strict;
89
    use warnings;
90

            
91
    use base 'DBIx::Custom';
92

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

            
104
    package MyModel2::Base1;
105

            
106
    use strict;
107
    use warnings;
108

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

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

            
113
    use strict;
114
    use warnings;
115

            
116
    use base 'MyModel2::Base1';
117

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

            
124
    sub list { shift->select; }
125

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

            
128
    use strict;
129
    use warnings;
130

            
131
    use base 'MyModel2::Base1';
132

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

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

            
141
    package MyModel2::TABLE1;
142

            
143
    use strict;
144
    use warnings;
145

            
146
    use base 'MyModel2::Base1';
147

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

            
154
    sub list { shift->select; }
155

            
156
    package MyModel2::TABLE2;
157

            
158
    use strict;
159
    use warnings;
160

            
161
    use base 'MyModel2::Base1';
162

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

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

            
174
    use strict;
175
    use warnings;
176

            
177
    use base 'DBIx::Custom';
178

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
734

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

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

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

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

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

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

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

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

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

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

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

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

            
830

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
968

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

            
974
$dbi->begin_work;
975

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

            
982
$dbi->rollback if $@;
983

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

            
988
$dbi->begin_work;
989

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

            
995
$dbi->commit unless $@;
996

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

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

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

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

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

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

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

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

            
1056
test 'method';
1057
$dbi->method(
1058
    one => sub { 1 }
1059
);
1060
$dbi->method(
1061
    two => sub { 2 }
1062
);
1063
$dbi->method({
1064
    twice => sub {
1065
        my $self = shift;
1066
        return $_[0] * 2;
1067
    }
1068
});
1069

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1595

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

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

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

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

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

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

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

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

            
1657
$dbi->apply_filter(
1658

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1991

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2187

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

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

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

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

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

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

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

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

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

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

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

            
2324

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

            
2340

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

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

            
2361

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

            
2380

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

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

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

            
2420

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

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

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

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

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

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

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

            
2516

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

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

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

            
2543

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3097

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3270
test 'assign_clause';
cleanup test
Yuki Kimoto authored on 2011-08-15
3271
$dbi = DBIx::Custom->connect;
3272
eval { $dbi->execute("drop table $table1") };
3273
$dbi->execute($create_table1_2);
3274
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3275
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3276

            
3277
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3278
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3279
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3280
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3281
where $key1 = 1
3282
EOS
3283
$dbi->execute($sql, param => $param);
3284
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3285
$rows   = $result->all;
3286
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3287
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3288
                  "basic");
3289

            
3290

            
3291
$dbi = DBIx::Custom->connect;
3292
eval { $dbi->execute("drop table $table1") };
3293
$dbi->execute($create_table1_2);
3294
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3295
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3296

            
3297
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3298
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3299
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3300
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3301
where $key1 = 1
3302
EOS
3303
$dbi->execute($sql, param => $param);
3304
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3305
$rows   = $result->all;
3306
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3307
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3308
                  "basic");
3309

            
3310
$dbi = DBIx::Custom->connect;
3311
eval { $dbi->execute("drop table $table1") };
3312
$dbi->execute($create_table1_2);
3313
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3314
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3315

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

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

            
3333
$dbi = DBIx::Custom->connect;
3334
eval { $dbi->execute("drop table $table1") };
3335
$dbi->execute($create_table1_2);
3336
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3337
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3338

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3365
test 'Model class';
3366
$dbi = MyDBI1->connect;
3367
eval { $dbi->execute("drop table $table1") };
3368
$dbi->execute($create_table1);
3369
$model = $dbi->model($table1);
3370
$model->insert({$key1 => 'a', $key2 => 'b'});
3371
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3372
eval { $dbi->execute("drop table $table2") };
3373
$dbi->execute($create_table2);
3374
$model = $dbi->model($table2);
3375
$model->insert({$key1 => 'a'});
3376
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3377
is($dbi->models->{$table1}, $dbi->model($table1));
3378
is($dbi->models->{$table2}, $dbi->model($table2));
3379

            
3380
$dbi = MyDBI4->connect;
3381
eval { $dbi->execute("drop table $table1") };
3382
$dbi->execute($create_table1);
3383
$model = $dbi->model($table1);
3384
$model->insert({$key1 => 'a', $key2 => 'b'});
3385
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3386
eval { $dbi->execute("drop table $table2") };
3387
$dbi->execute($create_table2);
3388
$model = $dbi->model($table2);
3389
$model->insert({$key1 => 'a'});
3390
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3391

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

            
3404
test 'primary_key';
3405
$dbi = MyDBI1->connect;
3406
$model = $dbi->model($table1);
3407
$model->primary_key([$key1, $key2]);
3408
is_deeply($model->primary_key, [$key1, $key2]);
3409

            
3410
test 'columns';
3411
$dbi = MyDBI1->connect;
3412
$model = $dbi->model($table1);
3413
$model->columns([$key1, $key2]);
3414
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3415

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3416
test 'setup_model';
3417
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3418
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3419
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3420
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3421

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3422
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3423
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3424
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3425
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3426
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3427

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3428
test 'each_column';
3429
$dbi = DBIx::Custom->connect;
3430
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3431
eval { $dbi->execute("drop table $table1") };
3432
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3433
eval { $dbi->execute("drop table $table3") };
3434
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3435
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3436

            
3437
$infos = [];
3438
$dbi->each_column(sub {
3439
    my ($self, $table, $column, $cinfo) = @_;
3440
    
3441
    if ($table =~ /^table\d/i) {
3442
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3443
         push @$infos, $info;
3444
    }
3445
});
3446
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3447
is_deeply($infos, 
3448
    [
3449
        [$table1, $key1, $key1],
3450
        [$table1, $key2, $key2],
3451
        [$table2, $key1, $key1],
3452
        [$table2, $key3, $key3]
3453
    ]
3454
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3455
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3456

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3457
test 'each_table';
3458
$dbi = DBIx::Custom->connect;
3459
eval { $dbi->execute("drop table $table1") };
3460
eval { $dbi->execute("drop table $table2") };
3461
$dbi->execute($create_table2);
3462
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3463

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3464
$infos = [];
3465
$dbi->each_table(sub {
3466
    my ($self, $table, $table_info) = @_;
3467
    
3468
    if ($table =~ /^table\d/i) {
3469
         my $info = [$table, $table_info->{TABLE_NAME}];
3470
         push @$infos, $info;
3471
    }
3472
});
3473
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3474
is_deeply($infos, 
3475
    [
3476
        [$table1, $table1],
3477
        [$table2, $table2],
3478
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3479
);
3480

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3481
$dbi = DBIx::Custom->connect;
3482
eval { $dbi->execute("drop table $table1") };
3483
eval { $dbi->execute("drop table $table2") };
3484
$dbi->execute($create_table2);
3485
$dbi->execute($create_table1_type);
3486

            
3487
$infos = [];
3488
$dbi->user_table_info($user_table_info);
3489
$dbi->each_table(sub {
3490
    my ($self, $table, $table_info) = @_;
3491
    
3492
    if ($table =~ /^table\d/i) {
3493
         my $info = [$table, $table_info->{TABLE_NAME}];
3494
         push @$infos, $info;
3495
    }
3496
});
3497
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3498
is_deeply($infos, 
3499
    [
3500
        [$table1, $table1],
3501
        [$table2, $table2],
3502
        [$table3, $table3],
3503
    ]
3504
);
3505

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3506
test 'type_rule into';
3507
eval { $dbi->execute("drop table $table1") };
3508
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3509
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3510

            
3511

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

            
cleanup
Yuki Kimoto authored on 2011-08-16
3516
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3517
$dbi->type_rule(
3518
    into1 => {
3519
        $date_typename => sub { '2010-' . $_[0] }
3520
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3521
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3522
$dbi->insert({$key1 => '01-01'}, table => $table1);
3523
$result = $dbi->select(table => $table1);
3524
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3525

            
3526
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3527
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3528
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3529
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3530
$dbi->type_rule(
3531
    into1 => [
3532
         [$date_typename, $datetime_typename] => sub {
3533
            my $value = shift;
3534
            $value =~ s/02/03/g;
3535
            return $value;
3536
         }
3537
    ]
3538
);
3539
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3540
$result = $dbi->select(table => $table1);
3541
$row = $result->one;
3542
like($row->{$key1}, qr/^2010-01-03/);
3543
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3544

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3545
$dbi = DBIx::Custom->connect;
3546
eval { $dbi->execute("drop table $table1") };
3547
$dbi->execute($create_table1_type);
3548
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3549
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3550
$dbi->type_rule(
3551
    into1 => [
3552
        [$date_typename, $datetime_typename] => sub {
3553
            my $value = shift;
3554
            $value =~ s/02/03/g;
3555
            return $value;
3556
        }
3557
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3558
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3559
$result = $dbi->execute(
3560
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3561
    param => {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
3562
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3563
$row = $result->one;
3564
like($row->{$key1}, qr/^2010-01-03/);
3565
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3566

            
3567
$dbi = DBIx::Custom->connect;
3568
eval { $dbi->execute("drop table $table1") };
3569
$dbi->execute($create_table1_type);
3570
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3571
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3572
$dbi->type_rule(
3573
    into1 => [
3574
        [$date_typename, $datetime_typename] => sub {
3575
            my $value = shift;
3576
            $value =~ s/02/03/g;
3577
            return $value;
3578
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3579
    ]
3580
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3581
$result = $dbi->execute(
3582
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3583
    param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
3584
    table => $table1
3585
);
3586
$row = $result->one;
3587
like($row->{$key1}, qr/^2010-01-03/);
3588
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3589

            
3590
$dbi = DBIx::Custom->connect;
3591
eval { $dbi->execute("drop table $table1") };
3592
$dbi->execute($create_table1_type);
3593
$dbi->register_filter(convert => sub {
3594
    my $value = shift || '';
3595
    $value =~ s/02/03/;
3596
    return $value;
3597
});
cleanup
Yuki Kimoto authored on 2011-08-16
3598
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3599
$dbi->type_rule(
3600
    from1 => {
3601
        $date_datatype => 'convert',
3602
    },
3603
    into1 => {
3604
        $date_typename => 'convert',
3605
    }
3606
);
3607
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3608
$result = $dbi->select(table => $table1);
3609
like($result->fetch->[0], qr/^2010-03-03/);
3610

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

            
3636

            
3637
$dbi = DBIx::Custom->connect;
3638
eval { $dbi->execute("drop table $table1") };
3639
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3640
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3641
$dbi->type_rule(
3642
    from1 => {
3643
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3644
    },
3645
    from2 => {
3646
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3647
    },
3648
);
3649
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3650
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3651
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3652
$result->type_rule(
3653
    from1 => {
3654
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3655
    },
3656
    from2 => {
3657
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3658
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3659
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3660
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3661
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3662

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3663
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
3664
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
3665
eval { $dbi->execute("drop table $table1") };
3666
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3667
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3668
$dbi->type_rule(
3669
    from1 => {
3670
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3671
    },
3672
    into1 => {
3673
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3674
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3675
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3676
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3677
$result = $dbi->select(table => $table1, type_rule_off => 1);
3678
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3679

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3680
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3681
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3682
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3683
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3684
$dbi->type_rule(
3685
    from1 => {
3686
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3687
    },
3688
    into1 => {
3689
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3690
    }
3691
);
3692
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3693
$result = $dbi->select(table => $table1, type_rule_off => 1);
3694
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3695

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3742
eval{$dbi->type_rule(
3743
    into1 => {
3744
        $date_typename => 'pp'
3745
    }
3746
)};
3747
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3748

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3749
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3750
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3751
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3752
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3753
    $dbi->type_rule(
3754
        from1 => {
3755
            Date => sub { $_[0] * 2 },
3756
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3757
    );
3758
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3759
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3760

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3761
eval {
3762
    $dbi->type_rule(
3763
        into1 => {
3764
            Date => sub { $_[0] * 2 },
3765
        }
3766
    );
3767
};
3768
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3769

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

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

            
3808
$result = $dbi->select(table => $table1);
3809
$result->type_rule(
3810
    from1 => {
3811
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3812
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3813
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3814
$row = $result->one;
3815
like($row->{$key1}, qr/2010-01-05/);
3816
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3817

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

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

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

            
3845
$result = $dbi->select(table => $table1);
3846
$result->type_rule(
3847
    from1 => [$date_datatype => undef]
3848
);
3849
$row = $result->one;
3850
like($row->{$key1}, qr/^2010-01-03/);
3851
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3852

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

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

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
3953
test 'join';
3954
$dbi = DBIx::Custom->connect;
3955
eval { $dbi->execute("drop table $table1") };
3956
$dbi->execute($create_table1);
3957
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3958
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
3959
eval { $dbi->execute("drop table $table2") };
3960
$dbi->execute($create_table2);
3961
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3962
eval { $dbi->execute("drop table $table3") };
3963
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
3964
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
3965
$rows = $dbi->select(
3966
    table => $table1,
3967
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3968
    where   => {"$table1.$key2" => 2},
3969
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
3970
)->all;
3971
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
3972

            
3973
$rows = $dbi->select(
3974
    table => $table1,
3975
    where   => {$key1 => 1},
3976
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
3977
)->all;
3978
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
3979

            
3980
eval {
3981
    $rows = $dbi->select(
3982
        table => $table1,
3983
        column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3984
        where   => {"$table1.$key2" => 2},
3985
        join  => {"$table1.$key1" => "$table2.$key1"}
3986
    );
3987
};
3988
like ($@, qr/array/);
3989

            
3990
$rows = $dbi->select(
3991
    table => $table1,
3992
    where   => {$key1 => 1},
3993
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3994
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
3995
)->all;
3996
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
3997

            
3998
$rows = $dbi->select(
3999
    column => "$table3.$key4 as ${table3}__$key4",
4000
    table => $table1,
4001
    where   => {"$table1.$key1" => 1},
4002
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4003
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4004
)->all;
4005
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4006

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

            
4016
$dbi = DBIx::Custom->connect;
4017
eval { $dbi->execute("drop table $table1") };
4018
$dbi->execute($create_table1);
4019
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4020
eval { $dbi->execute("drop table $table2") };
4021
$dbi->execute($create_table2);
4022
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4023
$rows = $dbi->select(
4024
    table => $table1,
4025
    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",
4026
    where   => {"$table1.$key2" => 2},
4027
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4028
)->all;
4029
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4030
          'quote');
4031

            
4032

            
4033
$dbi = DBIx::Custom->connect;
4034
eval { $dbi->execute("drop table $table1") };
4035
$dbi->execute($create_table1);
4036
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4037
$sql = <<"EOS";
4038
left outer join (
4039
  select * from $table1 t1
4040
  where t1.$key2 = (
4041
    select max(t2.$key2) from $table1 t2
4042
    where t1.$key1 = t2.$key1
4043
  )
4044
) $table3 on $table1.$key1 = $table3.$key1
4045
EOS
4046
$join = [$sql];
4047
$rows = $dbi->select(
4048
    table => $table1,
4049
    column => "$table3.$key1 as ${table3}__$key1",
4050
    join  => $join
4051
)->all;
4052
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4053

            
4054
$dbi = DBIx::Custom->connect;
4055
eval { $dbi->execute("drop table $table1") };
4056
eval { $dbi->execute("drop table $table2") };
4057
$dbi->execute($create_table1);
4058
$dbi->execute($create_table2);
4059
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4060
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4061
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4062
$result = $dbi->select(
4063
    table => $table1,
4064
    join => [
4065
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4066
    ]
4067
);
4068
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4069
$result = $dbi->select(
4070
    table => $table1,
4071
    column => [{$table2 => [$key3]}],
4072
    join => [
4073
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4074
    ]
4075
);
4076
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4077
$result = $dbi->select(
4078
    table => $table1,
4079
    column => [{$table2 => [$key3]}],
4080
    join => [
4081
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4082
    ]
4083
);
4084
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4085

            
4086
$dbi = DBIx::Custom->connect;
4087
eval { $dbi->execute("drop table $table1") };
4088
eval { $dbi->execute("drop table $table2") };
4089
$dbi->execute($create_table1);
4090
$dbi->execute($create_table2);
4091
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4092
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4093
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4094
$result = $dbi->select(
4095
    table => $table1,
4096
    column => [{$table2 => [$key3]}],
4097
    join => [
4098
        {
4099
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4100
            table => [$table1, $table2]
4101
        }
4102
    ]
4103
);
4104
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4105

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4106
$dbi = DBIx::Custom->connect;
4107
eval { $dbi->execute("drop table $table1") };
4108
eval { $dbi->execute("drop table $table2") };
4109
$dbi->execute($create_table1);
4110
$dbi->execute($create_table2);
4111
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4112
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4113
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4114
$result = $dbi->select(
4115
    table => $table1,
4116
    column => [{$table2 => [$key3]}],
4117
    join => [
4118
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4119
    ]
4120
);
4121
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4122

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4140
test 'columns';
4141
$dbi = MyDBI1->connect;
4142
$model = $dbi->model($table1);
4143

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4144
test 'count';
4145
$dbi = DBIx::Custom->connect;
4146
eval { $dbi->execute("drop table $table1") };
4147
$dbi->execute($create_table1);
4148
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4149
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 3});
4150
is($dbi->count(table => $table1), 2);
4151
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4152
$model = $dbi->create_model(table => $table1);
4153
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4154

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