DBIx-Custom / t / common.t /
Newer Older
4211 lines | 141.679kb
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;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
83
my $reuse;
cleanup test
Yuki Kimoto authored on 2011-08-15
84

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

            
89
    use strict;
90
    use warnings;
91

            
92
    use base 'DBIx::Custom';
93

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

            
105
    package MyModel2::Base1;
106

            
107
    use strict;
108
    use warnings;
109

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

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

            
114
    use strict;
115
    use warnings;
116

            
117
    use base 'MyModel2::Base1';
118

            
119
    sub insert {
120
        my ($self, $param) = @_;
121
        
cleanup
Yuki Kimoto authored on 2011-10-21
122
        return $self->SUPER::insert($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
123
    }
124

            
125
    sub list { shift->select; }
126

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

            
129
    use strict;
130
    use warnings;
131

            
132
    use base 'MyModel2::Base1';
133

            
134
    sub insert {
135
        my ($self, $param) = @_;
136
        
cleanup
Yuki Kimoto authored on 2011-10-21
137
        return $self->SUPER::insert($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
138
    }
139

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

            
142
    package MyModel2::TABLE1;
143

            
144
    use strict;
145
    use warnings;
146

            
147
    use base 'MyModel2::Base1';
148

            
149
    sub insert {
150
        my ($self, $param) = @_;
151
        
cleanup
Yuki Kimoto authored on 2011-10-21
152
        return $self->SUPER::insert($param);
test cleanup
Yuki Kimoto authored on 2011-08-15
153
    }
154

            
155
    sub list { shift->select; }
156

            
157
    package MyModel2::TABLE2;
158

            
159
    use strict;
160
    use warnings;
161

            
162
    use base 'MyModel2::Base1';
163

            
164
    sub insert {
165
        my ($self, $param) = @_;
166
        
cleanup
Yuki Kimoto authored on 2011-10-21
167
        return $self->SUPER::insert($param);
test cleanup
Yuki Kimoto authored on 2011-08-15
168
    }
169

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

            
175
    use strict;
176
    use warnings;
177

            
178
    use base 'DBIx::Custom';
179

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

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

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
241
test 'execute reuse option';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
242
eval { $dbi->execute("drop table $table1") };
243
$dbi->execute($create_table1);
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
244
$reuse = {};
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
245
for my $i (1 .. 2) {
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
246
  $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, reuse => $reuse);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
247
}
248
$rows = $dbi->select(table => $table1)->all;
249
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 1, $key2 => 2}]);
250

            
added test
Yuki Kimoto authored on 2011-08-16
251
# Get user table info
252
$dbi = DBIx::Custom->connect;
253
eval { $dbi->execute("drop table $table1") };
254
eval { $dbi->execute("drop table $table2") };
255
eval { $dbi->execute("drop table $table3") };
256
$dbi->execute($create_table1);
257
$dbi->execute($create_table2);
258
$dbi->execute($create_table3);
259
$user_table_info = $dbi->get_table_info(exclude => $dbi->exclude_table);
260

            
cleanup test
Yuki Kimoto authored on 2011-08-15
261
# Create table
test cleanup
Yuki Kimoto authored on 2011-08-10
262
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
263
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
264
$dbi->execute($create_table1);
265
$model = $dbi->create_model(table => $table1);
266
$model->insert({$key1 => 1, $key2 => 2});
267
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-08-15
268

            
cleanup test
Yuki Kimoto authored on 2011-08-15
269
test 'DBIx::Custom::Result test';
270
$dbi->delete_all(table => $table1);
271
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-10-21
272
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
273
$source = "select $key1, $key2 from $table1";
274
$query = $dbi->create_query($source);
275
$result = $dbi->execute($query);
cleanup
Yuki Kimoto authored on 2011-08-15
276

            
cleanup test
Yuki Kimoto authored on 2011-08-15
277
@rows = ();
278
while (my $row = $result->fetch) {
279
    push @rows, [@$row];
280
}
281
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
cleanup
Yuki Kimoto authored on 2011-08-15
282

            
cleanup test
Yuki Kimoto authored on 2011-08-15
283
$result = $dbi->execute($query);
284
@rows = ();
285
while (my $row = $result->fetch_hash) {
286
    push @rows, {%$row};
287
}
288
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
289

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
298
test 'Insert query return value';
299
$source = "insert into $table1 {insert_param $key1 $key2}";
300
$query = $dbi->execute($source, {}, query => 1);
301
$ret_val = $dbi->execute($query, param => {$key1 => 1, $key2 => 2});
302
ok($ret_val);
test cleanup
Yuki Kimoto authored on 2011-08-10
303

            
cleanup test
Yuki Kimoto authored on 2011-08-15
304
test 'Direct query';
305
$dbi->delete_all(table => $table1);
306
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
307
$dbi->execute($insert_source, param => {$key1 => 1, $key2 => 2});
308
$result = $dbi->execute("select * from $table1");
309
$rows = $result->all;
310
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
311

            
312
test 'Filter basic';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
313
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-08
314
$dbi->register_filter(twice       => sub { $_[0] * 2}, 
315
                    three_times => sub { $_[0] * 3});
316

            
cleanup test
Yuki Kimoto authored on 2011-08-15
317
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
318
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
319
$insert_query->filter({$key1 => 'twice'});
320
$dbi->execute($insert_query, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
321
$result = $dbi->execute("select * from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
322
$rows = $result->filter({$key2 => 'three_times'})->all;
323
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
324

            
325
test 'Filter in';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
326
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
327
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
328
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
329
$dbi->execute($insert_query, param => {$key1 => 2, $key2 => 4});
330
$select_source = "select * from $table1 where {in $table1.$key1 2} and {in $table1.$key2 2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
331
$select_query = $dbi->execute($select_source,{}, query => 1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
332
$select_query->filter({"$table1.$key1" => 'twice'});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
333
$result = $dbi->execute($select_query, param => {"$table1.$key1" => [1,5], "$table1.$key2" => [2,4]});
cleanup test
Yuki Kimoto authored on 2011-08-08
334
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
335
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
336

            
cleanup test
Yuki Kimoto authored on 2011-08-08
337
test 'DBIx::Custom::SQLTemplate basic tag';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
338
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
339
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
340
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
341
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
342

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

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

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

            
361
test 'DIB::Custom::SQLTemplate in tag';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
362
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
363
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
364
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
365
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
366

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-08
396
test 'Named placeholder';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
397
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
398
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
399
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
400
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
401

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
417
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
418
$result = $dbi->execute(
419
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
420
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
421
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
cleanup test
Yuki Kimoto authored on 2011-08-08
422
);
423
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
424
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
425

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
426
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
427
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
428
$dbi->insert(table => $table1, param => {$key1 => '2011-10-14 12:19:18', $key2 => 2});
429
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
430
$result = $dbi->execute(
431
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
432
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
433
);
434

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
439
$dbi->delete_all(table => $table1);
440
$dbi->insert(table => $table1, param => {$key1 => 'a:b c:d', $key2 => 2});
441
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
442
$result = $dbi->execute(
443
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
444
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
445
);
446
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
447
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
448

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
456
test 'insert';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
457
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
458
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
459
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
460
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
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 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
464

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
465
$dbi->execute("delete from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
466
$dbi->register_filter(
467
    twice       => sub { $_[0] * 2 },
468
    three_times => sub { $_[0] * 3 }
469
);
470
$dbi->default_bind_filter('twice');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
471
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => 'three_times'});
cleanup test
Yuki Kimoto authored on 2011-08-15
472
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
473
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
474
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-10
475
$dbi->default_bind_filter(undef);
476

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
477
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
478
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
479
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, append => '   ');
480
$rows = $dbi->select(table => $table1)->all;
481
is_deeply($rows, [{$key1 => 1, $key2 => 2}], 'insert append');
cleanup test
Yuki Kimoto authored on 2011-08-10
482

            
483
eval{$dbi->insert(table => 'table', param => {';' => 1})};
484
like($@, qr/safety/);
485

            
cleanup test
Yuki Kimoto authored on 2011-08-10
486
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
487
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
488
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
489
$dbi->insert(table => 'table', param => {select => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
490
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
491
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
492
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
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({$key1 => 1, $key2 => 2}, table => $table1);
497
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
502
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
503
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
504
$dbi->insert(table => $table1, param => {$key1 => \"'1'", $key2 => 2});
505
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
506
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
507
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
508
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
509

            
updated pod
Yuki Kimoto authored on 2011-09-02
510
eval { $dbi->execute("drop table $table1") };
511
$dbi->execute($create_table1);
512
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
513
  wrap => {$key1 => sub { "$_[0] - 1" }});
514
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
515
$result = $dbi->execute("select * from $table1");
516
$rows   = $result->all;
517
is_deeply($rows, [{$key1 => 0, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
518

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
529
eval { $dbi->execute("drop table $table1") };
530
$dbi->execute($create_table1);
531
$dbi->insert_timestamp(
532
    [$key1, $key2] => sub { 5 }
533
);
534
$dbi->insert(table => $table1, timestamp => 1);
535
$result = $dbi->execute("select * from $table1");
536
$rows   = $result->all;
537
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
538

            
539
eval { $dbi->execute("drop table $table1") };
540
$dbi->execute($create_table1);
541
$dbi->insert_timestamp(
542
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
543
);
544
$dbi->insert(table => $table1, timestamp => 1);
545
$result = $dbi->execute("select * from $table1");
546
$rows   = $result->all;
547
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
548

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
549
test 'update_or_insert';
550
eval { $dbi->execute("drop table $table1") };
551
$dbi->execute($create_table1);
552
$dbi->update_or_insert(
553
    {$key2 => 2},
554
    table => $table1,
555
    primary_key => $key1,
556
    id => 1
557
);
558
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
559
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
560

            
561
$dbi->update_or_insert(
562
    {$key2 => 3},
563
    table => $table1,
564
    primary_key => $key1,
565
    id => 1
566
);
567
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
568
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
569

            
570
eval { $dbi->execute("drop table $table1") };
571
$dbi->execute($create_table1);
572
$dbi->update_or_insert(
573
    {$key1 => 1, $key2 => 2},
574
    table => $table1,
575
    where => {$key1 => 1}
576
);
577
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
578
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
579

            
580

            
581
test 'default_bind_filter';
582
$dbi->execute("delete from $table1");
583
$dbi->register_filter(
584
    twice       => sub { $_[0] * 2 },
585
    three_times => sub { $_[0] * 3 }
586
);
587
$dbi->default_bind_filter('twice');
588
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => 'three_times'});
589
$result = $dbi->execute("select * from $table1");
590
$rows   = $result->all;
591
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
592
$dbi->default_bind_filter(undef);
593

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

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

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

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

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

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

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

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

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

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

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

            
691
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
692
like($@, qr/safety/);
693

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

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

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

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

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

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

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

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

            
784

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

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

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

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
838
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
839
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
840
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
841
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
842
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
843
$rows   = $result->all;
844
is_deeply($rows, [], "basic");
845

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

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

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

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

            
876

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

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

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

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

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

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

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

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

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

            
941
test 'filters';
942
$dbi = DBIx::Custom->new;
943

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
950
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
951
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
952
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
953
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
954
$dbi->begin_work;
955
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
956
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
957
$dbi->rollback;
958
$dbi->dbh->{AutoCommit} = 1;
959

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

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

            
964
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
965
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
966
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
967
$dbi->begin_work;
968
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
969
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
970
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
971
$dbi->commit;
972
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
973
$result = $dbi->select(table => $table1);
974
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
975
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
976

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

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

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

            
1008

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1009
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1010
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1011
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1012
$dbi->execute($create_table1);
1013

            
1014
$dbi->begin_work;
1015

            
1016
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1017
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1018
    die "Error";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1019
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1020
};
1021

            
1022
$dbi->rollback if $@;
1023

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

            
1028
$dbi->begin_work;
1029

            
1030
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1031
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1032
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1033
};
1034

            
1035
$dbi->commit unless $@;
1036

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

            
1041
$dbi->dbh->{AutoCommit} = 0;
1042
eval{ $dbi->begin_work };
1043
ok($@, "exception");
1044
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1045

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1046
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1047
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1048
$dbi->cache(1);
1049
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1050
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1051
$dbi->execute($source, {}, query => 1);
1052
is_deeply($dbi->{_cached}->{$source}, 
cleanup test
Yuki Kimoto authored on 2011-08-15
1053
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1054

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

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

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

            
1082
{
1083
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1084
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1085
    like($@, qr/\Q.t /, "caller spec : not vebose");
1086
}
1087
{
1088
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1089
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1090
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1091
}
1092

            
1093
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1094
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1095
    one => sub { 1 }
1096
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1097
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1098
    two => sub { 2 }
1099
);
1100
$dbi->method({
1101
    twice => sub {
1102
        my $self = shift;
1103
        return $_[0] * 2;
1104
    }
1105
});
1106

            
1107
is($dbi->one, 1, "first");
1108
is($dbi->two, 2, "second");
1109
is($dbi->twice(5), 10 , "second");
1110

            
1111
eval {$dbi->XXXXXX};
1112
ok($@, "not exists");
1113

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

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

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

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

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

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

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

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

            
1233
$result->filter({$key2 => 'twice'});
1234
$rows   = $result->all;
1235
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1236

            
1237
$result = $dbi->select(
1238
     table => [$table1, $table2],
1239
     column => [$key2, $key3],
1240
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1241

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

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

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

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

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

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

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

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

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

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

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

            
1340
test 'empty where select';
1341
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1342
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1343
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1344
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1345
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1346
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1347
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1348

            
1349
test 'select query option';
1350
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1351
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1352
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1353
$query = $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1354
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1355
$query = $dbi->update(table => $table1, where => {$key1 => 1}, param => {$key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1356
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1357
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1358
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1359
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1360
is(ref $query, 'DBIx::Custom::Query');
1361

            
1362
test 'where';
1363
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1364
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1365
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1366
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1367
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1368
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1369
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1370

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

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

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

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

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

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

            
1422
$where = $dbi->where;
1423
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1424
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1425
    where => $where
1426
);
1427
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1428
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1429

            
1430
eval {
1431
$where = $dbi->where
1432
             ->clause(['uuu']);
1433
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1434
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1435
    where => $where
1436
);
1437
};
1438
ok($@);
1439

            
1440
$where = $dbi->where;
1441
is("$where", '');
1442

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

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

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

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

            
1483
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1484
             ->clause("$key1 = :$key1 $key2 = :$key2")
1485
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1486
eval{$where->to_string};
1487
like($@, qr/one column/);
1488

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

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

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

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

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

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

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

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

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

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

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

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

            
1609
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1610
             ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1611
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1612
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1613
    where => $where,
1614
);
1615
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1616
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1617

            
1618
eval {$dbi->where(ppp => 1) };
1619
like($@, qr/invalid/);
1620

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

            
1632

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

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

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

            
1661
test 'register_tag_processor';
1662
$dbi = DBIx::Custom->connect;
1663
$dbi->register_tag_processor(
1664
    a => sub { 1 }
1665
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1666
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1667

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

            
1675
test 'table not specify exception';
1676
$dbi = DBIx::Custom->connect;
1677
eval {$dbi->select};
1678
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1679

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1680
test 'more tests';
1681
$dbi = DBIx::Custom->connect;
1682
eval{$dbi->apply_filter('table', 'column', [])};
1683
like($@, qr/apply_filter/);
1684

            
1685
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1686
like($@, qr/apply_filter/);
1687

            
1688
$dbi->apply_filter(
1689

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

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

            
1710
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1711
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1712
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1713
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1714
like($@, qr/not registered/);
1715
$dbi->method({one => sub { 1 }});
1716
is($dbi->one, 1);
1717

            
1718
eval{DBIx::Custom->connect(dsn => undef)};
1719
like($@, qr/_connect/);
1720

            
1721
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1722
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1723
$dbi->execute($create_table1);
1724
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1725
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1726
             filter => {$key1 => 'twice'});
1727
$row = $dbi->select(table => $table1)->one;
1728
is_deeply($row, {$key1 => 2, $key2 => 2});
1729
eval {$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1730
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
1731
like($@, qr//);
1732

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

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

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1763
test 'option';
1764
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
1765
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
1766
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
1767
ok($dbi->dbh->{PrintError});
1768
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
1769
ok($dbi->dbh->{PrintError});
1770

            
1771
test 'DBIx::Custom::Result stash()';
1772
$result = DBIx::Custom::Result->new;
1773
is_deeply($result->stash, {}, 'default');
1774
$result->stash->{foo} = 1;
1775
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
1776

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1789
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1790
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1791
    table => $table1,
1792
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1793
    where => 1,
1794
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1795
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1796

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1811
$dbi->delete_all(table => $table1);
1812
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1813
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1814
    primary_key => $key1, 
1815
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1816
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1817
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1818
);
1819

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1862
$dbi->delete_all(table => $table1);
1863
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1864
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1865
    table => $table1,
1866
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1867
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1868
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
1869
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1870
is($dbi->select(table => $table1)->one->{$key1}, 1);
1871
is($dbi->select(table => $table1)->one->{$key2}, 2);
1872
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1873

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1903
$dbi->delete_all(table => $table1);
1904
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1905
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1906
    table => $table1,
1907
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1908
    where => 1,
1909
);
1910
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1911
is($row->{$key1}, 1);
1912
is($row->{$key2}, 2);
1913
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1914

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

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

            
1936
eval {
1937
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1938
        table => $table1,
1939
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1940
        where => [1],
1941
    );
1942
};
1943
like($@, qr/same/);
1944

            
1945
eval {
1946
    $result = $dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1947
        table => $table1,
1948
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1949
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1950
        param => {$key1 => 1, $key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-10
1951
    );
1952
};
1953
like($@, qr/must be/);
1954

            
1955
eval {
1956
    $result = $dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1957
        table => $table1,
1958
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1959
        where => {},
1960
    );
1961
};
1962
like($@, qr/must be/);
1963

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

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

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

            
2011
test 'model select_at';
2012
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2013
eval { $dbi->execute("drop table $table1") };
cleanup test
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
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2016
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2017
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2018
is($row->{$key1}, 1);
2019
is($row->{$key2}, 2);
2020
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2021

            
2022

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

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

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

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

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

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

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

            
2116
$result = $model->select_at(
2117
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2118
        $model->mycolumn([$key1]),
2119
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2120
    ]
2121
);
2122
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2123
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2124

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2125
test 'merge_param';
2126
$dbi = DBIx::Custom->new;
2127
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2128
    {$key1 => 1, $key2 => 2, $key3 => 3},
2129
    {$key1 => 1, $key2 => 2},
2130
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2131
];
2132
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2133
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2134

            
2135
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2136
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2137
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2138
];
2139
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2140
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
2141

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
2162
$rows = $dbi->select(
2163
    table => $table1,
2164
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2165
    where   => {"$table1.$key2" => 3},
2166
    join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2167
             " $table2 on $table1.$key1 = $table2.$key1",
2168
    param => {"$table2.$key3" => 5}
2169
)->all;
2170
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2171

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

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

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

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

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

            
2242

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

            
2257
$dbi = DBIx::Custom->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);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2260
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2261
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2262
    table => $table1,
2263
    param => {$key1 => 5},
cleanup test
Yuki Kimoto authored on 2011-08-10
2264
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2265
        "$key1 = :$key1 and $key2 = :$key2",
2266
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2267
    ]
2268
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2269
$rows = $dbi->select(table => $table1)->all;
2270
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2271

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2286
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2287
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2288
    primary_key => $key1, 
2289
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2290
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2291
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2292
);
2293

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2353
$dbi->delete_all(table => $table1);
2354
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2355
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2356
    table => $table1,
2357
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2358
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2359
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2360
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2361
is($dbi->select(table => $table1)->one->{$key1}, 0);
2362
is($dbi->select(table => $table1)->one->{$key2}, 2);
2363
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2364

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

            
2379

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

            
2395

            
2396
test 'delete and id option';
2397
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2398
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2399
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2400
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2401
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2402
    table => $table1,
2403
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2404
    id => [1, 2],
2405
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2406
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2407

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2408
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2409
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2410
    table => $table1,
2411
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2412
    id => 0,
2413
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2414
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2415

            
2416

            
2417
test 'model delete and id option';
2418
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2419
eval { $dbi->execute("drop table $table1") };
2420
eval { $dbi->execute("drop table $table2") };
2421
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2422
$dbi->execute($create_table1_2);
2423
$dbi->execute($create_table2_2);
2424
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2425
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2426
$dbi->model($table1)->delete(id => [1, 2]);
2427
is_deeply($dbi->select(table => $table1)->all, []);
2428
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2429
$dbi->model($table1)->delete(id => [1, 2]);
2430
is_deeply($dbi->select(table => $table1)->all, []);
2431
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2432
$dbi->model($table3)->delete(id => [1, 2]);
2433
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2434

            
2435

            
2436
test 'select and id option';
2437
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2438
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2439
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2440
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2441
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2442
    table => $table1,
2443
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2444
    id => [1, 2]
2445
);
2446
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2447
is($row->{$key1}, 1);
2448
is($row->{$key2}, 2);
2449
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2450

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2463
$dbi->delete_all(table => $table1);
2464
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2465
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2466
    table => $table1,
2467
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2468
    id => [1, 2]
2469
);
2470
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2471
is($row->{$key1}, 1);
2472
is($row->{$key2}, 2);
2473
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2474

            
2475

            
2476
test 'model select_at';
2477
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2478
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2479
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2480
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2481
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2482
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2483
is($row->{$key1}, 1);
2484
is($row->{$key2}, 2);
2485
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2486

            
2487
test 'column separator is default .';
2488
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2489
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2490
eval { $dbi->execute("drop table $table1") };
2491
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2492
$dbi->execute($create_table1);
2493
$dbi->execute($create_table2);
2494
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2495
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2496
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2497
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2498
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2499
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2500
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2501
);
2502
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2503
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2504

            
2505
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2506
    column => [$model->column($table2 => [$key1, $key3])],
2507
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2508
);
2509
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2510
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2511

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2520
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2521
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2522
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2523
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2524
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2525
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2526
);
2527
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2528
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2529
);
2530
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2531
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2532
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2533
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2534
$result = $model->select(
2535
    column => [
2536
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2537
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2538
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2539
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2540
);
2541
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2542
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2543
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2544

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2558
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2559
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2560
$result = $model->select(
2561
    column => [
2562
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2563
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2564
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2565
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2566
);
2567
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2568
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2569
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2570

            
2571

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2572
test 'filter_off';
2573
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2574
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2575
eval { $dbi->execute("drop table $table1") };
2576
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2577
$dbi->execute($create_table1);
2578
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2579

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2580
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2581
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2582
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2583
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2584
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2585
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2586
);
2587
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2588
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2589
$model = $dbi->model($table1);
2590
$result = $model->select(column => $key1);
2591
$result->filter($key1 => sub { $_[0] * 2 });
2592
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2593

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2594
test 'available_datetype';
2595
$dbi = DBIx::Custom->connect;
2596
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2597

            
2598

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2599
test 'select prefix option';
2600
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2601
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2602
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2603
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2604
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2605
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2606

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

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

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2618
$dbi = DBIx::Custom->connect;
2619
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2620
    id => {key => "$table1.id"},
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2621
    author => ["$table1.author" => $dbi->like_value],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2622
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2623
);
2624
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2625
  "$table1.price" => 1900});
2626

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

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

            
2641
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2642
    id => {key => "$table1.id"},
2643
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2644
);
2645
is_deeply($param, {"$table1.price" => undef});
2646

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

            
2653
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2654
    id => {key => "$table1.id"},
added tests
Yuki Kimoto authored on 2011-08-26
2655
    price => ["$table1.price", sub { '%' . $_[0] }]
2656
);
2657
is_deeply($param, {"$table1.price" => '%a'});
2658

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2659
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2660
    price => sub { '%' . $_[0] },
2661
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2662
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2663
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2664

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2665
eval { $dbi->execute("drop table $table1") };
2666
$dbi->execute($create_table1);
2667
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2668
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
2669

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

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

            
2688
$where = $dbi->where;
2689
$where->clause(['and', ":${key1}{=}"]);
2690
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
2691
$where->param($param);
2692
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2693
$row = $result->all;
2694
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2695
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2696
$row = $result->all;
2697
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2698

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2700
$where = $dbi->where;
2701
$where->clause(['and', ":${key1}{=}"]);
2702
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
2703
  ->pass([$key1, $key2])->map;
2704
$where->param($param);
2705
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2706
$row = $result->all;
2707
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2708

            
2709
$where = $dbi->where;
2710
$where->clause(['and', ":${key1}{=}"]);
2711
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
2712
$where->param($param);
2713
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2714
$row = $result->all;
2715
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2716

            
2717
$where = $dbi->where;
2718
$where->clause(['and', ":${key1}{=}"]);
2719
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
2720
  ->pass([$key1, $key2])->map;
2721
$where->param($param);
2722
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2723
$row = $result->all;
2724
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2725

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2727
$where = $dbi->where;
2728
$where->clause(['and', ":${key1}{=}"]);
2729
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
2730
$where->param($param);
2731
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2732
$row = $result->all;
2733
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2734

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

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

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

            
2763
$where = $dbi->where;
2764
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2765
    id => {key => "$table1.id"},
2766
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2767
);
2768
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
2769

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

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

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

            
2795
$where = $dbi->where;
2796
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2797
    id => {key => "$table1.id", condition => 'length'},
2798
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
2799
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2800
);
2801
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2802
  "$table1.price" => 1900});
2803

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2809
test 'order';
2810
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2811
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2812
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2813
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2814
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
2815
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
2816
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2817
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2818
$order->prepend($key1, "$key2 desc");
2819
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2820
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
2821
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2822
$order->prepend("$key1 desc");
2823
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2824
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
2825
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2826

            
2827
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2828
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2829
$result = $dbi->select(table => $table1,
2830
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2831
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2832
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
2833
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
2834
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
2835
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2836

            
2837
test 'tag_parse';
2838
$dbi = DBIx::Custom->connect;
2839
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2840
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2841
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2842
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2843
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2844
ok($@);
2845

            
2846
test 'last_sql';
2847
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2848
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2849
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2850
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
2851
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2852

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2884
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
2885
$result = $dbi->execute(
2886
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2887
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2888
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
2889
);
2890
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2891
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2892

            
2893
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2894
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2895
$dbi->execute($create_table1_highperformance);
2896
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2897
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2898
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2899
];
2900
{
2901
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
2902
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2903
      $query ||= $dbi->insert($row, table => $table1, query => 1);
2904
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
2905
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2906
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2907
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2908
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2909
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2910
      ]
2911
    );
2912
}
2913

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2914
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2915
$dbi->execute($create_table1_highperformance);
2916
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2917
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2918
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2919
];
2920
{
2921
    my $query;
2922
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
2923
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2924
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2925
      $sth ||= $query->sth;
2926
      $sth->execute(map { $row->{$_} } sort keys %$row);
2927
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2928
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2929
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2930
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2931
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2932
      ]
2933
    );
2934
}
2935

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2936
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2937
$dbi->execute($create_table1_highperformance);
2938
$rows = [
2939
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
2940
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
2941
];
2942
{
2943
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
2944
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
2945
    for my $row (@$rows) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2946
      $query ||= $model->insert($row, query => 1);
2947
      $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2948
    }
2949
    is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
2950
      [
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2951
          {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
2952
          {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2953
      ]
2954
    );
2955
}
2956

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2957
test 'id option more';
2958
eval { $dbi->execute("drop table $table1") };
2959
$dbi->execute($create_table1_highperformance);
2960
$row = {
2961
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
2962
};
2963
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2964
$model->insert($row);
2965
$query = $model->update({$key7 => 11}, id => 1, query => 1);
2966
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
2967
is_deeply($dbi->select(table => $table1)->one,
2968
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
2969
);
2970

            
2971
eval { $dbi->execute("drop table $table1") };
2972
eval { $dbi->execute("drop table $table2") };
2973
$dbi->execute($create_table1);
2974
$dbi->execute($create_table2);
2975
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2976
$model->insert({$key1 => 1, $key2 => 2});
2977
$model = $dbi->create_model(table => $table2, primary_key => $key1,
2978
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
2979
$model->insert({$key1 => 1, $key3 => 3});
2980
$result = $model->select(
2981
    column => {$table1 => ["$key2"]},
2982
    id => 1
2983
);
2984
is_deeply($result->all, [{"$table1.$key2" => 2}]);
2985

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

            
2997
eval { $dbi->execute("drop table $table1") };
2998
eval { $dbi->execute($create_table1_highperformance) };
2999
$row = {
3000
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3001
};
3002
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3003
$model->insert($row);
3004
$query = $model->select(id => 1, query => 1);
3005
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3006
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3007
is_deeply($dbi->select(table => $table1)->one,
3008
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3009
);
3010

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3011
test 'result';
3012
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3013
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3014
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3015
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3016
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3017

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3025
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3026
@rows = ();
3027
while (my $row = $result->fetch_hash) {
3028
    push @rows, {%$row};
3029
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3030
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3031

            
3032
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3033
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3034
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3035
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3036
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3037

            
3038
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3039
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3040
$rows = $result->fetch_all;
3041
is_deeply($rows, [[1, 2], [3, 4]]);
3042

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

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

            
3051
$rows = $result->fetch_all;
3052
is_deeply($rows, [[3, 2], [9, 4]], "array");
3053

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

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

            
3096
for (my $i = 0; $i < @$datas; $i++) {
3097
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3098
    my $dbi = DBIx::Custom->new;
3099
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3100
    my $query = $builder->build_query($data->{source});
3101
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3102
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3103
}
3104

            
cleanup
Yuki Kimoto authored on 2011-08-13
3105
$dbi = DBIx::Custom->new;
3106
$builder = $dbi->query_builder;
3107
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3108
    p => sub {
3109
        my @args = @_;
3110
        
3111
        my $expand    = "? $args[0] $args[1]";
3112
        my $columns = [2];
3113
        return [$expand, $columns];
3114
    }
3115
);
3116

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3127
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3128
    q => 'string'
3129
});
3130

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3134
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3135
   r => sub {} 
3136
});
3137

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3141
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3142
   s => sub { return ["a", ""]} 
3143
});
3144

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3148
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3149
    t => sub {return ["a", []]}
3150
);
3151

            
3152

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

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

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

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

            
3168
test 'variouse source';
3169
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3170
$query = $builder->build_query($source);
3171
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3172

            
3173
$source = "abc";
3174
$query = $builder->build_query($source);
3175
is($query->sql, 'abc', "basic : 2");
3176

            
3177
$source = "{= a}";
3178
$query = $builder->build_query($source);
3179
is($query->sql, 'a = ?', "only tag");
3180

            
3181
$source = "000";
3182
$query = $builder->build_query($source);
3183
is($query->sql, '000', "contain 0 value");
3184

            
3185
$source = "a {= b} }";
3186
eval{$builder->build_query($source)};
3187
like($@, qr/unexpected "}"/, "error : 1");
3188

            
3189
$source = "a {= {}";
3190
eval{$builder->build_query($source)};
3191
like($@, qr/unexpected "{"/, "error : 2");
3192

            
3193
test 'select() sqlfilter option';
3194
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3195
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3196
eval { $dbi->execute("drop table $table1") };
3197
$dbi->execute($create_table1);
3198
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3199
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3200
$rows = $dbi->select(
3201
    table => $table1,
3202
    column => $key1,
3203
    sqlfilter => sub {
3204
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
3205
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
3206
        return $sql;
3207
    }
3208
)->all;
3209
is_deeply($rows, [{$key1 => 1}]);
3210

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3211
test 'select() after_build_sql option';
3212
$dbi = DBIx::Custom->connect;
3213
$dbi->user_table_info($user_table_info);
3214
eval { $dbi->execute("drop table $table1") };
3215
$dbi->execute($create_table1);
3216
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3217
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3218
$rows = $dbi->select(
3219
    table => $table1,
3220
    column => $key1,
3221
    after_build_sql => sub {
3222
        my $sql = shift;
3223
        $sql = "select * from ( $sql ) t where $key1 = 1";
3224
        return $sql;
3225
    }
3226
)->all;
3227
is_deeply($rows, [{$key1 => 1}]);
3228

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3229
test 'dbi method from model';
3230
$dbi = MyDBI9->connect;
3231
eval { $dbi->execute("drop table $table1") };
3232
$dbi->execute($create_table1);
3233
$dbi->setup_model;
3234
$model = $dbi->model($table1);
3235
eval{$model->execute("select * from $table1")};
3236
ok(!$@);
3237

            
3238
test 'column table option';
3239
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3240
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3241
eval { $dbi->execute("drop table $table1") };
3242
$dbi->execute($create_table1);
3243
eval { $dbi->execute("drop table $table2") };
3244
$dbi->execute($create_table2);
3245
$dbi->setup_model;
3246
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3247
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3248
$model = $dbi->model($table1);
3249
$result = $model->select(
3250
    column => [
3251
        $model->column($table2, {alias => $table2_alias})
3252
    ],
3253
    where => {"$table2_alias.$key3" => 4}
3254
);
3255
is_deeply($result->one, 
3256
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3257

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

            
3268
$dbi->separator('-');
3269
$result = $model->select(
3270
    column => [
3271
        $model->column($table2, {alias => $table2_alias})
3272
    ],
3273
    where => {"$table2_alias.$key3" => 4}
3274
);
3275
is_deeply($result->one, 
3276
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3277

            
3278
test 'create_model';
3279
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3280
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3281
eval { $dbi->execute("drop table $table1") };
3282
eval { $dbi->execute("drop table $table2") };
3283
$dbi->execute($create_table1);
3284
$dbi->execute($create_table2);
3285

            
3286
$dbi->create_model(
3287
    table => $table1,
3288
    join => [
3289
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3290
    ],
3291
    primary_key => [$key1]
3292
);
3293
$model2 = $dbi->create_model(
3294
    table => $table2
3295
);
3296
$dbi->create_model(
3297
    table => $table3,
3298
    filter => [
3299
        $key1 => {in => sub { uc $_[0] }}
3300
    ]
3301
);
3302
$dbi->setup_model;
3303
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3304
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3305
$model = $dbi->model($table1);
3306
$result = $model->select(
3307
    column => [$model->mycolumn, $model->column($table2)],
3308
    where => {"$table1.$key1" => 1}
3309
);
3310
is_deeply($result->one,
3311
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3312
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3313

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

            
3325
test 'model helper';
3326
$dbi = DBIx::Custom->connect;
3327
eval { $dbi->execute("drop table $table2") };
3328
$dbi->execute($create_table2);
3329
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3330
$model = $dbi->create_model(
3331
    table => $table2
3332
);
3333
$model->helper(foo => sub { shift->select(@_) });
3334
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3335

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3336
test 'assign_clause';
cleanup test
Yuki Kimoto authored on 2011-08-15
3337
$dbi = DBIx::Custom->connect;
3338
eval { $dbi->execute("drop table $table1") };
3339
$dbi->execute($create_table1_2);
3340
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3341
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3342

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

            
3356

            
3357
$dbi = DBIx::Custom->connect;
3358
eval { $dbi->execute("drop table $table1") };
3359
$dbi->execute($create_table1_2);
3360
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3361
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3362

            
3363
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3364
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3365
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3366
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3367
where $key1 = 1
3368
EOS
3369
$dbi->execute($sql, param => $param);
3370
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3371
$rows   = $result->all;
3372
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3373
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3374
                  "basic");
3375

            
3376
$dbi = DBIx::Custom->connect;
3377
eval { $dbi->execute("drop table $table1") };
3378
$dbi->execute($create_table1_2);
3379
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3380
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3381

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

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

            
3399
$dbi = DBIx::Custom->connect;
3400
eval { $dbi->execute("drop table $table1") };
3401
$dbi->execute($create_table1_2);
3402
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3403
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3404

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

            
3418
$param = {$key2 => 11};
3419
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3420
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3421
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3422
where $key1 = 1
3423
EOS
3424
$dbi->execute($sql, param => $param, table => $table1);
3425
$result = $dbi->execute("select * from $table1 order by $key1");
3426
$rows   = $result->all;
3427
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3428
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3429
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3430

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3431
test 'Model class';
3432
$dbi = MyDBI1->connect;
3433
eval { $dbi->execute("drop table $table1") };
3434
$dbi->execute($create_table1);
3435
$model = $dbi->model($table1);
3436
$model->insert({$key1 => 'a', $key2 => 'b'});
3437
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3438
eval { $dbi->execute("drop table $table2") };
3439
$dbi->execute($create_table2);
3440
$model = $dbi->model($table2);
3441
$model->insert({$key1 => 'a'});
3442
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3443
is($dbi->models->{$table1}, $dbi->model($table1));
3444
is($dbi->models->{$table2}, $dbi->model($table2));
3445

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

            
3458
$dbi = MyDBI5->connect;
3459
eval { $dbi->execute("drop table $table1") };
3460
eval { $dbi->execute("drop table $table2") };
3461
$dbi->execute($create_table1);
3462
$dbi->execute($create_table2);
3463
$model = $dbi->model($table2);
3464
$model->insert({$key1 => 'a'});
3465
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3466
$dbi->insert(table => $table1, param => {$key1 => 1});
3467
$model = $dbi->model($table1);
3468
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3469

            
3470
test 'primary_key';
3471
$dbi = MyDBI1->connect;
3472
$model = $dbi->model($table1);
3473
$model->primary_key([$key1, $key2]);
3474
is_deeply($model->primary_key, [$key1, $key2]);
3475

            
3476
test 'columns';
3477
$dbi = MyDBI1->connect;
3478
$model = $dbi->model($table1);
3479
$model->columns([$key1, $key2]);
3480
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3481

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3482
test 'setup_model';
3483
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3484
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3485
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3486
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3487

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3488
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3489
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3490
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3491
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3492
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3493

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3494
test 'each_column';
3495
$dbi = DBIx::Custom->connect;
3496
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3497
eval { $dbi->execute("drop table $table1") };
3498
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3499
eval { $dbi->execute("drop table $table3") };
3500
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3501
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3502

            
3503
$infos = [];
3504
$dbi->each_column(sub {
3505
    my ($self, $table, $column, $cinfo) = @_;
3506
    
3507
    if ($table =~ /^table\d/i) {
3508
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3509
         push @$infos, $info;
3510
    }
3511
});
3512
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3513
is_deeply($infos, 
3514
    [
3515
        [$table1, $key1, $key1],
3516
        [$table1, $key2, $key2],
3517
        [$table2, $key1, $key1],
3518
        [$table2, $key3, $key3]
3519
    ]
3520
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3521
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3522

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3523
test 'each_table';
3524
$dbi = DBIx::Custom->connect;
3525
eval { $dbi->execute("drop table $table1") };
3526
eval { $dbi->execute("drop table $table2") };
3527
$dbi->execute($create_table2);
3528
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3529

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3530
$infos = [];
3531
$dbi->each_table(sub {
3532
    my ($self, $table, $table_info) = @_;
3533
    
3534
    if ($table =~ /^table\d/i) {
3535
         my $info = [$table, $table_info->{TABLE_NAME}];
3536
         push @$infos, $info;
3537
    }
3538
});
3539
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3540
is_deeply($infos, 
3541
    [
3542
        [$table1, $table1],
3543
        [$table2, $table2],
3544
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3545
);
3546

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

            
3553
$infos = [];
3554
$dbi->user_table_info($user_table_info);
3555
$dbi->each_table(sub {
3556
    my ($self, $table, $table_info) = @_;
3557
    
3558
    if ($table =~ /^table\d/i) {
3559
         my $info = [$table, $table_info->{TABLE_NAME}];
3560
         push @$infos, $info;
3561
    }
3562
});
3563
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3564
is_deeply($infos, 
3565
    [
3566
        [$table1, $table1],
3567
        [$table2, $table2],
3568
        [$table3, $table3],
3569
    ]
3570
);
3571

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3572
test 'type_rule into';
3573
eval { $dbi->execute("drop table $table1") };
3574
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3575
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3576

            
3577

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3578
$dbi = DBIx::Custom->connect;
3579
eval { $dbi->execute("drop table $table1") };
3580
$dbi->execute($create_table1_type);
3581

            
cleanup
Yuki Kimoto authored on 2011-08-16
3582
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3583
$dbi->type_rule(
3584
    into1 => {
3585
        $date_typename => sub { '2010-' . $_[0] }
3586
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3587
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3588
$dbi->insert({$key1 => '01-01'}, table => $table1);
3589
$result = $dbi->select(table => $table1);
3590
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3591

            
3592
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3593
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3594
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3595
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3596
$dbi->type_rule(
3597
    into1 => [
3598
         [$date_typename, $datetime_typename] => sub {
3599
            my $value = shift;
3600
            $value =~ s/02/03/g;
3601
            return $value;
3602
         }
3603
    ]
3604
);
3605
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3606
$result = $dbi->select(table => $table1);
3607
$row = $result->one;
3608
like($row->{$key1}, qr/^2010-01-03/);
3609
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3610

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

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

            
3656
$dbi = DBIx::Custom->connect;
3657
eval { $dbi->execute("drop table $table1") };
3658
$dbi->execute($create_table1_type);
3659
$dbi->register_filter(convert => sub {
3660
    my $value = shift || '';
3661
    $value =~ s/02/03/;
3662
    return $value;
3663
});
cleanup
Yuki Kimoto authored on 2011-08-16
3664
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3665
$dbi->type_rule(
3666
    from1 => {
3667
        $date_datatype => 'convert',
3668
    },
3669
    into1 => {
3670
        $date_typename => 'convert',
3671
    }
3672
);
3673
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3674
$result = $dbi->select(table => $table1);
3675
like($result->fetch->[0], qr/^2010-03-03/);
3676

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

            
3702

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

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

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

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

            
3778
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3779
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3780
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3781
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3782
$dbi->type_rule(
3783
    from1 => {
3784
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3785
    },
3786
    into1 => {
3787
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3788
    }
3789
);
3790
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3791
$result = $dbi->select(table => $table1);
3792
like($result->fetch->[0], qr/2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3793

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3808
eval{$dbi->type_rule(
3809
    into1 => {
3810
        $date_typename => 'pp'
3811
    }
3812
)};
3813
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3814

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3815
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3816
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3817
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3818
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3819
    $dbi->type_rule(
3820
        from1 => {
3821
            Date => sub { $_[0] * 2 },
3822
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3823
    );
3824
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3825
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3826

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3827
eval {
3828
    $dbi->type_rule(
3829
        into1 => {
3830
            Date => sub { $_[0] * 2 },
3831
        }
3832
    );
3833
};
3834
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3835

            
3836
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3837
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3838
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3839
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3840
$dbi->type_rule(
3841
    from1 => {
3842
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3843
    },
3844
    into1 => {
3845
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3846
    }
3847
);
3848
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3849
$result = $dbi->select(table => $table1);
3850
$result->type_rule_off;
3851
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3852

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

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

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

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

            
3902
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
3903
$result = $dbi->select(table => $table1);
3904
$result->type_rule(
3905
    from1 => [$date_datatype => 'five']
3906
);
3907
$row = $result->one;
3908
like($row->{$key1}, qr/^2010-01-05/);
3909
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3910

            
3911
$result = $dbi->select(table => $table1);
3912
$result->type_rule(
3913
    from1 => [$date_datatype => undef]
3914
);
3915
$row = $result->one;
3916
like($row->{$key1}, qr/^2010-01-03/);
3917
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3918

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3933
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3934
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3935
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3936
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3937
$dbi->type_rule(
3938
    from1 => {
3939
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3940
    },
3941
);
3942
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3943
$result = $dbi->select(table => $table1);
3944
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3945
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3946

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4019
test 'join';
4020
$dbi = DBIx::Custom->connect;
4021
eval { $dbi->execute("drop table $table1") };
4022
$dbi->execute($create_table1);
4023
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4024
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
4025
eval { $dbi->execute("drop table $table2") };
4026
$dbi->execute($create_table2);
4027
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4028
eval { $dbi->execute("drop table $table3") };
4029
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
4030
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
4031
$rows = $dbi->select(
4032
    table => $table1,
4033
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4034
    where   => {"$table1.$key2" => 2},
4035
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4036
)->all;
4037
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
4038

            
4039
$rows = $dbi->select(
4040
    table => $table1,
4041
    where   => {$key1 => 1},
4042
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4043
)->all;
4044
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4045

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

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

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

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

            
4088

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

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

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

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

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

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

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

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