DBIx-Custom / t / common.t /
Newer Older
4099 lines | 137.434kb
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

            
1732
test 'dbi_option';
1733
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
1734
ok($dbi->dbh->{PrintError});
1735
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
1736
ok($dbi->dbh->{PrintError});
1737

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1989

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

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

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

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

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

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

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

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

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

            
2102
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2103
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2104
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2105
];
2106
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2107
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
2108

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

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

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

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

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

            
2185

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

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

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

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

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

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

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

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

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

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

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

            
2322

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

            
2338

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

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

            
2359

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

            
2378

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

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

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

            
2418

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

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

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

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

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

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

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

            
2514

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

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

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

            
2541

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2900
test 'result';
2901
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2902
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2903
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2904
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2905
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2906

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2907
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2908
@rows = ();
2909
while (my $row = $result->fetch) {
2910
    push @rows, [@$row];
2911
}
2912
is_deeply(\@rows, [[1, 2], [3, 4]]);
2913

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2914
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2915
@rows = ();
2916
while (my $row = $result->fetch_hash) {
2917
    push @rows, {%$row};
2918
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2919
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2920

            
2921
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2922
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2923
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2924
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2925
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2926

            
2927
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2928
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2929
$rows = $result->fetch_all;
2930
is_deeply($rows, [[1, 2], [3, 4]]);
2931

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

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

            
2940
$rows = $result->fetch_all;
2941
is_deeply($rows, [[3, 2], [9, 4]], "array");
2942

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

            
2949
test "query_builder";
2950
$datas = [
2951
    # Basic tests
2952
    {   name            => 'placeholder basic',
2953
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
2954
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
2955
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
2956
    },
2957
    {
2958
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
2959
        source            => "{in k1 3}",
2960
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
2961
        columns_expected   => [qw/k1 k1 k1/]
2962
    },
2963
    
2964
    # Table name
2965
    {
2966
        name            => 'placeholder with table name',
2967
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
2968
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
2969
        columns_expected  => [qw/a.k1 a.k2/]
2970
    },
2971
    {   
2972
        name            => 'placeholder in with table name',
2973
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
2974
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
2975
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
2976
    },
2977
    {
2978
        name            => 'not contain tag',
2979
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
2980
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
2981
        columns_expected  => [],
2982
    }
2983
];
2984

            
2985
for (my $i = 0; $i < @$datas; $i++) {
2986
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
2987
    my $dbi = DBIx::Custom->new;
2988
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
2989
    my $query = $builder->build_query($data->{source});
2990
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
2991
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
2992
}
2993

            
cleanup
Yuki Kimoto authored on 2011-08-13
2994
$dbi = DBIx::Custom->new;
2995
$builder = $dbi->query_builder;
2996
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
2997
    p => sub {
2998
        my @args = @_;
2999
        
3000
        my $expand    = "? $args[0] $args[1]";
3001
        my $columns = [2];
3002
        return [$expand, $columns];
3003
    }
3004
);
3005

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3016
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3017
    q => 'string'
3018
});
3019

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3023
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3024
   r => sub {} 
3025
});
3026

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3030
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3031
   s => sub { return ["a", ""]} 
3032
});
3033

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3037
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3038
    t => sub {return ["a", []]}
3039
);
3040

            
3041

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

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

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

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

            
3057
test 'variouse source';
3058
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3059
$query = $builder->build_query($source);
3060
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3061

            
3062
$source = "abc";
3063
$query = $builder->build_query($source);
3064
is($query->sql, 'abc', "basic : 2");
3065

            
3066
$source = "{= a}";
3067
$query = $builder->build_query($source);
3068
is($query->sql, 'a = ?', "only tag");
3069

            
3070
$source = "000";
3071
$query = $builder->build_query($source);
3072
is($query->sql, '000', "contain 0 value");
3073

            
3074
$source = "a {= b} }";
3075
eval{$builder->build_query($source)};
3076
like($@, qr/unexpected "}"/, "error : 1");
3077

            
3078
$source = "a {= {}";
3079
eval{$builder->build_query($source)};
3080
like($@, qr/unexpected "{"/, "error : 2");
3081

            
3082
test 'select() sqlfilter option';
3083
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3084
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3085
eval { $dbi->execute("drop table $table1") };
3086
$dbi->execute($create_table1);
3087
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3088
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3089
$rows = $dbi->select(
3090
    table => $table1,
3091
    column => $key1,
3092
    sqlfilter => sub {
3093
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
3094
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
3095
        return $sql;
3096
    }
3097
)->all;
3098
is_deeply($rows, [{$key1 => 1}]);
3099

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3100
test 'select() after_build_sql option';
3101
$dbi = DBIx::Custom->connect;
3102
$dbi->user_table_info($user_table_info);
3103
eval { $dbi->execute("drop table $table1") };
3104
$dbi->execute($create_table1);
3105
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3106
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3107
$rows = $dbi->select(
3108
    table => $table1,
3109
    column => $key1,
3110
    after_build_sql => sub {
3111
        my $sql = shift;
3112
        $sql = "select * from ( $sql ) t where $key1 = 1";
3113
        return $sql;
3114
    }
3115
)->all;
3116
is_deeply($rows, [{$key1 => 1}]);
3117

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3118
test 'dbi method from model';
3119
$dbi = MyDBI9->connect;
3120
eval { $dbi->execute("drop table $table1") };
3121
$dbi->execute($create_table1);
3122
$dbi->setup_model;
3123
$model = $dbi->model($table1);
3124
eval{$model->execute("select * from $table1")};
3125
ok(!$@);
3126

            
3127
test 'column table option';
3128
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3129
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3130
eval { $dbi->execute("drop table $table1") };
3131
$dbi->execute($create_table1);
3132
eval { $dbi->execute("drop table $table2") };
3133
$dbi->execute($create_table2);
3134
$dbi->setup_model;
3135
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3136
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3137
$model = $dbi->model($table1);
3138
$result = $model->select(
3139
    column => [
3140
        $model->column($table2, {alias => $table2_alias})
3141
    ],
3142
    where => {"$table2_alias.$key3" => 4}
3143
);
3144
is_deeply($result->one, 
3145
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3146

            
3147
$dbi->separator('__');
3148
$result = $model->select(
3149
    column => [
3150
        $model->column($table2, {alias => $table2_alias})
3151
    ],
3152
    where => {"$table2_alias.$key3" => 4}
3153
);
3154
is_deeply($result->one, 
3155
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3156

            
3157
$dbi->separator('-');
3158
$result = $model->select(
3159
    column => [
3160
        $model->column($table2, {alias => $table2_alias})
3161
    ],
3162
    where => {"$table2_alias.$key3" => 4}
3163
);
3164
is_deeply($result->one, 
3165
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3166

            
3167
test 'create_model';
3168
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3169
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3170
eval { $dbi->execute("drop table $table1") };
3171
eval { $dbi->execute("drop table $table2") };
3172
$dbi->execute($create_table1);
3173
$dbi->execute($create_table2);
3174

            
3175
$dbi->create_model(
3176
    table => $table1,
3177
    join => [
3178
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3179
    ],
3180
    primary_key => [$key1]
3181
);
3182
$model2 = $dbi->create_model(
3183
    table => $table2
3184
);
3185
$dbi->create_model(
3186
    table => $table3,
3187
    filter => [
3188
        $key1 => {in => sub { uc $_[0] }}
3189
    ]
3190
);
3191
$dbi->setup_model;
3192
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3193
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3194
$model = $dbi->model($table1);
3195
$result = $model->select(
3196
    column => [$model->mycolumn, $model->column($table2)],
3197
    where => {"$table1.$key1" => 1}
3198
);
3199
is_deeply($result->one,
3200
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3201
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3202

            
3203
test 'model method';
3204
$dbi = DBIx::Custom->connect;
3205
eval { $dbi->execute("drop table $table2") };
3206
$dbi->execute($create_table2);
3207
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3208
$model = $dbi->create_model(
3209
    table => $table2
3210
);
3211
$model->method(foo => sub { shift->select(@_) });
3212
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
3213

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3214
test 'assign_clause';
cleanup test
Yuki Kimoto authored on 2011-08-15
3215
$dbi = DBIx::Custom->connect;
3216
eval { $dbi->execute("drop table $table1") };
3217
$dbi->execute($create_table1_2);
3218
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3219
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3220

            
3221
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3222
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3223
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3224
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3225
where $key1 = 1
3226
EOS
3227
$dbi->execute($sql, param => $param);
3228
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3229
$rows   = $result->all;
3230
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3231
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3232
                  "basic");
3233

            
3234

            
3235
$dbi = DBIx::Custom->connect;
3236
eval { $dbi->execute("drop table $table1") };
3237
$dbi->execute($create_table1_2);
3238
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3239
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3240

            
3241
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3242
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3243
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3244
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3245
where $key1 = 1
3246
EOS
3247
$dbi->execute($sql, param => $param);
3248
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3249
$rows   = $result->all;
3250
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3251
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3252
                  "basic");
3253

            
3254
$dbi = DBIx::Custom->connect;
3255
eval { $dbi->execute("drop table $table1") };
3256
$dbi->execute($create_table1_2);
3257
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3258
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3259

            
3260
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3261
$assign_clause = $dbi->update_param($param, {no_set => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
3262
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3263
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3264
where $key1 = 1
3265
EOS
3266
$dbi->execute($sql, param => $param);
3267
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3268
$rows   = $result->all;
3269
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3270
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3271
                  "update param no_set");
3272

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

            
3277
$dbi = DBIx::Custom->connect;
3278
eval { $dbi->execute("drop table $table1") };
3279
$dbi->execute($create_table1_2);
3280
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3281
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3282

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3309
test 'Model class';
3310
$dbi = MyDBI1->connect;
3311
eval { $dbi->execute("drop table $table1") };
3312
$dbi->execute($create_table1);
3313
$model = $dbi->model($table1);
3314
$model->insert({$key1 => 'a', $key2 => 'b'});
3315
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3316
eval { $dbi->execute("drop table $table2") };
3317
$dbi->execute($create_table2);
3318
$model = $dbi->model($table2);
3319
$model->insert({$key1 => 'a'});
3320
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3321
is($dbi->models->{$table1}, $dbi->model($table1));
3322
is($dbi->models->{$table2}, $dbi->model($table2));
3323

            
3324
$dbi = MyDBI4->connect;
3325
eval { $dbi->execute("drop table $table1") };
3326
$dbi->execute($create_table1);
3327
$model = $dbi->model($table1);
3328
$model->insert({$key1 => 'a', $key2 => 'b'});
3329
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3330
eval { $dbi->execute("drop table $table2") };
3331
$dbi->execute($create_table2);
3332
$model = $dbi->model($table2);
3333
$model->insert({$key1 => 'a'});
3334
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3335

            
3336
$dbi = MyDBI5->connect;
3337
eval { $dbi->execute("drop table $table1") };
3338
eval { $dbi->execute("drop table $table2") };
3339
$dbi->execute($create_table1);
3340
$dbi->execute($create_table2);
3341
$model = $dbi->model($table2);
3342
$model->insert({$key1 => 'a'});
3343
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3344
$dbi->insert(table => $table1, param => {$key1 => 1});
3345
$model = $dbi->model($table1);
3346
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3347

            
3348
test 'primary_key';
3349
$dbi = MyDBI1->connect;
3350
$model = $dbi->model($table1);
3351
$model->primary_key([$key1, $key2]);
3352
is_deeply($model->primary_key, [$key1, $key2]);
3353

            
3354
test 'columns';
3355
$dbi = MyDBI1->connect;
3356
$model = $dbi->model($table1);
3357
$model->columns([$key1, $key2]);
3358
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3359

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3360
test 'setup_model';
3361
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3362
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3363
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3364
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3365

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3366
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3367
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3368
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3369
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3370
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3371

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3372
test 'each_column';
3373
$dbi = DBIx::Custom->connect;
3374
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3375
eval { $dbi->execute("drop table $table1") };
3376
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3377
eval { $dbi->execute("drop table $table3") };
3378
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3379
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3380

            
3381
$infos = [];
3382
$dbi->each_column(sub {
3383
    my ($self, $table, $column, $cinfo) = @_;
3384
    
3385
    if ($table =~ /^table\d/i) {
3386
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3387
         push @$infos, $info;
3388
    }
3389
});
3390
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3391
is_deeply($infos, 
3392
    [
3393
        [$table1, $key1, $key1],
3394
        [$table1, $key2, $key2],
3395
        [$table2, $key1, $key1],
3396
        [$table2, $key3, $key3]
3397
    ]
3398
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3399
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3400

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3401
test 'each_table';
3402
$dbi = DBIx::Custom->connect;
3403
eval { $dbi->execute("drop table $table1") };
3404
eval { $dbi->execute("drop table $table2") };
3405
$dbi->execute($create_table2);
3406
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3407

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3408
$infos = [];
3409
$dbi->each_table(sub {
3410
    my ($self, $table, $table_info) = @_;
3411
    
3412
    if ($table =~ /^table\d/i) {
3413
         my $info = [$table, $table_info->{TABLE_NAME}];
3414
         push @$infos, $info;
3415
    }
3416
});
3417
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3418
is_deeply($infos, 
3419
    [
3420
        [$table1, $table1],
3421
        [$table2, $table2],
3422
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3423
);
3424

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3425
$dbi = DBIx::Custom->connect;
3426
eval { $dbi->execute("drop table $table1") };
3427
eval { $dbi->execute("drop table $table2") };
3428
$dbi->execute($create_table2);
3429
$dbi->execute($create_table1_type);
3430

            
3431
$infos = [];
3432
$dbi->user_table_info($user_table_info);
3433
$dbi->each_table(sub {
3434
    my ($self, $table, $table_info) = @_;
3435
    
3436
    if ($table =~ /^table\d/i) {
3437
         my $info = [$table, $table_info->{TABLE_NAME}];
3438
         push @$infos, $info;
3439
    }
3440
});
3441
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3442
is_deeply($infos, 
3443
    [
3444
        [$table1, $table1],
3445
        [$table2, $table2],
3446
        [$table3, $table3],
3447
    ]
3448
);
3449

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3450
test 'type_rule into';
3451
eval { $dbi->execute("drop table $table1") };
3452
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3453
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3454

            
3455

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3456
$dbi = DBIx::Custom->connect;
3457
eval { $dbi->execute("drop table $table1") };
3458
$dbi->execute($create_table1_type);
3459

            
cleanup
Yuki Kimoto authored on 2011-08-16
3460
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3461
$dbi->type_rule(
3462
    into1 => {
3463
        $date_typename => sub { '2010-' . $_[0] }
3464
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3465
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3466
$dbi->insert({$key1 => '01-01'}, table => $table1);
3467
$result = $dbi->select(table => $table1);
3468
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3469

            
3470
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3471
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3472
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3473
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3474
$dbi->type_rule(
3475
    into1 => [
3476
         [$date_typename, $datetime_typename] => sub {
3477
            my $value = shift;
3478
            $value =~ s/02/03/g;
3479
            return $value;
3480
         }
3481
    ]
3482
);
3483
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3484
$result = $dbi->select(table => $table1);
3485
$row = $result->one;
3486
like($row->{$key1}, qr/^2010-01-03/);
3487
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3488

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3489
$dbi = DBIx::Custom->connect;
3490
eval { $dbi->execute("drop table $table1") };
3491
$dbi->execute($create_table1_type);
3492
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3493
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3494
$dbi->type_rule(
3495
    into1 => [
3496
        [$date_typename, $datetime_typename] => sub {
3497
            my $value = shift;
3498
            $value =~ s/02/03/g;
3499
            return $value;
3500
        }
3501
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3502
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3503
$result = $dbi->execute(
3504
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3505
    param => {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
3506
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3507
$row = $result->one;
3508
like($row->{$key1}, qr/^2010-01-03/);
3509
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3510

            
3511
$dbi = DBIx::Custom->connect;
3512
eval { $dbi->execute("drop table $table1") };
3513
$dbi->execute($create_table1_type);
3514
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3515
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3516
$dbi->type_rule(
3517
    into1 => [
3518
        [$date_typename, $datetime_typename] => sub {
3519
            my $value = shift;
3520
            $value =~ s/02/03/g;
3521
            return $value;
3522
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3523
    ]
3524
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3525
$result = $dbi->execute(
3526
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3527
    param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
3528
    table => $table1
3529
);
3530
$row = $result->one;
3531
like($row->{$key1}, qr/^2010-01-03/);
3532
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3533

            
3534
$dbi = DBIx::Custom->connect;
3535
eval { $dbi->execute("drop table $table1") };
3536
$dbi->execute($create_table1_type);
3537
$dbi->register_filter(convert => sub {
3538
    my $value = shift || '';
3539
    $value =~ s/02/03/;
3540
    return $value;
3541
});
cleanup
Yuki Kimoto authored on 2011-08-16
3542
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3543
$dbi->type_rule(
3544
    from1 => {
3545
        $date_datatype => 'convert',
3546
    },
3547
    into1 => {
3548
        $date_typename => 'convert',
3549
    }
3550
);
3551
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3552
$result = $dbi->select(table => $table1);
3553
like($result->fetch->[0], qr/^2010-03-03/);
3554

            
3555
test 'type_rule and filter order';
3556
$dbi = DBIx::Custom->connect;
3557
eval { $dbi->execute("drop table $table1") };
3558
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3559
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3560
$dbi->type_rule(
3561
    into1 => {
3562
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3563
    },
3564
    into2 => {
3565
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3566
    },
3567
    from1 => {
3568
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3569
    },
3570
    from2 => {
3571
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
3572
    }
3573
);
3574
$dbi->insert({$key1 => '2010-01-03'}, 
3575
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
3576
$result = $dbi->select(table => $table1);
3577
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3578
like($result->fetch_first->[0], qr/^2010-01-09/);
3579

            
3580

            
3581
$dbi = DBIx::Custom->connect;
3582
eval { $dbi->execute("drop table $table1") };
3583
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3584
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3585
$dbi->type_rule(
3586
    from1 => {
3587
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3588
    },
3589
    from2 => {
3590
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3591
    },
3592
);
3593
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3594
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3595
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3596
$result->type_rule(
3597
    from1 => {
3598
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3599
    },
3600
    from2 => {
3601
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3602
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3603
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3604
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3605
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3606

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3607
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
3608
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
3609
eval { $dbi->execute("drop table $table1") };
3610
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3611
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3612
$dbi->type_rule(
3613
    from1 => {
3614
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3615
    },
3616
    into1 => {
3617
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3618
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3619
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3620
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3621
$result = $dbi->select(table => $table1, type_rule_off => 1);
3622
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3623

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3624
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3625
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3626
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3627
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3628
$dbi->type_rule(
3629
    from1 => {
3630
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3631
    },
3632
    into1 => {
3633
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3634
    }
3635
);
3636
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3637
$result = $dbi->select(table => $table1, type_rule_off => 1);
3638
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3639

            
3640
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3641
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3642
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3643
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3644
$dbi->type_rule(
3645
    from1 => {
3646
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3647
    },
3648
    into1 => {
3649
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3650
    }
3651
);
3652
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3653
$result = $dbi->select(table => $table1);
3654
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3655

            
3656
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3657
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3658
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3659
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3660
$dbi->type_rule(
3661
    from1 => {
3662
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3663
    },
3664
    into1 => {
3665
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3666
    }
3667
);
3668
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3669
$result = $dbi->select(table => $table1);
3670
like($result->fetch->[0], qr/2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3671

            
3672
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3673
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3674
$dbi->execute($create_table1_type);
3675
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
3676
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3677
$dbi->type_rule(
3678
    into1 => {
3679
        $date_typename => 'ppp'
3680
    }
3681
);
3682
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3683
$result = $dbi->select(table => $table1);
3684
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3685

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3686
eval{$dbi->type_rule(
3687
    into1 => {
3688
        $date_typename => 'pp'
3689
    }
3690
)};
3691
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3692

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3693
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3694
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3695
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3696
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3697
    $dbi->type_rule(
3698
        from1 => {
3699
            Date => sub { $_[0] * 2 },
3700
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3701
    );
3702
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3703
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3704

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3705
eval {
3706
    $dbi->type_rule(
3707
        into1 => {
3708
            Date => sub { $_[0] * 2 },
3709
        }
3710
    );
3711
};
3712
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3713

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

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

            
3752
$result = $dbi->select(table => $table1);
3753
$result->type_rule(
3754
    from1 => {
3755
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3756
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3757
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3758
$row = $result->one;
3759
like($row->{$key1}, qr/2010-01-05/);
3760
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3761

            
3762
$result = $dbi->select(table => $table1);
3763
$result->type_rule(
3764
    from1 => {
3765
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3766
    }
3767
);
3768
$row = $result->one;
3769
like($row->{$key1}, qr/2010-01-05/);
3770
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3771

            
3772
$result = $dbi->select(table => $table1);
3773
$result->type_rule(
3774
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
3775
);
3776
$row = $result->one;
3777
like($row->{$key1}, qr/2010-01-05/);
3778
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3779

            
3780
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
3781
$result = $dbi->select(table => $table1);
3782
$result->type_rule(
3783
    from1 => [$date_datatype => 'five']
3784
);
3785
$row = $result->one;
3786
like($row->{$key1}, qr/^2010-01-05/);
3787
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3788

            
3789
$result = $dbi->select(table => $table1);
3790
$result->type_rule(
3791
    from1 => [$date_datatype => undef]
3792
);
3793
$row = $result->one;
3794
like($row->{$key1}, qr/^2010-01-03/);
3795
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3796

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3811
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3812
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3813
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3814
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3815
$dbi->type_rule(
3816
    from1 => {
3817
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3818
    },
3819
);
3820
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3821
$result = $dbi->select(table => $table1);
3822
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3823
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3824

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
3897
test 'join';
3898
$dbi = DBIx::Custom->connect;
3899
eval { $dbi->execute("drop table $table1") };
3900
$dbi->execute($create_table1);
3901
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3902
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
3903
eval { $dbi->execute("drop table $table2") };
3904
$dbi->execute($create_table2);
3905
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3906
eval { $dbi->execute("drop table $table3") };
3907
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
3908
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
3909
$rows = $dbi->select(
3910
    table => $table1,
3911
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3912
    where   => {"$table1.$key2" => 2},
3913
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
3914
)->all;
3915
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
3916

            
3917
$rows = $dbi->select(
3918
    table => $table1,
3919
    where   => {$key1 => 1},
3920
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
3921
)->all;
3922
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
3923

            
3924
eval {
3925
    $rows = $dbi->select(
3926
        table => $table1,
3927
        column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3928
        where   => {"$table1.$key2" => 2},
3929
        join  => {"$table1.$key1" => "$table2.$key1"}
3930
    );
3931
};
3932
like ($@, qr/array/);
3933

            
3934
$rows = $dbi->select(
3935
    table => $table1,
3936
    where   => {$key1 => 1},
3937
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3938
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
3939
)->all;
3940
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
3941

            
3942
$rows = $dbi->select(
3943
    column => "$table3.$key4 as ${table3}__$key4",
3944
    table => $table1,
3945
    where   => {"$table1.$key1" => 1},
3946
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3947
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
3948
)->all;
3949
is_deeply($rows, [{"${table3}__$key4" => 4}]);
3950

            
3951
$rows = $dbi->select(
3952
    column => "$table1.$key1 as ${table1}__$key1",
3953
    table => $table1,
3954
    where   => {"$table3.$key4" => 4},
3955
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3956
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
3957
)->all;
3958
is_deeply($rows, [{"${table1}__$key1" => 1}]);
3959

            
3960
$dbi = DBIx::Custom->connect;
3961
eval { $dbi->execute("drop table $table1") };
3962
$dbi->execute($create_table1);
3963
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3964
eval { $dbi->execute("drop table $table2") };
3965
$dbi->execute($create_table2);
3966
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3967
$rows = $dbi->select(
3968
    table => $table1,
3969
    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",
3970
    where   => {"$table1.$key2" => 2},
3971
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
3972
)->all;
3973
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
3974
          'quote');
3975

            
3976

            
3977
$dbi = DBIx::Custom->connect;
3978
eval { $dbi->execute("drop table $table1") };
3979
$dbi->execute($create_table1);
3980
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3981
$sql = <<"EOS";
3982
left outer join (
3983
  select * from $table1 t1
3984
  where t1.$key2 = (
3985
    select max(t2.$key2) from $table1 t2
3986
    where t1.$key1 = t2.$key1
3987
  )
3988
) $table3 on $table1.$key1 = $table3.$key1
3989
EOS
3990
$join = [$sql];
3991
$rows = $dbi->select(
3992
    table => $table1,
3993
    column => "$table3.$key1 as ${table3}__$key1",
3994
    join  => $join
3995
)->all;
3996
is_deeply($rows, [{"${table3}__$key1" => 1}]);
3997

            
3998
$dbi = DBIx::Custom->connect;
3999
eval { $dbi->execute("drop table $table1") };
4000
eval { $dbi->execute("drop table $table2") };
4001
$dbi->execute($create_table1);
4002
$dbi->execute($create_table2);
4003
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4004
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4005
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4006
$result = $dbi->select(
4007
    table => $table1,
4008
    join => [
4009
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4010
    ]
4011
);
4012
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4013
$result = $dbi->select(
4014
    table => $table1,
4015
    column => [{$table2 => [$key3]}],
4016
    join => [
4017
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4018
    ]
4019
);
4020
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4021
$result = $dbi->select(
4022
    table => $table1,
4023
    column => [{$table2 => [$key3]}],
4024
    join => [
4025
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4026
    ]
4027
);
4028
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4029

            
4030
$dbi = DBIx::Custom->connect;
4031
eval { $dbi->execute("drop table $table1") };
4032
eval { $dbi->execute("drop table $table2") };
4033
$dbi->execute($create_table1);
4034
$dbi->execute($create_table2);
4035
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4036
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4037
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4038
$result = $dbi->select(
4039
    table => $table1,
4040
    column => [{$table2 => [$key3]}],
4041
    join => [
4042
        {
4043
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4044
            table => [$table1, $table2]
4045
        }
4046
    ]
4047
);
4048
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4049

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4050
$dbi = DBIx::Custom->connect;
4051
eval { $dbi->execute("drop table $table1") };
4052
eval { $dbi->execute("drop table $table2") };
4053
$dbi->execute($create_table1);
4054
$dbi->execute($create_table2);
4055
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4056
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4057
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4058
$result = $dbi->select(
4059
    table => $table1,
4060
    column => [{$table2 => [$key3]}],
4061
    join => [
4062
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4063
    ]
4064
);
4065
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4066

            
4067
$dbi = DBIx::Custom->connect;
4068
eval { $dbi->execute("drop table $table1") };
4069
eval { $dbi->execute("drop table $table2") };
4070
$dbi->execute($create_table1);
4071
$dbi->execute($create_table2);
4072
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4073
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4074
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4075
$result = $dbi->select(
4076
    table => $table1,
4077
    column => [{$table2 => [$key3]}],
4078
    join => [
4079
        "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4080
    ]
4081
);
4082
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4083

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4084
test 'columns';
4085
$dbi = MyDBI1->connect;
4086
$model = $dbi->model($table1);
4087

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4088
test 'count';
4089
$dbi = DBIx::Custom->connect;
4090
eval { $dbi->execute("drop table $table1") };
4091
$dbi->execute($create_table1);
4092
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4093
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 3});
4094
is($dbi->count(table => $table1), 2);
4095
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4096
$model = $dbi->create_model(table => $table1);
4097
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4098

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