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

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

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

            
14
plan 'no_plan';
15

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

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

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

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

            
88
    use strict;
89
    use warnings;
90

            
91
    use base 'DBIx::Custom';
92

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

            
104
    package MyModel2::Base1;
105

            
106
    use strict;
107
    use warnings;
108

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

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

            
113
    use strict;
114
    use warnings;
115

            
116
    use base 'MyModel2::Base1';
117

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

            
124
    sub list { shift->select; }
125

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

            
128
    use strict;
129
    use warnings;
130

            
131
    use base 'MyModel2::Base1';
132

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

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

            
141
    package MyModel2::TABLE1;
142

            
143
    use strict;
144
    use warnings;
145

            
146
    use base 'MyModel2::Base1';
147

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

            
154
    sub list { shift->select; }
155

            
156
    package MyModel2::TABLE2;
157

            
158
    use strict;
159
    use warnings;
160

            
161
    use base 'MyModel2::Base1';
162

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

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

            
174
    use strict;
175
    use warnings;
176

            
177
    use base 'DBIx::Custom';
178

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
734

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

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

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

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

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

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

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

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

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

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

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

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

            
830

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
968

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

            
974
$dbi->begin_work;
975

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

            
982
$dbi->rollback if $@;
983

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

            
988
$dbi->begin_work;
989

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

            
995
$dbi->commit unless $@;
996

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1595

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

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

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

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

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

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

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

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

            
1657
$dbi->apply_filter(
1658

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1991

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2187

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

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

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

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

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

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

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

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

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

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

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

            
2324

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

            
2340

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

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

            
2361

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

            
2380

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

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

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

            
2420

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

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

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

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

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

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

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

            
2516

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

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

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

            
2543

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3043

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3236

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3457

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

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

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

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

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

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

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

            
3582

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3978

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

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

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

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

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

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

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

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