DBIx-Custom / t / common.t /
Newer Older
4226 lines | 142.149kb
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
test 'default_bind_filter';
581
$dbi->execute("delete from $table1");
582
$dbi->register_filter(
583
    twice       => sub { $_[0] * 2 },
584
    three_times => sub { $_[0] * 3 }
585
);
586
$dbi->default_bind_filter('twice');
587
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => 'three_times'});
588
$result = $dbi->execute("select * from $table1");
589
$rows   = $result->all;
590
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
591
$dbi->default_bind_filter(undef);
592

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
783

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

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

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

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

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

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

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

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

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

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

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

            
875

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1007

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

            
1013
$dbi->begin_work;
1014

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

            
1021
$dbi->rollback if $@;
1022

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

            
1027
$dbi->begin_work;
1028

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

            
1034
$dbi->commit unless $@;
1035

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1631

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

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

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

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

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

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

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

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

            
1687
$dbi->apply_filter(
1688

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2021

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2241

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

            
2256
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2257
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2258
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2259
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2260
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2261
    table => $table1,
2262
    param => {$key1 => 5},
cleanup test
Yuki Kimoto authored on 2011-08-10
2263
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2264
        "$key1 = :$key1 and $key2 = :$key2",
2265
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2266
    ]
2267
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2268
$rows = $dbi->select(table => $table1)->all;
2269
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2270

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

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

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

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

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2310
$dbi = DBIx::Custom->connect;
2311
eval { $dbi->execute("drop table $table1") };
2312
$dbi->execute($create_table1_2);
2313
$param = {$key3 => 3, $key2 => 4};
2314
$DB::single = 1;
2315
$dbi->insert(
2316
    $param,
2317
    primary_key => [$key1, $key2], 
2318
    table => $table1,
2319
    id => [1, 2],
2320
);
2321
is($dbi->select(table => $table1)->one->{$key1}, 1);
2322
is($dbi->select(table => $table1)->one->{$key2}, 4);
2323
is($dbi->select(table => $table1)->one->{$key3}, 3);
2324
is_deeply($param, {$key3 => 3, $key2 => 4});
2325

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

            
2340
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2341
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2342
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2343
$dbi->model($table1)->insert(
2344
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2345
    id => [1, 2]
2346
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2347
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2348
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2349
is($row->{$key1}, 1);
2350
is($row->{$key2}, 2);
2351
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2352

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2368
$dbi->delete_all(table => $table1);
2369
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2370
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2371
    table => $table1,
2372
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2373
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2374
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2375
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2376
is($dbi->select(table => $table1)->one->{$key1}, 0);
2377
is($dbi->select(table => $table1)->one->{$key2}, 2);
2378
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2379

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

            
2394

            
2395
test 'model update and id option';
2396
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2397
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2398
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2399
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2400
$dbi->model($table1)->update(
cleanup test
Yuki Kimoto authored on 2011-08-10
2401
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2402
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2403
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2404
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2405
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2406
is($row->{$key1}, 1);
2407
is($row->{$key2}, 2);
2408
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2409

            
2410

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2423
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2424
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2425
    table => $table1,
2426
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2427
    id => 0,
2428
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2429
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2430

            
2431

            
2432
test 'model delete and id option';
2433
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2434
eval { $dbi->execute("drop table $table1") };
2435
eval { $dbi->execute("drop table $table2") };
2436
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2437
$dbi->execute($create_table1_2);
2438
$dbi->execute($create_table2_2);
2439
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2440
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2441
$dbi->model($table1)->delete(id => [1, 2]);
2442
is_deeply($dbi->select(table => $table1)->all, []);
2443
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2444
$dbi->model($table1)->delete(id => [1, 2]);
2445
is_deeply($dbi->select(table => $table1)->all, []);
2446
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2447
$dbi->model($table3)->delete(id => [1, 2]);
2448
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2449

            
2450

            
2451
test 'select and id option';
2452
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2453
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2454
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2455
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2456
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2457
    table => $table1,
2458
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2459
    id => [1, 2]
2460
);
2461
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2462
is($row->{$key1}, 1);
2463
is($row->{$key2}, 2);
2464
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2465

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2478
$dbi->delete_all(table => $table1);
2479
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2480
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2481
    table => $table1,
2482
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2483
    id => [1, 2]
2484
);
2485
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2486
is($row->{$key1}, 1);
2487
is($row->{$key2}, 2);
2488
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2489

            
2490

            
2491
test 'model select_at';
2492
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2493
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2494
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2495
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2496
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2497
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2498
is($row->{$key1}, 1);
2499
is($row->{$key2}, 2);
2500
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2501

            
2502
test 'column separator is default .';
2503
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2504
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2505
eval { $dbi->execute("drop table $table1") };
2506
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2507
$dbi->execute($create_table1);
2508
$dbi->execute($create_table2);
2509
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2510
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2511
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2512
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2513
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2514
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2515
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2516
);
2517
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2518
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2519

            
2520
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2521
    column => [$model->column($table2 => [$key1, $key3])],
2522
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2523
);
2524
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2525
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2526

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2527
test 'separator';
2528
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2529
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2530
eval { $dbi->execute("drop table $table1") };
2531
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2532
$dbi->execute($create_table1);
2533
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2534

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2535
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2536
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2537
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2538
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2539
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2540
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2541
);
2542
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2543
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2544
);
2545
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2546
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2547
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2548
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2549
$result = $model->select(
2550
    column => [
2551
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2552
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2553
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2554
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2555
);
2556
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2557
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2558
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2559

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2573
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2574
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2575
$result = $model->select(
2576
    column => [
2577
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2578
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2579
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2580
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2581
);
2582
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2583
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2584
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2585

            
2586

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2587
test 'filter_off';
2588
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2589
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2590
eval { $dbi->execute("drop table $table1") };
2591
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2592
$dbi->execute($create_table1);
2593
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2594

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2595
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2596
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2597
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2598
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2599
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2600
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2601
);
2602
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2603
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2604
$model = $dbi->model($table1);
2605
$result = $model->select(column => $key1);
2606
$result->filter($key1 => sub { $_[0] * 2 });
2607
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2608

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2609
test 'available_datetype';
2610
$dbi = DBIx::Custom->connect;
2611
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2612

            
2613

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2614
test 'select prefix option';
2615
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2616
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2617
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2618
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2619
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2620
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2621

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

            
added tests
Yuki Kimoto authored on 2011-08-26
2623
test 'mapper';
2624
$dbi = DBIx::Custom->connect;
2625
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2626
    id => {key => "$table1.id"},
2627
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2628
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
2629
);
2630
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2631
  "$table1.price" => 1900});
2632

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2633
$dbi = DBIx::Custom->connect;
2634
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2635
    id => {key => "$table1.id"},
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2636
    author => ["$table1.author" => $dbi->like_value],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2637
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2638
);
2639
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2640
  "$table1.price" => 1900});
2641

            
added tests
Yuki Kimoto authored on 2011-08-26
2642
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2643
    id => {key => "$table1.id"},
2644
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2645
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
2646
);
2647
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2648

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

            
2656
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2657
    id => {key => "$table1.id"},
2658
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2659
);
2660
is_deeply($param, {"$table1.price" => undef});
2661

            
2662
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2663
    id => {key => "$table1.id", condition => 'exists'},
2664
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
2665
);
2666
is_deeply($param, {"$table1.price" => '%a'});
2667

            
2668
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2669
    id => {key => "$table1.id"},
added tests
Yuki Kimoto authored on 2011-08-26
2670
    price => ["$table1.price", sub { '%' . $_[0] }]
2671
);
2672
is_deeply($param, {"$table1.price" => '%a'});
2673

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2674
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2675
    price => sub { '%' . $_[0] },
2676
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2677
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2678
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2679

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2680
eval { $dbi->execute("drop table $table1") };
2681
$dbi->execute($create_table1);
2682
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2683
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
2684

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

            
2693
$where = $dbi->where;
2694
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2695
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
2696
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2697
$row = $result->all;
2698
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2699
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2700
$row = $result->all;
2701
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2702

            
2703
$where = $dbi->where;
2704
$where->clause(['and', ":${key1}{=}"]);
2705
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
2706
$where->param($param);
2707
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2708
$row = $result->all;
2709
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2710
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2711
$row = $result->all;
2712
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2713

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2715
$where = $dbi->where;
2716
$where->clause(['and', ":${key1}{=}"]);
2717
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
2718
  ->pass([$key1, $key2])->map;
2719
$where->param($param);
2720
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2721
$row = $result->all;
2722
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2723

            
2724
$where = $dbi->where;
2725
$where->clause(['and', ":${key1}{=}"]);
2726
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
2727
$where->param($param);
2728
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2729
$row = $result->all;
2730
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2731

            
2732
$where = $dbi->where;
2733
$where->clause(['and', ":${key1}{=}"]);
2734
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
2735
  ->pass([$key1, $key2])->map;
2736
$where->param($param);
2737
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2738
$row = $result->all;
2739
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2740

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2742
$where = $dbi->where;
2743
$where->clause(['and', ":${key1}{=}"]);
2744
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
2745
$where->param($param);
2746
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2747
$row = $result->all;
2748
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2749

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

            
2760
$where = $dbi->where;
2761
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2762
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2763
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2764
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2765
);
2766
$where->param($param);
2767
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2768

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

            
2778
$where = $dbi->where;
2779
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2780
    id => {key => "$table1.id"},
2781
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2782
);
2783
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
2784

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

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

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

            
2810
$where = $dbi->where;
2811
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2812
    id => {key => "$table1.id", condition => 'length'},
2813
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
2814
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2815
);
2816
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2817
  "$table1.price" => 1900});
2818

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2824
test 'order';
2825
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2826
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2827
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2828
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2829
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
2830
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
2831
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2832
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2833
$order->prepend($key1, "$key2 desc");
2834
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2835
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
2836
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2837
$order->prepend("$key1 desc");
2838
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2839
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
2840
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2841

            
2842
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2843
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2844
$result = $dbi->select(table => $table1,
2845
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2846
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2847
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
2848
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
2849
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
2850
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2851

            
2852
test 'tag_parse';
2853
$dbi = DBIx::Custom->connect;
2854
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2855
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2856
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2857
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2858
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2859
ok($@);
2860

            
2861
test 'last_sql';
2862
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2863
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2864
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2865
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
2866
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2867

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

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

            
2878
test 'Named placeholder :name(operater) syntax';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2879
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2880
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2881
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
2882
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
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 :${key1}{=} and :${key2}{=}";
2885
$result = $dbi->execute($source, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2886
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2887
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2888

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2899
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
2900
$result = $dbi->execute(
2901
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2902
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2903
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
2904
);
2905
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2906
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2907

            
2908
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2909
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2910
$dbi->execute($create_table1_highperformance);
2911
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2912
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2913
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2914
];
2915
{
2916
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
2917
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2918
      $query ||= $dbi->insert($row, table => $table1, query => 1);
2919
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
2920
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2921
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2922
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2923
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2924
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2925
      ]
2926
    );
2927
}
2928

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2929
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2930
$dbi->execute($create_table1_highperformance);
2931
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2932
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2933
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2934
];
2935
{
2936
    my $query;
2937
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
2938
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2939
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2940
      $sth ||= $query->sth;
2941
      $sth->execute(map { $row->{$_} } sort keys %$row);
2942
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2943
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2944
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2945
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2946
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2947
      ]
2948
    );
2949
}
2950

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2951
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2952
$dbi->execute($create_table1_highperformance);
2953
$rows = [
2954
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
2955
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
2956
];
2957
{
2958
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
2959
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
2960
    for my $row (@$rows) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2961
      $query ||= $model->insert($row, query => 1);
2962
      $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2963
    }
2964
    is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
2965
      [
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2966
          {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
2967
          {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2968
      ]
2969
    );
2970
}
2971

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2972
test 'id option more';
2973
eval { $dbi->execute("drop table $table1") };
2974
$dbi->execute($create_table1_highperformance);
2975
$row = {
2976
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
2977
};
2978
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2979
$model->insert($row);
2980
$query = $model->update({$key7 => 11}, id => 1, query => 1);
2981
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
2982
is_deeply($dbi->select(table => $table1)->one,
2983
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
2984
);
2985

            
2986
eval { $dbi->execute("drop table $table1") };
2987
eval { $dbi->execute("drop table $table2") };
2988
$dbi->execute($create_table1);
2989
$dbi->execute($create_table2);
2990
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2991
$model->insert({$key1 => 1, $key2 => 2});
2992
$model = $dbi->create_model(table => $table2, primary_key => $key1,
2993
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
2994
$model->insert({$key1 => 1, $key3 => 3});
2995
$result = $model->select(
2996
    column => {$table1 => ["$key2"]},
2997
    id => 1
2998
);
2999
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3000

            
3001
eval { $dbi->execute("drop table $table1") };
3002
$dbi->execute($create_table1_highperformance);
3003
$row = {
3004
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3005
};
3006
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3007
$model->insert($row);
3008
$query = $model->delete(id => 1, query => 1);
3009
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3010
is_deeply($dbi->select(table => $table1)->all, []);
3011

            
3012
eval { $dbi->execute("drop table $table1") };
3013
eval { $dbi->execute($create_table1_highperformance) };
3014
$row = {
3015
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3016
};
3017
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3018
$model->insert($row);
3019
$query = $model->select(id => 1, query => 1);
3020
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3021
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3022
is_deeply($dbi->select(table => $table1)->one,
3023
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3024
);
3025

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3026
test 'result';
3027
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3028
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3029
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3030
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3031
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3032

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3033
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3034
@rows = ();
3035
while (my $row = $result->fetch) {
3036
    push @rows, [@$row];
3037
}
3038
is_deeply(\@rows, [[1, 2], [3, 4]]);
3039

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3040
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3041
@rows = ();
3042
while (my $row = $result->fetch_hash) {
3043
    push @rows, {%$row};
3044
}
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

            
3047
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3048
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3049
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3050
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3051
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3052

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

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

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

            
3066
$rows = $result->fetch_all;
3067
is_deeply($rows, [[3, 2], [9, 4]], "array");
3068

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

            
3075
test "query_builder";
3076
$datas = [
3077
    # Basic tests
3078
    {   name            => 'placeholder basic',
3079
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3080
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3081
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3082
    },
3083
    {
3084
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3085
        source            => "{in k1 3}",
3086
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3087
        columns_expected   => [qw/k1 k1 k1/]
3088
    },
3089
    
3090
    # Table name
3091
    {
3092
        name            => 'placeholder with table name',
3093
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3094
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3095
        columns_expected  => [qw/a.k1 a.k2/]
3096
    },
3097
    {   
3098
        name            => 'placeholder in with table name',
3099
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3100
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3101
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3102
    },
3103
    {
3104
        name            => 'not contain tag',
3105
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3106
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3107
        columns_expected  => [],
3108
    }
3109
];
3110

            
3111
for (my $i = 0; $i < @$datas; $i++) {
3112
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3113
    my $dbi = DBIx::Custom->new;
3114
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3115
    my $query = $builder->build_query($data->{source});
3116
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3117
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3118
}
3119

            
cleanup
Yuki Kimoto authored on 2011-08-13
3120
$dbi = DBIx::Custom->new;
3121
$builder = $dbi->query_builder;
3122
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3123
    p => sub {
3124
        my @args = @_;
3125
        
3126
        my $expand    = "? $args[0] $args[1]";
3127
        my $columns = [2];
3128
        return [$expand, $columns];
3129
    }
3130
);
3131

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3142
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3143
    q => 'string'
3144
});
3145

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3149
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3150
   r => sub {} 
3151
});
3152

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3156
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3157
   s => sub { return ["a", ""]} 
3158
});
3159

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3163
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3164
    t => sub {return ["a", []]}
3165
);
3166

            
3167

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

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

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

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

            
3183
test 'variouse source';
3184
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3185
$query = $builder->build_query($source);
3186
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3187

            
3188
$source = "abc";
3189
$query = $builder->build_query($source);
3190
is($query->sql, 'abc', "basic : 2");
3191

            
3192
$source = "{= a}";
3193
$query = $builder->build_query($source);
3194
is($query->sql, 'a = ?', "only tag");
3195

            
3196
$source = "000";
3197
$query = $builder->build_query($source);
3198
is($query->sql, '000', "contain 0 value");
3199

            
3200
$source = "a {= b} }";
3201
eval{$builder->build_query($source)};
3202
like($@, qr/unexpected "}"/, "error : 1");
3203

            
3204
$source = "a {= {}";
3205
eval{$builder->build_query($source)};
3206
like($@, qr/unexpected "{"/, "error : 2");
3207

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3226
test 'select() after_build_sql option';
3227
$dbi = DBIx::Custom->connect;
3228
$dbi->user_table_info($user_table_info);
3229
eval { $dbi->execute("drop table $table1") };
3230
$dbi->execute($create_table1);
3231
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3232
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3233
$rows = $dbi->select(
3234
    table => $table1,
3235
    column => $key1,
3236
    after_build_sql => sub {
3237
        my $sql = shift;
3238
        $sql = "select * from ( $sql ) t where $key1 = 1";
3239
        return $sql;
3240
    }
3241
)->all;
3242
is_deeply($rows, [{$key1 => 1}]);
3243

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3244
test 'dbi method from model';
3245
$dbi = MyDBI9->connect;
3246
eval { $dbi->execute("drop table $table1") };
3247
$dbi->execute($create_table1);
3248
$dbi->setup_model;
3249
$model = $dbi->model($table1);
3250
eval{$model->execute("select * from $table1")};
3251
ok(!$@);
3252

            
3253
test 'column table option';
3254
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3255
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3256
eval { $dbi->execute("drop table $table1") };
3257
$dbi->execute($create_table1);
3258
eval { $dbi->execute("drop table $table2") };
3259
$dbi->execute($create_table2);
3260
$dbi->setup_model;
3261
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3262
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3263
$model = $dbi->model($table1);
3264
$result = $model->select(
3265
    column => [
3266
        $model->column($table2, {alias => $table2_alias})
3267
    ],
3268
    where => {"$table2_alias.$key3" => 4}
3269
);
3270
is_deeply($result->one, 
3271
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3272

            
3273
$dbi->separator('__');
3274
$result = $model->select(
3275
    column => [
3276
        $model->column($table2, {alias => $table2_alias})
3277
    ],
3278
    where => {"$table2_alias.$key3" => 4}
3279
);
3280
is_deeply($result->one, 
3281
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3282

            
3283
$dbi->separator('-');
3284
$result = $model->select(
3285
    column => [
3286
        $model->column($table2, {alias => $table2_alias})
3287
    ],
3288
    where => {"$table2_alias.$key3" => 4}
3289
);
3290
is_deeply($result->one, 
3291
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3292

            
3293
test 'create_model';
3294
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3295
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3296
eval { $dbi->execute("drop table $table1") };
3297
eval { $dbi->execute("drop table $table2") };
3298
$dbi->execute($create_table1);
3299
$dbi->execute($create_table2);
3300

            
3301
$dbi->create_model(
3302
    table => $table1,
3303
    join => [
3304
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3305
    ],
3306
    primary_key => [$key1]
3307
);
3308
$model2 = $dbi->create_model(
3309
    table => $table2
3310
);
3311
$dbi->create_model(
3312
    table => $table3,
3313
    filter => [
3314
        $key1 => {in => sub { uc $_[0] }}
3315
    ]
3316
);
3317
$dbi->setup_model;
3318
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3319
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3320
$model = $dbi->model($table1);
3321
$result = $model->select(
3322
    column => [$model->mycolumn, $model->column($table2)],
3323
    where => {"$table1.$key1" => 1}
3324
);
3325
is_deeply($result->one,
3326
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3327
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3328

            
3329
test 'model method';
3330
$dbi = DBIx::Custom->connect;
3331
eval { $dbi->execute("drop table $table2") };
3332
$dbi->execute($create_table2);
3333
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3334
$model = $dbi->create_model(
3335
    table => $table2
3336
);
3337
$model->method(foo => sub { shift->select(@_) });
3338
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3339

            
3340
test 'model helper';
3341
$dbi = DBIx::Custom->connect;
3342
eval { $dbi->execute("drop table $table2") };
3343
$dbi->execute($create_table2);
3344
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3345
$model = $dbi->create_model(
3346
    table => $table2
3347
);
3348
$model->helper(foo => sub { shift->select(@_) });
3349
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3350

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3351
test 'assign_clause';
cleanup test
Yuki Kimoto authored on 2011-08-15
3352
$dbi = DBIx::Custom->connect;
3353
eval { $dbi->execute("drop table $table1") };
3354
$dbi->execute($create_table1_2);
3355
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3356
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3357

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

            
3371

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

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

            
3391
$dbi = DBIx::Custom->connect;
3392
eval { $dbi->execute("drop table $table1") };
3393
$dbi->execute($create_table1_2);
3394
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3395
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3396

            
3397
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3398
$assign_clause = $dbi->update_param($param, {no_set => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
3399
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3400
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3401
where $key1 = 1
3402
EOS
3403
$dbi->execute($sql, param => $param);
3404
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3405
$rows   = $result->all;
3406
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3407
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3408
                  "update param no_set");
3409

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

            
3414
$dbi = DBIx::Custom->connect;
3415
eval { $dbi->execute("drop table $table1") };
3416
$dbi->execute($create_table1_2);
3417
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3418
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3419

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

            
3433
$param = {$key2 => 11};
3434
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3435
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3436
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3437
where $key1 = 1
3438
EOS
3439
$dbi->execute($sql, param => $param, table => $table1);
3440
$result = $dbi->execute("select * from $table1 order by $key1");
3441
$rows   = $result->all;
3442
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3443
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3444
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3445

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3446
test 'Model class';
3447
$dbi = MyDBI1->connect;
3448
eval { $dbi->execute("drop table $table1") };
3449
$dbi->execute($create_table1);
3450
$model = $dbi->model($table1);
3451
$model->insert({$key1 => 'a', $key2 => 'b'});
3452
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3453
eval { $dbi->execute("drop table $table2") };
3454
$dbi->execute($create_table2);
3455
$model = $dbi->model($table2);
3456
$model->insert({$key1 => 'a'});
3457
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3458
is($dbi->models->{$table1}, $dbi->model($table1));
3459
is($dbi->models->{$table2}, $dbi->model($table2));
3460

            
3461
$dbi = MyDBI4->connect;
3462
eval { $dbi->execute("drop table $table1") };
3463
$dbi->execute($create_table1);
3464
$model = $dbi->model($table1);
3465
$model->insert({$key1 => 'a', $key2 => 'b'});
3466
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3467
eval { $dbi->execute("drop table $table2") };
3468
$dbi->execute($create_table2);
3469
$model = $dbi->model($table2);
3470
$model->insert({$key1 => 'a'});
3471
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3472

            
3473
$dbi = MyDBI5->connect;
3474
eval { $dbi->execute("drop table $table1") };
3475
eval { $dbi->execute("drop table $table2") };
3476
$dbi->execute($create_table1);
3477
$dbi->execute($create_table2);
3478
$model = $dbi->model($table2);
3479
$model->insert({$key1 => 'a'});
3480
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3481
$dbi->insert(table => $table1, param => {$key1 => 1});
3482
$model = $dbi->model($table1);
3483
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3484

            
3485
test 'primary_key';
3486
$dbi = MyDBI1->connect;
3487
$model = $dbi->model($table1);
3488
$model->primary_key([$key1, $key2]);
3489
is_deeply($model->primary_key, [$key1, $key2]);
3490

            
3491
test 'columns';
3492
$dbi = MyDBI1->connect;
3493
$model = $dbi->model($table1);
3494
$model->columns([$key1, $key2]);
3495
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3496

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3497
test 'setup_model';
3498
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3499
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3500
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3501
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3502

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3503
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3504
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3505
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3506
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3507
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3508

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3509
test 'each_column';
3510
$dbi = DBIx::Custom->connect;
3511
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3512
eval { $dbi->execute("drop table $table1") };
3513
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3514
eval { $dbi->execute("drop table $table3") };
3515
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3516
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3517

            
3518
$infos = [];
3519
$dbi->each_column(sub {
3520
    my ($self, $table, $column, $cinfo) = @_;
3521
    
3522
    if ($table =~ /^table\d/i) {
3523
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3524
         push @$infos, $info;
3525
    }
3526
});
3527
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3528
is_deeply($infos, 
3529
    [
3530
        [$table1, $key1, $key1],
3531
        [$table1, $key2, $key2],
3532
        [$table2, $key1, $key1],
3533
        [$table2, $key3, $key3]
3534
    ]
3535
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3536
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3537

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3538
test 'each_table';
3539
$dbi = DBIx::Custom->connect;
3540
eval { $dbi->execute("drop table $table1") };
3541
eval { $dbi->execute("drop table $table2") };
3542
$dbi->execute($create_table2);
3543
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3544

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3545
$infos = [];
3546
$dbi->each_table(sub {
3547
    my ($self, $table, $table_info) = @_;
3548
    
3549
    if ($table =~ /^table\d/i) {
3550
         my $info = [$table, $table_info->{TABLE_NAME}];
3551
         push @$infos, $info;
3552
    }
3553
});
3554
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3555
is_deeply($infos, 
3556
    [
3557
        [$table1, $table1],
3558
        [$table2, $table2],
3559
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3560
);
3561

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3562
$dbi = DBIx::Custom->connect;
3563
eval { $dbi->execute("drop table $table1") };
3564
eval { $dbi->execute("drop table $table2") };
3565
$dbi->execute($create_table2);
3566
$dbi->execute($create_table1_type);
3567

            
3568
$infos = [];
3569
$dbi->user_table_info($user_table_info);
3570
$dbi->each_table(sub {
3571
    my ($self, $table, $table_info) = @_;
3572
    
3573
    if ($table =~ /^table\d/i) {
3574
         my $info = [$table, $table_info->{TABLE_NAME}];
3575
         push @$infos, $info;
3576
    }
3577
});
3578
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3579
is_deeply($infos, 
3580
    [
3581
        [$table1, $table1],
3582
        [$table2, $table2],
3583
        [$table3, $table3],
3584
    ]
3585
);
3586

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3587
test 'type_rule into';
3588
eval { $dbi->execute("drop table $table1") };
3589
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3590
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3591

            
3592

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3593
$dbi = DBIx::Custom->connect;
3594
eval { $dbi->execute("drop table $table1") };
3595
$dbi->execute($create_table1_type);
3596

            
cleanup
Yuki Kimoto authored on 2011-08-16
3597
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3598
$dbi->type_rule(
3599
    into1 => {
3600
        $date_typename => sub { '2010-' . $_[0] }
3601
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3602
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3603
$dbi->insert({$key1 => '01-01'}, table => $table1);
3604
$result = $dbi->select(table => $table1);
3605
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3606

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

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

            
3648
$dbi = DBIx::Custom->connect;
3649
eval { $dbi->execute("drop table $table1") };
3650
$dbi->execute($create_table1_type);
3651
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3652
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3653
$dbi->type_rule(
3654
    into1 => [
3655
        [$date_typename, $datetime_typename] => sub {
3656
            my $value = shift;
3657
            $value =~ s/02/03/g;
3658
            return $value;
3659
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3660
    ]
3661
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3662
$result = $dbi->execute(
3663
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3664
    param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
3665
    table => $table1
3666
);
3667
$row = $result->one;
3668
like($row->{$key1}, qr/^2010-01-03/);
3669
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3670

            
3671
$dbi = DBIx::Custom->connect;
3672
eval { $dbi->execute("drop table $table1") };
3673
$dbi->execute($create_table1_type);
3674
$dbi->register_filter(convert => sub {
3675
    my $value = shift || '';
3676
    $value =~ s/02/03/;
3677
    return $value;
3678
});
cleanup
Yuki Kimoto authored on 2011-08-16
3679
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3680
$dbi->type_rule(
3681
    from1 => {
3682
        $date_datatype => 'convert',
3683
    },
3684
    into1 => {
3685
        $date_typename => 'convert',
3686
    }
3687
);
3688
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3689
$result = $dbi->select(table => $table1);
3690
like($result->fetch->[0], qr/^2010-03-03/);
3691

            
3692
test 'type_rule and filter order';
3693
$dbi = DBIx::Custom->connect;
3694
eval { $dbi->execute("drop table $table1") };
3695
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3696
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3697
$dbi->type_rule(
3698
    into1 => {
3699
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3700
    },
3701
    into2 => {
3702
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3703
    },
3704
    from1 => {
3705
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3706
    },
3707
    from2 => {
3708
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
3709
    }
3710
);
3711
$dbi->insert({$key1 => '2010-01-03'}, 
3712
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
3713
$result = $dbi->select(table => $table1);
3714
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3715
like($result->fetch_first->[0], qr/^2010-01-09/);
3716

            
3717

            
3718
$dbi = DBIx::Custom->connect;
3719
eval { $dbi->execute("drop table $table1") };
3720
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3721
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3722
$dbi->type_rule(
3723
    from1 => {
3724
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3725
    },
3726
    from2 => {
3727
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3728
    },
3729
);
3730
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3731
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3732
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3733
$result->type_rule(
3734
    from1 => {
3735
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3736
    },
3737
    from2 => {
3738
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3739
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3740
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3741
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3742
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3743

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

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

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

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

            
3809
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3810
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3811
$dbi->execute($create_table1_type);
3812
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
3813
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3814
$dbi->type_rule(
3815
    into1 => {
3816
        $date_typename => 'ppp'
3817
    }
3818
);
3819
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3820
$result = $dbi->select(table => $table1);
3821
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3822

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3823
eval{$dbi->type_rule(
3824
    into1 => {
3825
        $date_typename => 'pp'
3826
    }
3827
)};
3828
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3829

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3830
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3831
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3832
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3833
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3834
    $dbi->type_rule(
3835
        from1 => {
3836
            Date => sub { $_[0] * 2 },
3837
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3838
    );
3839
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3840
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3841

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3842
eval {
3843
    $dbi->type_rule(
3844
        into1 => {
3845
            Date => sub { $_[0] * 2 },
3846
        }
3847
    );
3848
};
3849
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3850

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

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

            
3889
$result = $dbi->select(table => $table1);
3890
$result->type_rule(
3891
    from1 => {
3892
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3893
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3894
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3895
$row = $result->one;
3896
like($row->{$key1}, qr/2010-01-05/);
3897
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3898

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

            
3909
$result = $dbi->select(table => $table1);
3910
$result->type_rule(
3911
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
3912
);
3913
$row = $result->one;
3914
like($row->{$key1}, qr/2010-01-05/);
3915
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3916

            
3917
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
3918
$result = $dbi->select(table => $table1);
3919
$result->type_rule(
3920
    from1 => [$date_datatype => 'five']
3921
);
3922
$row = $result->one;
3923
like($row->{$key1}, qr/^2010-01-05/);
3924
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3925

            
3926
$result = $dbi->select(table => $table1);
3927
$result->type_rule(
3928
    from1 => [$date_datatype => undef]
3929
);
3930
$row = $result->one;
3931
like($row->{$key1}, qr/^2010-01-03/);
3932
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3933

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3948
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3949
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3950
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3951
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3952
$dbi->type_rule(
3953
    from1 => {
3954
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3955
    },
3956
);
3957
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3958
$result = $dbi->select(table => $table1);
3959
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3960
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3961

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3986
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3987
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3988
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3989
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3990
$dbi->type_rule(
3991
    into1 => {
3992
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3993
    },
3994
    into2 => {
3995
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3996
    },
3997
    from1 => {
3998
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
3999
    },
4000
    from2 => {
4001
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4002
    }
4003
);
4004
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4005
$result = $dbi->select(table => $table1);
4006
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/);
4007
$result = $dbi->select(table => $table1);
4008
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4009

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4010
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4011
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4012
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4013
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4014
$dbi->type_rule(
4015
    into1 => {
4016
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4017
    },
4018
    into2 => {
4019
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4020
    },
4021
    from1 => {
4022
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4023
    },
4024
    from2 => {
4025
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4026
    }
4027
);
4028
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4029
$result = $dbi->select(table => $table1);
4030
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
4031
$result = $dbi->select(table => $table1);
4032
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4033

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4034
test 'join';
4035
$dbi = DBIx::Custom->connect;
4036
eval { $dbi->execute("drop table $table1") };
4037
$dbi->execute($create_table1);
4038
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4039
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
4040
eval { $dbi->execute("drop table $table2") };
4041
$dbi->execute($create_table2);
4042
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4043
eval { $dbi->execute("drop table $table3") };
4044
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
4045
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
4046
$rows = $dbi->select(
4047
    table => $table1,
4048
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4049
    where   => {"$table1.$key2" => 2},
4050
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4051
)->all;
4052
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
4053

            
4054
$rows = $dbi->select(
4055
    table => $table1,
4056
    where   => {$key1 => 1},
4057
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4058
)->all;
4059
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4060

            
4061
$rows = $dbi->select(
4062
    table => $table1,
4063
    where   => {$key1 => 1},
4064
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4065
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4066
)->all;
4067
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4068

            
4069
$rows = $dbi->select(
4070
    column => "$table3.$key4 as ${table3}__$key4",
4071
    table => $table1,
4072
    where   => {"$table1.$key1" => 1},
4073
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4074
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4075
)->all;
4076
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4077

            
4078
$rows = $dbi->select(
4079
    column => "$table1.$key1 as ${table1}__$key1",
4080
    table => $table1,
4081
    where   => {"$table3.$key4" => 4},
4082
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4083
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4084
)->all;
4085
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4086

            
4087
$dbi = DBIx::Custom->connect;
4088
eval { $dbi->execute("drop table $table1") };
4089
$dbi->execute($create_table1);
4090
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4091
eval { $dbi->execute("drop table $table2") };
4092
$dbi->execute($create_table2);
4093
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4094
$rows = $dbi->select(
4095
    table => $table1,
4096
    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",
4097
    where   => {"$table1.$key2" => 2},
4098
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4099
)->all;
4100
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4101
          'quote');
4102

            
4103

            
4104
$dbi = DBIx::Custom->connect;
4105
eval { $dbi->execute("drop table $table1") };
4106
$dbi->execute($create_table1);
4107
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4108
$sql = <<"EOS";
4109
left outer join (
4110
  select * from $table1 t1
4111
  where t1.$key2 = (
4112
    select max(t2.$key2) from $table1 t2
4113
    where t1.$key1 = t2.$key1
4114
  )
4115
) $table3 on $table1.$key1 = $table3.$key1
4116
EOS
4117
$join = [$sql];
4118
$rows = $dbi->select(
4119
    table => $table1,
4120
    column => "$table3.$key1 as ${table3}__$key1",
4121
    join  => $join
4122
)->all;
4123
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4124

            
4125
$dbi = DBIx::Custom->connect;
4126
eval { $dbi->execute("drop table $table1") };
4127
eval { $dbi->execute("drop table $table2") };
4128
$dbi->execute($create_table1);
4129
$dbi->execute($create_table2);
4130
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4131
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4132
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4133
$result = $dbi->select(
4134
    table => $table1,
4135
    join => [
4136
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4137
    ]
4138
);
4139
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4140
$result = $dbi->select(
4141
    table => $table1,
4142
    column => [{$table2 => [$key3]}],
4143
    join => [
4144
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4145
    ]
4146
);
4147
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4148
$result = $dbi->select(
4149
    table => $table1,
4150
    column => [{$table2 => [$key3]}],
4151
    join => [
4152
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4153
    ]
4154
);
4155
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4156

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

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

            
4194
$dbi = DBIx::Custom->connect;
4195
eval { $dbi->execute("drop table $table1") };
4196
eval { $dbi->execute("drop table $table2") };
4197
$dbi->execute($create_table1);
4198
$dbi->execute($create_table2);
4199
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4200
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4201
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4202
$result = $dbi->select(
4203
    table => $table1,
4204
    column => [{$table2 => [$key3]}],
4205
    join => [
4206
        "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4207
    ]
4208
);
4209
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4210

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4211
test 'columns';
4212
$dbi = MyDBI1->connect;
4213
$model = $dbi->model($table1);
4214

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4215
test 'count';
4216
$dbi = DBIx::Custom->connect;
4217
eval { $dbi->execute("drop table $table1") };
4218
$dbi->execute($create_table1);
4219
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4220
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 3});
4221
is($dbi->count(table => $table1), 2);
4222
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4223
$model = $dbi->create_model(table => $table1);
4224
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4225

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