DBIx-Custom / t / common.t /
Newer Older
4239 lines | 142.49kb
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
$dbi->insert(
2315
    $param,
2316
    primary_key => [$key1, $key2], 
2317
    table => $table1,
2318
    id => [1, 2],
2319
);
2320
is($dbi->select(table => $table1)->one->{$key1}, 1);
2321
is($dbi->select(table => $table1)->one->{$key2}, 4);
2322
is($dbi->select(table => $table1)->one->{$key3}, 3);
2323
is_deeply($param, {$key3 => 3, $key2 => 4});
2324

            
added test
Yuki Kimoto authored on 2011-10-25
2325
$dbi = DBIx::Custom->connect;
2326
eval { $dbi->execute("drop table $table1") };
2327
$dbi->execute($create_table1_2);
2328
$param = {$key3 => 3, $key2 => 4};
2329
$query = $dbi->insert(
2330
    $param,
2331
    primary_key => [$key1, $key2], 
2332
    table => $table1,
2333
    id => [1, 2],
2334
    query => 1
2335
);
2336
is(ref $query, 'DBIx::Custom::Query');
2337
is_deeply($param, {$key3 => 3, $key2 => 4});
2338

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2339
test 'model insert id and primary_key option';
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(
cleanup test
Yuki Kimoto authored on 2011-08-10
2344
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2345
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
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
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2354
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2355
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2356
$dbi->model($table1)->insert(
2357
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2358
    id => [1, 2]
2359
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2360
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2361
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2362
is($row->{$key1}, 1);
2363
is($row->{$key2}, 2);
2364
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2365

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2381
$dbi->delete_all(table => $table1);
2382
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2383
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2384
    table => $table1,
2385
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2386
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2387
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2388
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2389
is($dbi->select(table => $table1)->one->{$key1}, 0);
2390
is($dbi->select(table => $table1)->one->{$key2}, 2);
2391
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2392

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

            
2407

            
2408
test 'model update and id option';
2409
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2410
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2411
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2412
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2413
$dbi->model($table1)->update(
cleanup test
Yuki Kimoto authored on 2011-08-10
2414
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2415
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2416
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2417
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2418
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2419
is($row->{$key1}, 1);
2420
is($row->{$key2}, 2);
2421
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2422

            
2423

            
2424
test 'delete and id option';
2425
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2426
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2427
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2428
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2429
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2430
    table => $table1,
2431
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2432
    id => [1, 2],
2433
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2434
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2435

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2436
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2437
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2438
    table => $table1,
2439
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2440
    id => 0,
2441
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2442
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2443

            
2444

            
2445
test 'model delete and id option';
2446
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2447
eval { $dbi->execute("drop table $table1") };
2448
eval { $dbi->execute("drop table $table2") };
2449
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2450
$dbi->execute($create_table1_2);
2451
$dbi->execute($create_table2_2);
2452
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2453
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2454
$dbi->model($table1)->delete(id => [1, 2]);
2455
is_deeply($dbi->select(table => $table1)->all, []);
2456
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2457
$dbi->model($table1)->delete(id => [1, 2]);
2458
is_deeply($dbi->select(table => $table1)->all, []);
2459
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2460
$dbi->model($table3)->delete(id => [1, 2]);
2461
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2462

            
2463

            
2464
test 'select and id option';
2465
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2466
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2467
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2468
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2469
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2470
    table => $table1,
2471
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2472
    id => [1, 2]
2473
);
2474
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2475
is($row->{$key1}, 1);
2476
is($row->{$key2}, 2);
2477
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2478

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2491
$dbi->delete_all(table => $table1);
2492
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2493
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2494
    table => $table1,
2495
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2496
    id => [1, 2]
2497
);
2498
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2499
is($row->{$key1}, 1);
2500
is($row->{$key2}, 2);
2501
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2502

            
2503

            
2504
test 'model select_at';
2505
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2506
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2507
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2508
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2509
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2510
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2511
is($row->{$key1}, 1);
2512
is($row->{$key2}, 2);
2513
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2514

            
2515
test 'column separator is default .';
2516
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2517
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2518
eval { $dbi->execute("drop table $table1") };
2519
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2520
$dbi->execute($create_table1);
2521
$dbi->execute($create_table2);
2522
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2523
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2524
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2525
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2526
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2527
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2528
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2529
);
2530
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2531
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2532

            
2533
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2534
    column => [$model->column($table2 => [$key1, $key3])],
2535
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2536
);
2537
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2538
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2539

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2540
test 'separator';
2541
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2542
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2543
eval { $dbi->execute("drop table $table1") };
2544
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2545
$dbi->execute($create_table1);
2546
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2547

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2548
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2549
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2550
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2551
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2552
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2553
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2554
);
2555
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2556
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2557
);
2558
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2559
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2560
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2586
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2587
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2588
$result = $model->select(
2589
    column => [
2590
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2591
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2592
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2593
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2594
);
2595
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2596
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2597
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2598

            
2599

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2600
test 'filter_off';
2601
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2602
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2603
eval { $dbi->execute("drop table $table1") };
2604
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2605
$dbi->execute($create_table1);
2606
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2607

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2608
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2609
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2610
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2611
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2612
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2613
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2614
);
2615
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2616
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2617
$model = $dbi->model($table1);
2618
$result = $model->select(column => $key1);
2619
$result->filter($key1 => sub { $_[0] * 2 });
2620
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2621

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2622
test 'available_datetype';
2623
$dbi = DBIx::Custom->connect;
2624
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2625

            
2626

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2627
test 'select prefix option';
2628
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2629
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2630
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2631
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2632
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2633
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2634

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

            
added tests
Yuki Kimoto authored on 2011-08-26
2636
test 'mapper';
2637
$dbi = DBIx::Custom->connect;
2638
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2639
    id => {key => "$table1.id"},
2640
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2641
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
2642
);
2643
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2644
  "$table1.price" => 1900});
2645

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2646
$dbi = DBIx::Custom->connect;
2647
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2648
    id => {key => "$table1.id"},
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2649
    author => ["$table1.author" => $dbi->like_value],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2650
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2651
);
2652
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2653
  "$table1.price" => 1900});
2654

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

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

            
2669
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2670
    id => {key => "$table1.id"},
2671
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2672
);
2673
is_deeply($param, {"$table1.price" => undef});
2674

            
2675
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2676
    id => {key => "$table1.id", condition => 'exists'},
2677
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
2678
);
2679
is_deeply($param, {"$table1.price" => '%a'});
2680

            
2681
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2682
    id => {key => "$table1.id"},
added tests
Yuki Kimoto authored on 2011-08-26
2683
    price => ["$table1.price", sub { '%' . $_[0] }]
2684
);
2685
is_deeply($param, {"$table1.price" => '%a'});
2686

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2687
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2688
    price => sub { '%' . $_[0] },
2689
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2690
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2691
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2692

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2693
eval { $dbi->execute("drop table $table1") };
2694
$dbi->execute($create_table1);
2695
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2696
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
2697

            
2698
$where = $dbi->where;
2699
$where->clause(['and', ":${key1}{=}"]);
2700
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
2701
$where->param($param);
2702
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2703
$row = $result->all;
2704
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2705

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

            
2716
$where = $dbi->where;
2717
$where->clause(['and', ":${key1}{=}"]);
2718
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
2719
$where->param($param);
2720
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2721
$row = $result->all;
2722
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2723
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2724
$row = $result->all;
2725
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2726

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

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

            
2737
$where = $dbi->where;
2738
$where->clause(['and', ":${key1}{=}"]);
2739
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
2740
$where->param($param);
2741
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2742
$row = $result->all;
2743
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2744

            
2745
$where = $dbi->where;
2746
$where->clause(['and', ":${key1}{=}"]);
2747
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
2748
  ->pass([$key1, $key2])->map;
2749
$where->param($param);
2750
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2751
$row = $result->all;
2752
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2753

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2755
$where = $dbi->where;
2756
$where->clause(['and', ":${key1}{=}"]);
2757
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
2758
$where->param($param);
2759
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2760
$row = $result->all;
2761
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2762

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

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

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

            
2791
$where = $dbi->where;
2792
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2793
    id => {key => "$table1.id"},
2794
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2795
);
2796
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
2797

            
2798
$where = $dbi->where;
2799
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2800
    id => {key => "$table1.id", condition => 'exists'},
2801
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2802
);
2803
is_deeply($param, {"$table1.price" => '%a'});
2804

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

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

            
2823
$where = $dbi->where;
2824
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2825
    id => {key => "$table1.id", condition => 'length'},
2826
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
2827
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2828
);
2829
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2830
  "$table1.price" => 1900});
2831

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2837
test 'order';
2838
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2839
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2840
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2841
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2842
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
2843
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
2844
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2845
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2846
$order->prepend($key1, "$key2 desc");
2847
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2848
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
2849
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2850
$order->prepend("$key1 desc");
2851
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2852
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
2853
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2854

            
2855
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2856
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2857
$result = $dbi->select(table => $table1,
2858
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2859
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2860
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
2861
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
2862
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
2863
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2864

            
2865
test 'tag_parse';
2866
$dbi = DBIx::Custom->connect;
2867
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2868
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2869
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2870
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2871
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2872
ok($@);
2873

            
2874
test 'last_sql';
2875
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2876
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2877
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2878
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
2879
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2880

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2912
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
2913
$result = $dbi->execute(
2914
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2915
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2916
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
2917
);
2918
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2919
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2920

            
2921
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2922
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2923
$dbi->execute($create_table1_highperformance);
2924
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2925
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2926
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2927
];
2928
{
2929
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
2930
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2931
      $query ||= $dbi->insert($row, table => $table1, query => 1);
2932
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
2933
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2934
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2935
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2936
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2937
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2938
      ]
2939
    );
2940
}
2941

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2942
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2943
$dbi->execute($create_table1_highperformance);
2944
$rows = [
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
    my $query;
2950
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
2951
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2952
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2953
      $sth ||= $query->sth;
2954
      $sth->execute(map { $row->{$_} } sort keys %$row);
2955
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2956
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2957
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2958
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2959
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2960
      ]
2961
    );
2962
}
2963

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2964
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2965
$dbi->execute($create_table1_highperformance);
2966
$rows = [
2967
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
2968
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
2969
];
2970
{
2971
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
2972
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
2973
    for my $row (@$rows) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2974
      $query ||= $model->insert($row, query => 1);
2975
      $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2976
    }
2977
    is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
2978
      [
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2979
          {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
2980
          {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2981
      ]
2982
    );
2983
}
2984

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2985
test 'id option more';
2986
eval { $dbi->execute("drop table $table1") };
2987
$dbi->execute($create_table1_highperformance);
2988
$row = {
2989
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
2990
};
2991
$model = $dbi->create_model(table => $table1, primary_key => $key1);
2992
$model->insert($row);
2993
$query = $model->update({$key7 => 11}, id => 1, query => 1);
2994
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
2995
is_deeply($dbi->select(table => $table1)->one,
2996
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
2997
);
2998

            
2999
eval { $dbi->execute("drop table $table1") };
3000
eval { $dbi->execute("drop table $table2") };
3001
$dbi->execute($create_table1);
3002
$dbi->execute($create_table2);
3003
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3004
$model->insert({$key1 => 1, $key2 => 2});
3005
$model = $dbi->create_model(table => $table2, primary_key => $key1,
3006
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
3007
$model->insert({$key1 => 1, $key3 => 3});
3008
$result = $model->select(
3009
    column => {$table1 => ["$key2"]},
3010
    id => 1
3011
);
3012
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3013

            
3014
eval { $dbi->execute("drop table $table1") };
3015
$dbi->execute($create_table1_highperformance);
3016
$row = {
3017
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3018
};
3019
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3020
$model->insert($row);
3021
$query = $model->delete(id => 1, query => 1);
3022
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3023
is_deeply($dbi->select(table => $table1)->all, []);
3024

            
3025
eval { $dbi->execute("drop table $table1") };
3026
eval { $dbi->execute($create_table1_highperformance) };
3027
$row = {
3028
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3029
};
3030
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3031
$model->insert($row);
3032
$query = $model->select(id => 1, query => 1);
3033
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3034
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3035
is_deeply($dbi->select(table => $table1)->one,
3036
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3037
);
3038

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3039
test 'result';
3040
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3041
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3042
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3043
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3044
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3045

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3046
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3047
@rows = ();
3048
while (my $row = $result->fetch) {
3049
    push @rows, [@$row];
3050
}
3051
is_deeply(\@rows, [[1, 2], [3, 4]]);
3052

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3053
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3054
@rows = ();
3055
while (my $row = $result->fetch_hash) {
3056
    push @rows, {%$row};
3057
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3058
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3059

            
3060
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3061
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3062
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3063
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3064
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3065

            
3066
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3067
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3068
$rows = $result->fetch_all;
3069
is_deeply($rows, [[1, 2], [3, 4]]);
3070

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3071
$result = $dbi->select(table => $table1);
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 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3074

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

            
3079
$rows = $result->fetch_all;
3080
is_deeply($rows, [[3, 2], [9, 4]], "array");
3081

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

            
3088
test "query_builder";
3089
$datas = [
3090
    # Basic tests
3091
    {   name            => 'placeholder basic',
3092
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3093
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3094
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3095
    },
3096
    {
3097
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3098
        source            => "{in k1 3}",
3099
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3100
        columns_expected   => [qw/k1 k1 k1/]
3101
    },
3102
    
3103
    # Table name
3104
    {
3105
        name            => 'placeholder with table name',
3106
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3107
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3108
        columns_expected  => [qw/a.k1 a.k2/]
3109
    },
3110
    {   
3111
        name            => 'placeholder in with table name',
3112
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3113
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3114
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3115
    },
3116
    {
3117
        name            => 'not contain tag',
3118
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3119
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3120
        columns_expected  => [],
3121
    }
3122
];
3123

            
3124
for (my $i = 0; $i < @$datas; $i++) {
3125
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3126
    my $dbi = DBIx::Custom->new;
3127
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3128
    my $query = $builder->build_query($data->{source});
3129
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3130
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3131
}
3132

            
cleanup
Yuki Kimoto authored on 2011-08-13
3133
$dbi = DBIx::Custom->new;
3134
$builder = $dbi->query_builder;
3135
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3136
    p => sub {
3137
        my @args = @_;
3138
        
3139
        my $expand    = "? $args[0] $args[1]";
3140
        my $columns = [2];
3141
        return [$expand, $columns];
3142
    }
3143
);
3144

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3155
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3156
    q => 'string'
3157
});
3158

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3162
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3163
   r => sub {} 
3164
});
3165

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3169
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3170
   s => sub { return ["a", ""]} 
3171
});
3172

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3176
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3177
    t => sub {return ["a", []]}
3178
);
3179

            
3180

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

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

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

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

            
3196
test 'variouse source';
3197
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3198
$query = $builder->build_query($source);
3199
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3200

            
3201
$source = "abc";
3202
$query = $builder->build_query($source);
3203
is($query->sql, 'abc', "basic : 2");
3204

            
3205
$source = "{= a}";
3206
$query = $builder->build_query($source);
3207
is($query->sql, 'a = ?', "only tag");
3208

            
3209
$source = "000";
3210
$query = $builder->build_query($source);
3211
is($query->sql, '000', "contain 0 value");
3212

            
3213
$source = "a {= b} }";
3214
eval{$builder->build_query($source)};
3215
like($@, qr/unexpected "}"/, "error : 1");
3216

            
3217
$source = "a {= {}";
3218
eval{$builder->build_query($source)};
3219
like($@, qr/unexpected "{"/, "error : 2");
3220

            
3221
test 'select() sqlfilter option';
3222
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3223
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3224
eval { $dbi->execute("drop table $table1") };
3225
$dbi->execute($create_table1);
3226
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3227
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3228
$rows = $dbi->select(
3229
    table => $table1,
3230
    column => $key1,
3231
    sqlfilter => sub {
3232
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
3233
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
3234
        return $sql;
3235
    }
3236
)->all;
3237
is_deeply($rows, [{$key1 => 1}]);
3238

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3239
test 'select() after_build_sql option';
3240
$dbi = DBIx::Custom->connect;
3241
$dbi->user_table_info($user_table_info);
3242
eval { $dbi->execute("drop table $table1") };
3243
$dbi->execute($create_table1);
3244
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3245
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3246
$rows = $dbi->select(
3247
    table => $table1,
3248
    column => $key1,
3249
    after_build_sql => sub {
3250
        my $sql = shift;
3251
        $sql = "select * from ( $sql ) t where $key1 = 1";
3252
        return $sql;
3253
    }
3254
)->all;
3255
is_deeply($rows, [{$key1 => 1}]);
3256

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3257
test 'dbi method from model';
3258
$dbi = MyDBI9->connect;
3259
eval { $dbi->execute("drop table $table1") };
3260
$dbi->execute($create_table1);
3261
$dbi->setup_model;
3262
$model = $dbi->model($table1);
3263
eval{$model->execute("select * from $table1")};
3264
ok(!$@);
3265

            
3266
test 'column table option';
3267
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3268
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3269
eval { $dbi->execute("drop table $table1") };
3270
$dbi->execute($create_table1);
3271
eval { $dbi->execute("drop table $table2") };
3272
$dbi->execute($create_table2);
3273
$dbi->setup_model;
3274
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3275
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3276
$model = $dbi->model($table1);
3277
$result = $model->select(
3278
    column => [
3279
        $model->column($table2, {alias => $table2_alias})
3280
    ],
3281
    where => {"$table2_alias.$key3" => 4}
3282
);
3283
is_deeply($result->one, 
3284
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3285

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

            
3296
$dbi->separator('-');
3297
$result = $model->select(
3298
    column => [
3299
        $model->column($table2, {alias => $table2_alias})
3300
    ],
3301
    where => {"$table2_alias.$key3" => 4}
3302
);
3303
is_deeply($result->one, 
3304
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3305

            
3306
test 'create_model';
3307
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3308
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3309
eval { $dbi->execute("drop table $table1") };
3310
eval { $dbi->execute("drop table $table2") };
3311
$dbi->execute($create_table1);
3312
$dbi->execute($create_table2);
3313

            
3314
$dbi->create_model(
3315
    table => $table1,
3316
    join => [
3317
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3318
    ],
3319
    primary_key => [$key1]
3320
);
3321
$model2 = $dbi->create_model(
3322
    table => $table2
3323
);
3324
$dbi->create_model(
3325
    table => $table3,
3326
    filter => [
3327
        $key1 => {in => sub { uc $_[0] }}
3328
    ]
3329
);
3330
$dbi->setup_model;
3331
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3332
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3333
$model = $dbi->model($table1);
3334
$result = $model->select(
3335
    column => [$model->mycolumn, $model->column($table2)],
3336
    where => {"$table1.$key1" => 1}
3337
);
3338
is_deeply($result->one,
3339
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3340
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3341

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

            
3353
test 'model helper';
3354
$dbi = DBIx::Custom->connect;
3355
eval { $dbi->execute("drop table $table2") };
3356
$dbi->execute($create_table2);
3357
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3358
$model = $dbi->create_model(
3359
    table => $table2
3360
);
3361
$model->helper(foo => sub { shift->select(@_) });
3362
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3363

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3364
test 'assign_clause';
cleanup test
Yuki Kimoto authored on 2011-08-15
3365
$dbi = DBIx::Custom->connect;
3366
eval { $dbi->execute("drop table $table1") };
3367
$dbi->execute($create_table1_2);
3368
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3369
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3370

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

            
3384

            
3385
$dbi = DBIx::Custom->connect;
3386
eval { $dbi->execute("drop table $table1") };
3387
$dbi->execute($create_table1_2);
3388
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3389
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3390

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

            
3404
$dbi = DBIx::Custom->connect;
3405
eval { $dbi->execute("drop table $table1") };
3406
$dbi->execute($create_table1_2);
3407
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3408
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3409

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

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

            
3427
$dbi = DBIx::Custom->connect;
3428
eval { $dbi->execute("drop table $table1") };
3429
$dbi->execute($create_table1_2);
3430
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3431
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3432

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3433
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3434
$assign_clause = $dbi->assign_param($param);
3435
$sql = <<"EOS";
3436
update $table1 set $assign_clause
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");
3445

            
3446
$param = {$key2 => 11};
3447
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3448
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3449
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3450
where $key1 = 1
3451
EOS
3452
$dbi->execute($sql, param => $param, table => $table1);
3453
$result = $dbi->execute("select * from $table1 order by $key1");
3454
$rows   = $result->all;
3455
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3456
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3457
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3458

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3459
test 'Model class';
3460
$dbi = MyDBI1->connect;
3461
eval { $dbi->execute("drop table $table1") };
3462
$dbi->execute($create_table1);
3463
$model = $dbi->model($table1);
3464
$model->insert({$key1 => 'a', $key2 => 'b'});
3465
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3466
eval { $dbi->execute("drop table $table2") };
3467
$dbi->execute($create_table2);
3468
$model = $dbi->model($table2);
3469
$model->insert({$key1 => 'a'});
3470
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3471
is($dbi->models->{$table1}, $dbi->model($table1));
3472
is($dbi->models->{$table2}, $dbi->model($table2));
3473

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

            
3486
$dbi = MyDBI5->connect;
3487
eval { $dbi->execute("drop table $table1") };
3488
eval { $dbi->execute("drop table $table2") };
3489
$dbi->execute($create_table1);
3490
$dbi->execute($create_table2);
3491
$model = $dbi->model($table2);
3492
$model->insert({$key1 => 'a'});
3493
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3494
$dbi->insert(table => $table1, param => {$key1 => 1});
3495
$model = $dbi->model($table1);
3496
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3497

            
3498
test 'primary_key';
3499
$dbi = MyDBI1->connect;
3500
$model = $dbi->model($table1);
3501
$model->primary_key([$key1, $key2]);
3502
is_deeply($model->primary_key, [$key1, $key2]);
3503

            
3504
test 'columns';
3505
$dbi = MyDBI1->connect;
3506
$model = $dbi->model($table1);
3507
$model->columns([$key1, $key2]);
3508
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3509

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3510
test 'setup_model';
3511
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3512
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3513
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3514
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3515

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3516
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3517
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3518
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3519
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3520
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3521

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3522
test 'each_column';
3523
$dbi = DBIx::Custom->connect;
3524
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3525
eval { $dbi->execute("drop table $table1") };
3526
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3527
eval { $dbi->execute("drop table $table3") };
3528
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3529
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3530

            
3531
$infos = [];
3532
$dbi->each_column(sub {
3533
    my ($self, $table, $column, $cinfo) = @_;
3534
    
3535
    if ($table =~ /^table\d/i) {
3536
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3537
         push @$infos, $info;
3538
    }
3539
});
3540
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3541
is_deeply($infos, 
3542
    [
3543
        [$table1, $key1, $key1],
3544
        [$table1, $key2, $key2],
3545
        [$table2, $key1, $key1],
3546
        [$table2, $key3, $key3]
3547
    ]
3548
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3549
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3550

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3551
test 'each_table';
3552
$dbi = DBIx::Custom->connect;
3553
eval { $dbi->execute("drop table $table1") };
3554
eval { $dbi->execute("drop table $table2") };
3555
$dbi->execute($create_table2);
3556
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3557

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3558
$infos = [];
3559
$dbi->each_table(sub {
3560
    my ($self, $table, $table_info) = @_;
3561
    
3562
    if ($table =~ /^table\d/i) {
3563
         my $info = [$table, $table_info->{TABLE_NAME}];
3564
         push @$infos, $info;
3565
    }
3566
});
3567
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3568
is_deeply($infos, 
3569
    [
3570
        [$table1, $table1],
3571
        [$table2, $table2],
3572
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3573
);
3574

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

            
3581
$infos = [];
3582
$dbi->user_table_info($user_table_info);
3583
$dbi->each_table(sub {
3584
    my ($self, $table, $table_info) = @_;
3585
    
3586
    if ($table =~ /^table\d/i) {
3587
         my $info = [$table, $table_info->{TABLE_NAME}];
3588
         push @$infos, $info;
3589
    }
3590
});
3591
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3592
is_deeply($infos, 
3593
    [
3594
        [$table1, $table1],
3595
        [$table2, $table2],
3596
        [$table3, $table3],
3597
    ]
3598
);
3599

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3600
test 'type_rule into';
3601
eval { $dbi->execute("drop table $table1") };
3602
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3603
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3604

            
3605

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3606
$dbi = DBIx::Custom->connect;
3607
eval { $dbi->execute("drop table $table1") };
3608
$dbi->execute($create_table1_type);
3609

            
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 => sub { '2010-' . $_[0] }
3614
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3615
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3616
$dbi->insert({$key1 => '01-01'}, table => $table1);
3617
$result = $dbi->select(table => $table1);
3618
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3619

            
3620
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3621
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3622
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3623
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3624
$dbi->type_rule(
3625
    into1 => [
3626
         [$date_typename, $datetime_typename] => sub {
3627
            my $value = shift;
3628
            $value =~ s/02/03/g;
3629
            return $value;
3630
         }
3631
    ]
3632
);
3633
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3634
$result = $dbi->select(table => $table1);
3635
$row = $result->one;
3636
like($row->{$key1}, qr/^2010-01-03/);
3637
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3638

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

            
3661
$dbi = DBIx::Custom->connect;
3662
eval { $dbi->execute("drop table $table1") };
3663
$dbi->execute($create_table1_type);
3664
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3665
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3666
$dbi->type_rule(
3667
    into1 => [
3668
        [$date_typename, $datetime_typename] => sub {
3669
            my $value = shift;
3670
            $value =~ s/02/03/g;
3671
            return $value;
3672
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3673
    ]
3674
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3675
$result = $dbi->execute(
3676
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3677
    param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
3678
    table => $table1
3679
);
3680
$row = $result->one;
3681
like($row->{$key1}, qr/^2010-01-03/);
3682
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3683

            
3684
$dbi = DBIx::Custom->connect;
3685
eval { $dbi->execute("drop table $table1") };
3686
$dbi->execute($create_table1_type);
3687
$dbi->register_filter(convert => sub {
3688
    my $value = shift || '';
3689
    $value =~ s/02/03/;
3690
    return $value;
3691
});
cleanup
Yuki Kimoto authored on 2011-08-16
3692
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3693
$dbi->type_rule(
3694
    from1 => {
3695
        $date_datatype => 'convert',
3696
    },
3697
    into1 => {
3698
        $date_typename => 'convert',
3699
    }
3700
);
3701
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3702
$result = $dbi->select(table => $table1);
3703
like($result->fetch->[0], qr/^2010-03-03/);
3704

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

            
3730

            
3731
$dbi = DBIx::Custom->connect;
3732
eval { $dbi->execute("drop table $table1") };
3733
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3734
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3735
$dbi->type_rule(
3736
    from1 => {
3737
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3738
    },
3739
    from2 => {
3740
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3741
    },
3742
);
3743
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3744
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3745
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3746
$result->type_rule(
3747
    from1 => {
3748
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3749
    },
3750
    from2 => {
3751
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3752
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3753
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3754
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3755
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3756

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

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

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

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

            
3822
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3823
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3824
$dbi->execute($create_table1_type);
3825
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
3826
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3827
$dbi->type_rule(
3828
    into1 => {
3829
        $date_typename => 'ppp'
3830
    }
3831
);
3832
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3833
$result = $dbi->select(table => $table1);
3834
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3835

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3836
eval{$dbi->type_rule(
3837
    into1 => {
3838
        $date_typename => 'pp'
3839
    }
3840
)};
3841
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3842

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3843
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3844
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3845
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3846
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3847
    $dbi->type_rule(
3848
        from1 => {
3849
            Date => sub { $_[0] * 2 },
3850
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3851
    );
3852
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3853
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3854

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3855
eval {
3856
    $dbi->type_rule(
3857
        into1 => {
3858
            Date => sub { $_[0] * 2 },
3859
        }
3860
    );
3861
};
3862
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3863

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

            
3881
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3882
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3883
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3884
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3885
$dbi->type_rule(
3886
    from1 => {
3887
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3888
        $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3889
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3890
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3891
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3892
$result = $dbi->select(table => $table1);
3893
$result->type_rule(
3894
    from1 => {
3895
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3896
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3897
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3898
$row = $result->one;
3899
like($row->{$key1}, qr/^2010-01-05/);
3900
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3901

            
3902
$result = $dbi->select(table => $table1);
3903
$result->type_rule(
3904
    from1 => {
3905
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3906
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3907
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3908
$row = $result->one;
3909
like($row->{$key1}, qr/2010-01-05/);
3910
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3911

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

            
3922
$result = $dbi->select(table => $table1);
3923
$result->type_rule(
3924
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
3925
);
3926
$row = $result->one;
3927
like($row->{$key1}, qr/2010-01-05/);
3928
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3929

            
3930
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
3931
$result = $dbi->select(table => $table1);
3932
$result->type_rule(
3933
    from1 => [$date_datatype => 'five']
3934
);
3935
$row = $result->one;
3936
like($row->{$key1}, qr/^2010-01-05/);
3937
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3938

            
3939
$result = $dbi->select(table => $table1);
3940
$result->type_rule(
3941
    from1 => [$date_datatype => undef]
3942
);
3943
$row = $result->one;
3944
like($row->{$key1}, qr/^2010-01-03/);
3945
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3946

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3961
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3962
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3963
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3964
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3965
$dbi->type_rule(
3966
    from1 => {
3967
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3968
    },
3969
);
3970
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3971
$result = $dbi->select(table => $table1);
3972
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3973
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3974

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4023
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4024
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4025
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4026
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4027
$dbi->type_rule(
4028
    into1 => {
4029
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4030
    },
4031
    into2 => {
4032
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4033
    },
4034
    from1 => {
4035
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4036
    },
4037
    from2 => {
4038
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4039
    }
4040
);
4041
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4042
$result = $dbi->select(table => $table1);
4043
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
4044
$result = $dbi->select(table => $table1);
4045
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4046

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4047
test 'join';
4048
$dbi = DBIx::Custom->connect;
4049
eval { $dbi->execute("drop table $table1") };
4050
$dbi->execute($create_table1);
4051
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4052
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
4053
eval { $dbi->execute("drop table $table2") };
4054
$dbi->execute($create_table2);
4055
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4056
eval { $dbi->execute("drop table $table3") };
4057
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
4058
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
4059
$rows = $dbi->select(
4060
    table => $table1,
4061
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4062
    where   => {"$table1.$key2" => 2},
4063
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4064
)->all;
4065
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
4066

            
4067
$rows = $dbi->select(
4068
    table => $table1,
4069
    where   => {$key1 => 1},
4070
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4071
)->all;
4072
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4073

            
4074
$rows = $dbi->select(
4075
    table => $table1,
4076
    where   => {$key1 => 1},
4077
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4078
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4079
)->all;
4080
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4081

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

            
4091
$rows = $dbi->select(
4092
    column => "$table1.$key1 as ${table1}__$key1",
4093
    table => $table1,
4094
    where   => {"$table3.$key4" => 4},
4095
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4096
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4097
)->all;
4098
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4099

            
4100
$dbi = DBIx::Custom->connect;
4101
eval { $dbi->execute("drop table $table1") };
4102
$dbi->execute($create_table1);
4103
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4104
eval { $dbi->execute("drop table $table2") };
4105
$dbi->execute($create_table2);
4106
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4107
$rows = $dbi->select(
4108
    table => $table1,
4109
    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",
4110
    where   => {"$table1.$key2" => 2},
4111
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4112
)->all;
4113
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4114
          'quote');
4115

            
4116

            
4117
$dbi = DBIx::Custom->connect;
4118
eval { $dbi->execute("drop table $table1") };
4119
$dbi->execute($create_table1);
4120
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4121
$sql = <<"EOS";
4122
left outer join (
4123
  select * from $table1 t1
4124
  where t1.$key2 = (
4125
    select max(t2.$key2) from $table1 t2
4126
    where t1.$key1 = t2.$key1
4127
  )
4128
) $table3 on $table1.$key1 = $table3.$key1
4129
EOS
4130
$join = [$sql];
4131
$rows = $dbi->select(
4132
    table => $table1,
4133
    column => "$table3.$key1 as ${table3}__$key1",
4134
    join  => $join
4135
)->all;
4136
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4137

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

            
4170
$dbi = DBIx::Custom->connect;
4171
eval { $dbi->execute("drop table $table1") };
4172
eval { $dbi->execute("drop table $table2") };
4173
$dbi->execute($create_table1);
4174
$dbi->execute($create_table2);
4175
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4176
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4177
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4178
$result = $dbi->select(
4179
    table => $table1,
4180
    column => [{$table2 => [$key3]}],
4181
    join => [
4182
        {
4183
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4184
            table => [$table1, $table2]
4185
        }
4186
    ]
4187
);
4188
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4189

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4190
$dbi = DBIx::Custom->connect;
4191
eval { $dbi->execute("drop table $table1") };
4192
eval { $dbi->execute("drop table $table2") };
4193
$dbi->execute($create_table1);
4194
$dbi->execute($create_table2);
4195
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4196
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4197
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4198
$result = $dbi->select(
4199
    table => $table1,
4200
    column => [{$table2 => [$key3]}],
4201
    join => [
4202
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4203
    ]
4204
);
4205
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4206

            
4207
$dbi = DBIx::Custom->connect;
4208
eval { $dbi->execute("drop table $table1") };
4209
eval { $dbi->execute("drop table $table2") };
4210
$dbi->execute($create_table1);
4211
$dbi->execute($create_table2);
4212
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4213
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4214
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4215
$result = $dbi->select(
4216
    table => $table1,
4217
    column => [{$table2 => [$key3]}],
4218
    join => [
4219
        "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4220
    ]
4221
);
4222
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4223

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4224
test 'columns';
4225
$dbi = MyDBI1->connect;
4226
$model = $dbi->model($table1);
4227

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4228
test 'count';
4229
$dbi = DBIx::Custom->connect;
4230
eval { $dbi->execute("drop table $table1") };
4231
$dbi->execute($create_table1);
4232
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4233
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 3});
4234
is($dbi->count(table => $table1), 2);
4235
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4236
$model = $dbi->create_model(table => $table1);
4237
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4238

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