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

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
549
eval { $dbi->execute("drop table $table1") };
550
$dbi->execute($create_table1_2);
551
$param = {$key1 => 1};
552
$dbi->insert(table => $table1, param => $param, created_at => $key2);
553
$result = $dbi->select(table => $table1);
554
is_deeply($param, {$key1 => 1});
555
$row   = $result->one;
556
is($row->{$key1}, 1);
557
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
558

            
559
eval { $dbi->execute("drop table $table1") };
560
$dbi->execute($create_table1_2);
561
$param = {$key1 => 1};
562
$dbi->insert(table => $table1, param => $param, updated_at => $key3);
563
$result = $dbi->select(table => $table1);
564
is_deeply($param, {$key1 => 1});
565
$row   = $result->one;
566
is($row->{$key1}, 1);
567
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
568

            
569
eval { $dbi->execute("drop table $table1") };
570
$dbi->execute($create_table1_2);
571
$param = {$key1 => 1};
572
$dbi->insert(table => $table1, param => $param, created_at => $key2, updated_at => $key3);
573
$result = $dbi->select(table => $table1);
574
is_deeply($param, {$key1 => 1});
575
$row   = $result->one;
576
is($row->{$key1}, 1);
577
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
578
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
579
is($row->{$key2}, $row->{$key3});
580

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
581
eval { $dbi->execute("drop table $table1") };
582
$dbi->execute($create_table1_2);
583
$model = $dbi->create_model(table => $table1, created_at => $key2);
584
$param = {$key1 => 1};
585
$model->insert($param);
586
$result = $dbi->select(table => $table1);
587
is_deeply($param, {$key1 => 1});
588
$row   = $result->one;
589
is($row->{$key1}, 1);
590
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
591

            
592
eval { $dbi->execute("drop table $table1") };
593
$dbi->execute($create_table1_2);
594
$param = {$key1 => 1};
595
$model = $dbi->create_model(table => $table1, updated_at => $key3);
596
$model->insert($param);
597
$result = $dbi->select(table => $table1);
598
is_deeply($param, {$key1 => 1});
599
$row   = $result->one;
600
is($row->{$key1}, 1);
601
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
602

            
603
eval { $dbi->execute("drop table $table1") };
604
$dbi->execute($create_table1_2);
605
$param = {$key1 => 1};
606
$model = $dbi->create_model(table => $table1, created_at => $key2, updated_at => $key3);
607
$model->insert($param);
608
$result = $dbi->select(table => $table1);
609
is_deeply($param, {$key1 => 1});
610
$row   = $result->one;
611
is($row->{$key1}, 1);
612
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
613
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
614
is($row->{$key2}, $row->{$key3});
615

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
616
test 'update_or_insert';
617
eval { $dbi->execute("drop table $table1") };
618
$dbi->execute($create_table1);
619
$dbi->update_or_insert(
620
    {$key2 => 2},
621
    table => $table1,
622
    primary_key => $key1,
623
    id => 1
624
);
625
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
626
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
627

            
628
$dbi->update_or_insert(
629
    {$key2 => 3},
630
    table => $table1,
631
    primary_key => $key1,
632
    id => 1
633
);
634
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
635
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
636

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
637
eval {
638
    $dbi->update_or_insert(
639
        {$key2 => 3},
640
        table => $table1,
641
    );
642
};
643

            
644
like($@, qr/primary_key/);
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
645

            
micro optimization
Yuki Kimoto authored on 2011-10-31
646
test 'model update_or_insert';
647
eval { $dbi->execute("drop table $table1") };
648
$dbi->execute($create_table1);
649
$model = $dbi->create_model(
650
    table => $table1,
651
    primary_key => $key1
652
);
653
$model->update_or_insert({$key2 => 2}, id => 1);
654
$row = $model->select(id => 1)->one;
655
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
656

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
657
test 'default_bind_filter';
658
$dbi->execute("delete from $table1");
659
$dbi->register_filter(
660
    twice       => sub { $_[0] * 2 },
661
    three_times => sub { $_[0] * 3 }
662
);
663
$dbi->default_bind_filter('twice');
664
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => 'three_times'});
665
$result = $dbi->execute("select * from $table1");
666
$rows   = $result->all;
667
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
668
$dbi->default_bind_filter(undef);
669

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
699
$dbi->execute("delete from $table1");
700
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
701
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
702
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
703
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1},
704
              filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
705
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
706
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
707
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
708
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
709
                  "filter");
710

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
716
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
717
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
718
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
719
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
720
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
721
$where->param({$key1 => 1, $key2 => 2});
722
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
723
$result = $dbi->select(table => $table1);
724
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
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);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
728
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
729
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
730
    table => $table1,
731
    param => {$key1 => 3},
test cleanup
Yuki Kimoto authored on 2011-08-10
732
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
733
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
734
        {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
735
    ]
736
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
737
$result = $dbi->select(table => $table1);
738
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
739

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
740
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
741
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
742
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
743
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
744
$where->clause(['and', "$key2 = :$key2"]);
745
$where->param({$key2 => 2});
746
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
747
$result = $dbi->select(table => $table1);
748
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
749

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
756
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
757
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
758
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
759
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
760
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
761
$dbi->insert(table => 'table', param => {select => 1});
762
$dbi->update(table => 'table', where => {select => 1}, param => {update => 2});
763
$result = $dbi->execute("select * from ${q}table$p");
764
$rows   = $result->all;
765
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
766

            
767
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
768
like($@, qr/safety/);
769

            
770
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
771
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
772
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
773
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
774
$dbi->insert(table => 'table', param => {select => 1});
775
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
776
$result = $dbi->execute("select * from ${q}table$p");
777
$rows   = $result->all;
778
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
779

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
780
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
781
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
782
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
783
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
784
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
785
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
786
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
787
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
788
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
789
                  "basic");
790

            
updated pod
Yuki Kimoto authored on 2011-09-02
791
eval { $dbi->execute("drop table $table1") };
792
$dbi->execute($create_table1_2);
793
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
794
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
795
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1},
796
wrap => {$key2 => sub { "$_[0] - 1" }});
797
$result = $dbi->execute("select * from $table1 order by $key1");
798
$rows   = $result->all;
799
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5},
800
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
801
                  "basic");
802

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
803
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
804
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
805
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
806
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
807
$dbi->update(table => $table1, param => {$key2 => \"'11'"}, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
808
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
809
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
810
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
811
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
812
                  "basic");
813

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
814
eval { $dbi->execute("drop table $table1") };
815
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
816
$dbi->update_timestamp(
817
    $key1 => '5'
818
);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
819
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
820
$dbi->update(table => $table1, timestamp => 1, where => {$key2 => 2});
821
$result = $dbi->execute("select * from $table1");
822
$rows   = $result->all;
823
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
824

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
825
eval { $dbi->execute("drop table $table1") };
826
$dbi->execute($create_table1);
827
$dbi->update_timestamp(
828
    [$key1, $key2] => sub { '5' }
829
);
830
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
831
$dbi->update_all(table => $table1, timestamp => 1);
832
$result = $dbi->execute("select * from $table1");
833
$rows   = $result->all;
834
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
835

            
836
eval { $dbi->execute("drop table $table1") };
837
$dbi->execute($create_table1);
838
$dbi->update_timestamp(
839
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
840
);
841
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
842
$dbi->update_all(table => $table1, timestamp => 1);
843
$result = $dbi->execute("select * from $table1");
844
$rows   = $result->all;
845
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
846

            
micro optimization and
Yuki Kimoto authored on 2011-10-25
847
eval { $dbi->execute("drop table $table1") };
848
$dbi->execute($create_table1_2);
849
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
850
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
851
$param = {$key2 => 11};
852
$dbi->update($param, table => $table1, where => {$key1 => 1});
853
is_deeply($param, {$key2 => 11});
854
$result = $dbi->execute("select * from $table1 order by $key1");
855
$rows   = $result->all;
856
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
857
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
858
                  "basic");
859

            
860
eval { $dbi->execute("drop table $table1") };
861
$dbi->execute($create_table1_2);
862
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
863
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
864
$param = {$key2 => 11};
865
$dbi->update($param, table => $table1, where => {$key2 => 2});
866
is_deeply($param, {$key2 => 11});
867
$result = $dbi->execute("select * from $table1 order by $key1");
868
$rows   = $result->all;
869
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
870
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
871
                  "basic");
872

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
873
eval { $dbi->execute("drop table $table1") };
874
$dbi->execute($create_table1_2);
875
$param = {$key3 => 4};
876
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
877
$dbi->update(table => $table1, param => $param, updated_at => $key2, where => {$key1 => 1});
878
$result = $dbi->select(table => $table1);
879
is_deeply($param, {$key3 => 4});
880
$row   = $result->one;
881
is($row->{$key3}, 4);
882
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
883

            
884
eval { $dbi->execute("drop table $table1") };
885
$dbi->execute($create_table1_2);
886
$param = {$key3 => 4};
887
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
888
$dbi->update(table => $table1, param => $param, updated_at => $key2, where => {$key3 => 3});
889
$result = $dbi->select(table => $table1);
890
is_deeply($param, {$key3 => 4});
891
$row   = $result->one;
892
is($row->{$key3}, 4);
893
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
894

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
895
eval { $dbi->execute("drop table $table1") };
896
$dbi->execute($create_table1_2);
897
$model = $dbi->create_model(table => $table1, updated_at => $key2);
898
$param = {$key3 => 4};
899
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
900
$model->update($param, where => {$key1 => 1});
901
$result = $dbi->select(table => $table1);
902
is_deeply($param, {$key3 => 4});
903
$row   = $result->one;
904
is($row->{$key3}, 4);
905
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
906

            
test cleanup
Yuki Kimoto authored on 2011-08-10
907
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
908
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
909
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
910
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
911
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
912
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
913
$dbi->update_all(table => $table1, param => {$key2 => 10}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
914
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
915
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
916
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
917
                  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
918
                  "filter");
919

            
920

            
921
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
922
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
923
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
924
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
925
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
926
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
927
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
928
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
929
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
930

            
cleanup test
Yuki Kimoto authored on 2011-08-15
931
$dbi->execute("delete from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
932
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
933
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
934
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
935
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
936
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
937
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
938
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
939

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
942
$dbi->delete_all(table => $table1);
943
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
944
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
945
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
946
$rows = $dbi->select(table => $table1)->all;
947
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
948

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
949
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
950
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
951
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
952
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
953
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
954
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
955
$where->param({ke1 => 1, $key2 => 2});
956
$dbi->delete(table => $table1, where => $where);
957
$result = $dbi->select(table => $table1);
958
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
959

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
960
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
961
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
962
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
963
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
964
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
965
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
966
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
967
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
968
        {ke1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
969
    ]
970
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
971
$result = $dbi->select(table => $table1);
972
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
973

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
974
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
975
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
976
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
977
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
978
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
979
$rows   = $result->all;
980
is_deeply($rows, [], "basic");
981

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
991
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
992
$dbi = DBIx::Custom->connect;
993
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
994
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
995
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
996
$dbi->insert(table => 'table', param => {select => 1});
997
$dbi->delete(table => 'table', where => {select => 1});
998
$result = $dbi->execute("select * from ${q}table$p");
999
$rows   = $result->all;
1000
is_deeply($rows, [], "reserved word");
1001

            
1002
test 'delete_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1003
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1004
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1005
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1006
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1007
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1008
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1009
$rows   = $result->all;
1010
is_deeply($rows, [], "basic");
1011

            
1012

            
1013
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1014
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1015
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1016
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1017
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1018
$rows = $dbi->select(table => $table1)->all;
1019
is_deeply($rows, [{$key1 => 1, $key2 => 2},
1020
                  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
1021

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1036
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1037
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1038
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
test cleanup
Yuki Kimoto authored on 2011-08-10
1039
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1040
    table => [$table1, $table2],
1041
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
1042
    where   => {"$table1.$key2" => 2},
1043
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1044
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1045
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
1046

            
1047
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1048
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1049
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1050
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1051
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1052
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
1053

            
1054
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
1055
eval { $dbi->execute("drop table ${q}table$p") };
1056
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1057
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
1058
$dbi->insert(table => 'table', param => {select => 1, update => 2});
1059
$result = $dbi->select(table => 'table', where => {select => 1});
1060
$rows   = $result->all;
1061
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
1062

            
1063
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1064
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1065
$dbi->register_filter(
1066
    twice       => sub { $_[0] * 2 },
1067
    three_times => sub { $_[0] * 3 }
1068
);
1069
$dbi->default_fetch_filter('twice');
1070
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1071
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1072
$result = $dbi->select(table => $table1);
1073
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1074
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1075
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1076

            
1077
test 'filters';
1078
$dbi = DBIx::Custom->new;
1079

            
1080
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
1081
   'あ', "decode_utf8");
1082

            
1083
is($dbi->filters->{encode_utf8}->('あ'),
1084
   encode_utf8('あ'), "encode_utf8");
1085

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1086
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1087
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1088
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1089
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1090
$dbi->begin_work;
1091
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1092
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1093
$dbi->rollback;
1094
$dbi->dbh->{AutoCommit} = 1;
1095

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

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

            
1100
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1101
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1102
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1103
$dbi->begin_work;
1104
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1105
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1106
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1107
$dbi->commit;
1108
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1109
$result = $dbi->select(table => $table1);
1110
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1111
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1112

            
1113
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1114
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1115
$dbi->execute($create_table1);
1116
{
1117
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1118
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1119
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1120
    like($@, qr/\.t /, "fail : not verbose");
1121
}
1122
{
1123
    local $Carp::Verbose = 1;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1124
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1125
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1126
}
1127

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

            
1133
{
1134
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1135
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1136
    like($@, qr/\Q.t /, "caller spec : not vebose");
1137
}
1138
{
1139
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1140
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1141
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1142
}
1143

            
1144

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1145
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
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

            
1150
$dbi->begin_work;
1151

            
1152
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1153
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1154
    die "Error";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1155
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1156
};
1157

            
1158
$dbi->rollback if $@;
1159

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

            
1164
$dbi->begin_work;
1165

            
1166
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1167
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1168
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1169
};
1170

            
1171
$dbi->commit unless $@;
1172

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

            
1177
$dbi->dbh->{AutoCommit} = 0;
1178
eval{ $dbi->begin_work };
1179
ok($@, "exception");
1180
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1181

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1182
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1183
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1184
$dbi->cache(1);
1185
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1186
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1187
$dbi->execute($source, {}, query => 1);
1188
is_deeply($dbi->{_cached}->{$source}, 
cleanup test
Yuki Kimoto authored on 2011-08-15
1189
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1190

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1191
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1192
$dbi->execute($create_table1);
1193
$dbi->{_cached} = {};
1194
$dbi->cache(0);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1195
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1196
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1197

            
1198
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1199
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1200
$dbi->execute($create_table1);
1201
{
1202
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1203
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1204
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1205
    like($@, qr/\.t /, "fail : not verbose");
1206
}
1207
{
1208
    local $Carp::Verbose = 1;
- removed argument checking ...
Yuki Kimoto authored on 2011-10-21
1209
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1210
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1211
}
1212

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

            
1218
{
1219
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1220
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1221
    like($@, qr/\Q.t /, "caller spec : not vebose");
1222
}
1223
{
1224
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1225
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1226
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1227
}
1228

            
1229
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1230
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1231
    one => sub { 1 }
1232
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1233
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1234
    two => sub { 2 }
1235
);
1236
$dbi->method({
1237
    twice => sub {
1238
        my $self = shift;
1239
        return $_[0] * 2;
1240
    }
1241
});
1242

            
1243
is($dbi->one, 1, "first");
1244
is($dbi->two, 2, "second");
1245
is($dbi->twice(5), 10 , "second");
1246

            
1247
eval {$dbi->XXXXXX};
1248
ok($@, "not exists");
1249

            
1250
test 'out filter';
1251
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1252
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1253
$dbi->execute($create_table1);
1254
$dbi->register_filter(twice => sub { $_[0] * 2 });
1255
$dbi->register_filter(three_times => sub { $_[0] * 3});
1256
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1257
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1258
              $key2 => {out => 'three_times', in => 'twice'});
1259
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1260
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1261
$row   = $result->fetch_hash_first;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1262
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1263
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1264
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1265
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1266

            
1267
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1268
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1269
$dbi->execute($create_table1);
1270
$dbi->register_filter(twice => sub { $_[0] * 2 });
1271
$dbi->register_filter(three_times => sub { $_[0] * 3});
1272
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1273
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1274
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1275
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1276
    $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1277
); 
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1278
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1279
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1280
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1281
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1282

            
1283
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1284
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1285
$dbi->execute($create_table1);
1286
$dbi->register_filter(twice => sub { $_[0] * 2 });
1287
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1288
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1289
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1290
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => undef});
1291
$dbi->update(table => $table1, param => {$key1 => 2}, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1292
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1293
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1294
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
test cleanup
Yuki Kimoto authored on 2011-08-10
1295

            
1296
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1297
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1298
$dbi->execute($create_table1);
1299
$dbi->register_filter(twice => sub { $_[0] * 2 });
1300
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1301
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1302
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1303
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1=> undef});
1304
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1305
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1306
$rows   = $result->all;
1307
is_deeply($rows, [], "delete");
1308

            
1309
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1310
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1311
$dbi->execute($create_table1);
1312
$dbi->register_filter(twice => sub { $_[0] * 2 });
1313
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1314
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1315
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1316
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
1317
$result = $dbi->select(table => $table1, where => {$key1 => 1});
1318
$result->filter({$key2 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1319
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1320
is_deeply($rows, [{$key1 => 4, $key2 => 4}], "select");
test cleanup
Yuki Kimoto authored on 2011-08-10
1321

            
1322
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1323
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1324
$dbi->execute($create_table1);
1325
$dbi->register_filter(twice => sub { $_[0] * 2 });
1326
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1327
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1328
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1329
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1330
$result = $dbi->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1331
                        param => {$key1 => 1, $key2 => 2},
1332
                        table => [$table1]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1333
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1334
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute");
test cleanup
Yuki Kimoto authored on 2011-08-10
1335

            
1336
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1337
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1338
$dbi->execute($create_table1);
1339
$dbi->register_filter(twice => sub { $_[0] * 2 });
1340
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1341
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1342
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1343
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1344
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1345
                        param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1346
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1347
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1348

            
1349
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1350
eval { $dbi->execute("drop table $table1") };
1351
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1352
$dbi->execute($create_table1);
1353
$dbi->execute($create_table2);
1354
$dbi->register_filter(twice => sub { $_[0] * 2 });
1355
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1356
$dbi->apply_filter(
cleanup test
Yuki Kimoto authored on 2011-08-15
1357
    $table1, $key2 => {out => 'twice', in => 'twice'}
1358
);
1359
$dbi->apply_filter(
1360
    $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1361
);
cleanup test
Yuki Kimoto authored on 2011-08-15
1362
$dbi->insert(table => $table1, param => {$key1 => 5, $key2 => 2}, filter => {$key2 => undef});
1363
$dbi->insert(table => $table2, param => {$key1 => 5, $key3 => 6}, filter => {$key3 => undef});
1364
$result = $dbi->select(
1365
     table => [$table1, $table2],
1366
     column => [$key2, $key3],
1367
     where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1368

            
1369
$result->filter({$key2 => 'twice'});
1370
$rows   = $result->all;
1371
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1372

            
1373
$result = $dbi->select(
1374
     table => [$table1, $table2],
1375
     column => [$key2, $key3],
1376
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1377

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

            
1382
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1383
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1384
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1385
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1386
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1387
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1388

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1389
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1390
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1391
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1392
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1393
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1394
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1395

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1396
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1397
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1398
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1399
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1400
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1401

            
1402
test 'end_filter';
1403
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1404
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1405
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1406
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1407
$result = $dbi->select(table => $table1);
1408
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1409
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1410
$row = $result->fetch_first;
1411
is_deeply($row, [6, 40]);
1412

            
1413
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1414
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1415
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1416
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1417
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1418
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1419
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1420
$row = $result->fetch_first;
1421
is_deeply($row, [6, 12]);
1422

            
1423
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1424
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1425
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1426
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1427
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1428
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1429
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1430
$row = $result->fetch_first;
1431
is_deeply($row, [6, 12]);
1432

            
1433
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1434
$result = $dbi->select(table => $table1);
1435
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1436
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1437
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1438
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1439

            
1440
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1441
$dbi->apply_filter($table1,
1442
    $key1 => {end => sub { $_[0] * 3 } },
1443
    $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1444
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1445
$result = $dbi->select(table => $table1);
1446
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1447
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1448
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1449

            
1450
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1451
$dbi->apply_filter($table1,
1452
    $key1 => {end => sub { $_[0] * 3 } },
1453
    $key2 => {end => 'five_times'}
1454
);
1455
$result = $dbi->select(table => $table1);
1456
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1457
$result->filter($key1 => undef);
1458
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1459
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1460
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1461

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1462
test 'remove_end_filter and remove_filter';
1463
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1464
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1465
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1466
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1467
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1468
$row = $result
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1469
       ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1470
       ->remove_filter
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1471
       ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1472
       ->remove_end_filter
1473
       ->fetch_first;
1474
is_deeply($row, [1, 2]);
1475

            
1476
test 'empty where select';
1477
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1478
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1479
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1480
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1481
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1482
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1483
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1484

            
1485
test 'select query option';
1486
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1487
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1488
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1489
$query = $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1490
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1491
$query = $dbi->update(table => $table1, where => {$key1 => 1}, param => {$key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1492
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1493
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1494
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1495
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1496
is(ref $query, 'DBIx::Custom::Query');
1497

            
1498
test 'where';
1499
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1500
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1501
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1502
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1503
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1504
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1505
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1506

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

            
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}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1517

            
1518
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1519
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1520
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1521
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
1522
        {$key1 => 1}
test cleanup
Yuki Kimoto authored on 2011-08-10
1523
    ]
1524
);
1525
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1526
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
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(['and', "$key1 = :$key1", "$key2 = :$key2"])
1530
             ->param({$key1 => 1, $key2 => 2});
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}]);
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(['and', "$key1 = :$key1", "$key2 = :$key2"])
test cleanup
Yuki Kimoto authored on 2011-08-10
1540
             ->param({});
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}, {$key1 => 3, $key2 => 4}]);
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(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"])
1550
             ->param({$key1 => [0, 3], $key2 => 2});
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}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1557

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

            
1566
eval {
1567
$where = $dbi->where
1568
             ->clause(['uuu']);
1569
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1570
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1571
    where => $where
1572
);
1573
};
1574
ok($@);
1575

            
1576
$where = $dbi->where;
1577
is("$where", '');
1578

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

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

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

            
1609
$where = $dbi->where
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1610
             ->clause("$key1 = :$key1")
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1611
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1612
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1613
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1614
    where => $where,
1615
);
1616
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1617
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1618

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

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

            
1639
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1640
             ->clause(['or', ("$key1 = :$key1") x 3])
1641
             ->param({$key1 => [1, 3, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1642
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1643
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1644
    where => $where,
1645
);
1646
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1647
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1648

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

            
1659
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1660
             ->clause(['or', ("$key1 = :$key1") x 3])
1661
             ->param({$key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1662
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1663
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1664
    where => $where,
1665
);
1666
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1667
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1668

            
1669
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1670
             ->clause(['or', ("$key1 = :$key1") x 3])
1671
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1672
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1673
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1674
    where => $where,
1675
);
1676
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1677
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1678

            
1679
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1680
             ->clause(['or', ("$key1 = :$key1") x 3])
1681
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1682
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1683
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1684
    where => $where,
1685
);
1686
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1687
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1688

            
1689
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1690
             ->clause(['or', ("$key1 = :$key1") x 3])
1691
             ->param({$key1 => []});
test cleanup
Yuki Kimoto authored on 2011-08-10
1692
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1693
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1694
    where => $where,
1695
);
1696
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1697
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1698

            
1699
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1700
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1701
             ->param({$key1 => [2, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1702
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1703
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1704
    where => $where,
1705
);
1706
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1707
is_deeply($row, [{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1708

            
1709
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1710
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1711
             ->param({$key1 => [$dbi->not_exists, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1712
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1713
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1714
    where => $where,
1715
);
1716
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1717
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1718

            
1719
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1720
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1721
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1722
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1723
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1724
    where => $where,
1725
);
1726
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1727
is_deeply($row, [{$key1 => 1, $key2 => 2},{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1728

            
1729
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1730
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1731
             ->param({$key1 => [0, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1732
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1733
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1734
    where => $where,
1735
);
1736
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1737
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1738

            
1739
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1740
             ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1741
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1742
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1743
    where => $where,
1744
);
1745
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1746
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1747

            
1748
eval {$dbi->where(ppp => 1) };
1749
like($@, qr/invalid/);
1750

            
1751
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1752
    clause => ['and', ['or'], ['and', "$key1 = :$key1", "$key2 = :$key2"]],
1753
    param => {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
1754
);
1755
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1756
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1757
    where => $where,
1758
);
1759
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1760
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1761

            
1762

            
1763
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1764
    clause => ['and', ['or'], ['or', ":$key1", ":$key2"]],
test cleanup
Yuki Kimoto authored on 2011-08-10
1765
    param => {}
1766
);
1767
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1768
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1769
    where => $where,
1770
);
1771
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1772
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1773

            
1774
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1775
$where->clause(['and', ":${key1}{=}"]);
1776
$where->param({$key1 => undef});
1777
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1778
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1779
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1780

            
1781
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1782
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1783
$where->param({$key1 => [undef, undef]});
1784
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1785
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1786
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1787
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1788
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1789
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1790

            
1791
test 'register_tag_processor';
1792
$dbi = DBIx::Custom->connect;
1793
$dbi->register_tag_processor(
1794
    a => sub { 1 }
1795
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1796
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1797

            
1798
test 'register_tag';
1799
$dbi = DBIx::Custom->connect;
1800
$dbi->register_tag(
1801
    b => sub { 2 }
1802
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1803
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1804

            
1805
test 'table not specify exception';
1806
$dbi = DBIx::Custom->connect;
1807
eval {$dbi->select};
1808
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1809

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1810
test 'more tests';
1811
$dbi = DBIx::Custom->connect;
1812
eval{$dbi->apply_filter('table', 'column', [])};
1813
like($@, qr/apply_filter/);
1814

            
1815
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1816
like($@, qr/apply_filter/);
1817

            
1818
$dbi->apply_filter(
1819

            
1820
);
1821
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1822
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1823
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1824
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1825
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1826
$dbi->apply_filter($table1, $key2, 
test cleanup
Yuki Kimoto authored on 2011-08-10
1827
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1828
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
1829
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1830

            
1831
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1832
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1833
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1834
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1835
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1836
$dbi->apply_filter($table1, $key2, {});
1837
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1838
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1839

            
1840
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1841
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1842
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1843
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1844
like($@, qr/not registered/);
1845
$dbi->method({one => sub { 1 }});
1846
is($dbi->one, 1);
1847

            
1848
eval{DBIx::Custom->connect(dsn => undef)};
1849
like($@, qr/_connect/);
1850

            
1851
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1852
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1853
$dbi->execute($create_table1);
1854
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1855
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1856
             filter => {$key1 => 'twice'});
1857
$row = $dbi->select(table => $table1)->one;
1858
is_deeply($row, {$key1 => 2, $key2 => 2});
1859
eval {$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1860
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
1861
like($@, qr//);
1862

            
1863
$dbi->register_filter(one => sub { });
1864
$dbi->default_fetch_filter('one');
1865
ok($dbi->default_fetch_filter);
1866
$dbi->default_bind_filter('one');
1867
ok($dbi->default_bind_filter);
1868
eval{$dbi->default_fetch_filter('no')};
1869
like($@, qr/not registered/);
1870
eval{$dbi->default_bind_filter('no')};
1871
like($@, qr/not registered/);
1872
$dbi->default_bind_filter(undef);
1873
ok(!defined $dbi->default_bind_filter);
1874
$dbi->default_fetch_filter(undef);
1875
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1876
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1877
like($@, qr/Tag not finished/);
1878

            
1879
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1880
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1881
$dbi->execute($create_table1);
1882
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1883
$result = $dbi->select(table => $table1);
1884
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1885
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1886
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1887
like($@, qr/not registered/);
1888
$result->default_filter(undef);
1889
ok(!defined $result->default_filter);
1890
$result->default_filter('one');
1891
is($result->default_filter->(), 1);
1892

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1893
test 'option';
1894
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
1895
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
1896
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
1897
ok($dbi->dbh->{PrintError});
1898
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
1899
ok($dbi->dbh->{PrintError});
1900

            
1901
test 'DBIx::Custom::Result stash()';
1902
$result = DBIx::Custom::Result->new;
1903
is_deeply($result->stash, {}, 'default');
1904
$result->stash->{foo} = 1;
1905
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
1906

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1907
test 'delete_at';
1908
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1909
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1910
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1911
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1912
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1913
    table => $table1,
1914
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1915
    where => [1, 2],
1916
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1917
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1918

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1919
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1920
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1921
    table => $table1,
1922
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1923
    where => 1,
1924
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1925
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1926

            
1927
test 'insert_at';
1928
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1929
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1930
$dbi->execute($create_table1_2);
1931
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1932
    primary_key => [$key1, $key2], 
1933
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1934
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1935
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1936
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1937
is($dbi->select(table => $table1)->one->{$key1}, 1);
1938
is($dbi->select(table => $table1)->one->{$key2}, 2);
1939
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1940

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1941
$dbi->delete_all(table => $table1);
1942
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1943
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1944
    primary_key => $key1, 
1945
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1946
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1947
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1948
);
1949

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

            
1954
eval {
1955
    $dbi->insert_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 => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1959
        param => {$key1 => 1, $key2 => 2, $key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
1960
    );
1961
};
1962
like($@, qr/must be/);
1963

            
1964
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1965
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1966
$dbi->execute($create_table1_2);
1967
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1968
    {$key3 => 3},
1969
    primary_key => [$key1, $key2], 
1970
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1971
    where => [1, 2],
1972
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1973
is($dbi->select(table => $table1)->one->{$key1}, 1);
1974
is($dbi->select(table => $table1)->one->{$key2}, 2);
1975
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1976

            
1977
test 'update_at';
1978
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1979
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1980
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1981
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1982
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1983
    table => $table1,
1984
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1985
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1986
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
1987
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1988
is($dbi->select(table => $table1)->one->{$key1}, 1);
1989
is($dbi->select(table => $table1)->one->{$key2}, 2);
1990
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1991

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1992
$dbi->delete_all(table => $table1);
1993
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1994
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1995
    table => $table1,
1996
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1997
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1998
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
1999
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2000
is($dbi->select(table => $table1)->one->{$key1}, 1);
2001
is($dbi->select(table => $table1)->one->{$key2}, 2);
2002
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2003

            
2004
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2005
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2006
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2007
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2008
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2009
    {$key3 => 4},
2010
    table => $table1,
2011
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2012
    where => [1, 2]
2013
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2014
is($dbi->select(table => $table1)->one->{$key1}, 1);
2015
is($dbi->select(table => $table1)->one->{$key2}, 2);
2016
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2017

            
2018
test 'select_at';
2019
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2020
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2021
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2022
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2023
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2024
    table => $table1,
2025
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2026
    where => [1, 2]
2027
);
2028
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2029
is($row->{$key1}, 1);
2030
is($row->{$key2}, 2);
2031
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2032

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2033
$dbi->delete_all(table => $table1);
2034
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2035
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2036
    table => $table1,
2037
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2038
    where => 1,
2039
);
2040
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2041
is($row->{$key1}, 1);
2042
is($row->{$key2}, 2);
2043
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2044

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2045
$dbi->delete_all(table => $table1);
2046
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2047
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2048
    table => $table1,
2049
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2050
    where => [1, 2]
2051
);
2052
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2053
is($row->{$key1}, 1);
2054
is($row->{$key2}, 2);
2055
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2056

            
2057
eval {
2058
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2059
        table => $table1,
2060
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2061
        where => {},
2062
    );
2063
};
2064
like($@, qr/must be/);
2065

            
2066
eval {
2067
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2068
        table => $table1,
2069
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2070
        where => [1],
2071
    );
2072
};
2073
like($@, qr/same/);
2074

            
2075
eval {
2076
    $result = $dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2077
        table => $table1,
2078
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2079
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2080
        param => {$key1 => 1, $key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-10
2081
    );
2082
};
2083
like($@, qr/must be/);
2084

            
2085
eval {
2086
    $result = $dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2087
        table => $table1,
2088
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2089
        where => {},
2090
    );
2091
};
2092
like($@, qr/must be/);
2093

            
2094
test 'model delete_at';
2095
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2096
eval { $dbi->execute("drop table $table1") };
2097
eval { $dbi->execute("drop table $table2") };
2098
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2099
$dbi->execute($create_table1_2);
2100
$dbi->execute($create_table2_2);
2101
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2102
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2103
$dbi->model($table1)->delete_at(where => [1, 2]);
2104
is_deeply($dbi->select(table => $table1)->all, []);
2105
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2106
$dbi->model($table1)->delete_at(where => [1, 2]);
2107
is_deeply($dbi->select(table => $table1)->all, []);
2108
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2109
$dbi->model($table3)->delete_at(where => [1, 2]);
2110
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2111

            
2112
test 'model insert_at';
2113
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2114
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2115
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2116
$dbi->model($table1)->insert_at(
cleanup test
Yuki Kimoto authored on 2011-08-10
2117
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2118
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2119
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2120
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2121
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2122
is($row->{$key1}, 1);
2123
is($row->{$key2}, 2);
2124
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2125

            
2126
test 'model update_at';
2127
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2128
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2129
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2130
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2131
$dbi->model($table1)->update_at(
cleanup test
Yuki Kimoto authored on 2011-08-10
2132
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2133
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2134
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2135
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2136
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2137
is($row->{$key1}, 1);
2138
is($row->{$key2}, 2);
2139
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2140

            
2141
test 'model select_at';
2142
$dbi = MyDBI6->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_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2145
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2146
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2147
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2148
is($row->{$key1}, 1);
2149
is($row->{$key2}, 2);
2150
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2151

            
2152

            
2153
test 'mycolumn and column';
2154
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2155
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2156
eval { $dbi->execute("drop table $table1") };
2157
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2158
$dbi->execute($create_table1);
2159
$dbi->execute($create_table2);
2160
$dbi->separator('__');
2161
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2162
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2163
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2164
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2165
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2166
    column => [$model->mycolumn, $model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2167
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2168
);
2169
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2170
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2171

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2172
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2173
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2174
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2175
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2176
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2177
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2178
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2179
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2180
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2181
$dbi->execute($sql, param => $param, table => $table1);
2182
is($dbi->select(table => $table1)->one->{$key1}, 1);
2183
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2184

            
2185
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2186
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2187
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2188
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2189
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2190
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2191
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2192
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2193
$dbi->execute($sql, param => $param, table => $table1);
2194
is($dbi->select(table => $table1)->one->{$key1}, 1);
2195
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2196

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2200
test 'mycolumn';
2201
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2202
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2203
eval { $dbi->execute("drop table $table1") };
2204
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2205
$dbi->execute($create_table1);
2206
$dbi->execute($create_table2);
2207
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2208
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2209
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2210
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2211
$result = $model->select_at(
2212
    column => [
2213
        $model->mycolumn,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2214
        $model->column($table2)
cleanup test
Yuki Kimoto authored on 2011-08-10
2215
    ]
2216
);
2217
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2218
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2219

            
2220
$result = $model->select_at(
2221
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2222
        $model->mycolumn([$key1]),
2223
        $model->column($table2 => [$key1])
cleanup test
Yuki Kimoto authored on 2011-08-10
2224
    ]
2225
);
2226
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2227
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2228
$result = $model->select_at(
2229
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2230
        $model->mycolumn([$key1]),
2231
        {$table2 => [$key1]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2232
    ]
2233
);
2234
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2235
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2236

            
2237
$result = $model->select_at(
2238
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2239
        $model->mycolumn([$key1]),
2240
        ["$table2.$key1", as => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2241
    ]
2242
);
2243
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2244
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2245

            
2246
$result = $model->select_at(
2247
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2248
        $model->mycolumn([$key1]),
2249
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2250
    ]
2251
);
2252
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2253
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2254

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2255
test 'merge_param';
2256
$dbi = DBIx::Custom->new;
2257
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2258
    {$key1 => 1, $key2 => 2, $key3 => 3},
2259
    {$key1 => 1, $key2 => 2},
2260
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2261
];
2262
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2263
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2264

            
2265
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2266
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2267
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2268
];
2269
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2270
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
2271

            
2272
test 'select() param option';
2273
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2274
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2275
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2276
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2277
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2278
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2279
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2280
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
2281
$dbi->insert(table => $table2, param => {$key1 => 2, $key3 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-10
2282
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2283
    table => $table1,
2284
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2285
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2286
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
test cleanup
Yuki Kimoto authored on 2011-08-15
2287
              " $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2288
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2289
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2290
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2291

            
cleanup
Yuki Kimoto authored on 2011-10-21
2292
$rows = $dbi->select(
2293
    table => $table1,
2294
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2295
    where   => {"$table1.$key2" => 3},
2296
    join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2297
             " $table2 on $table1.$key1 = $table2.$key1",
2298
    param => {"$table2.$key3" => 5}
2299
)->all;
2300
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2301

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2302
test 'select() string where';
2303
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2304
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2305
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2306
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2307
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2308
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2309
    table => $table1,
2310
    where => "$key1 = :$key1 and $key2 = :$key2",
2311
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2312
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2313
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2314

            
2315
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2316
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2317
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2318
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2319
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2320
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2321
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2322
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2323
        "$key1 = :$key1 and $key2 = :$key2",
2324
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2325
    ]
2326
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2327
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2328

            
cleanup
Yuki Kimoto authored on 2011-10-21
2329
$dbi = DBIx::Custom->connect;
2330
eval { $dbi->execute("drop table $table1") };
2331
$dbi->execute($create_table1);
2332
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2333
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
2334
$rows = $dbi->select(
2335
    table => $table1,
2336
    where => [
2337
        "$key1 = :$key1 and $key2 = :$key2",
2338
        {$key1 => 1, $key2 => 2}
2339
    ]
2340
)->all;
2341
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2342

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2343
test 'delete() string where';
2344
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2345
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2346
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2347
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2348
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2349
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2350
    table => $table1,
2351
    where => "$key1 = :$key1 and $key2 = :$key2",
2352
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2353
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2354
$rows = $dbi->select(table => $table1)->all;
2355
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2356

            
2357
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2358
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2359
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2360
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2361
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2362
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2363
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2364
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2365
        "$key1 = :$key1 and $key2 = :$key2",
2366
         {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2367
    ]
2368
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2369
$rows = $dbi->select(table => $table1)->all;
2370
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2371

            
2372

            
2373
test 'update() string where';
2374
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2375
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2376
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2377
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2378
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2379
    table => $table1,
2380
    param => {$key1 => 5},
2381
    where => "$key1 = :$key1 and $key2 = :$key2",
2382
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2383
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2384
$rows = $dbi->select(table => $table1)->all;
2385
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2386

            
2387
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2388
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2389
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2390
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2391
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2392
    table => $table1,
2393
    param => {$key1 => 5},
cleanup test
Yuki Kimoto authored on 2011-08-10
2394
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2395
        "$key1 = :$key1 and $key2 = :$key2",
2396
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2397
    ]
2398
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2399
$rows = $dbi->select(table => $table1)->all;
2400
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2401

            
2402
test 'insert id and primary_key option';
2403
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2404
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2405
$dbi->execute($create_table1_2);
2406
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2407
    primary_key => [$key1, $key2], 
2408
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2409
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2410
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2411
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2412
is($dbi->select(table => $table1)->one->{$key1}, 1);
2413
is($dbi->select(table => $table1)->one->{$key2}, 2);
2414
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2415

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2416
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2417
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2418
    primary_key => $key1, 
2419
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2420
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2421
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2422
);
2423

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

            
2428
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2429
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2430
$dbi->execute($create_table1_2);
2431
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2432
    {$key3 => 3},
2433
    primary_key => [$key1, $key2], 
2434
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2435
    id => [1, 2],
2436
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2437
is($dbi->select(table => $table1)->one->{$key1}, 1);
2438
is($dbi->select(table => $table1)->one->{$key2}, 2);
2439
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2440

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2441
$dbi = DBIx::Custom->connect;
2442
eval { $dbi->execute("drop table $table1") };
2443
$dbi->execute($create_table1_2);
2444
$param = {$key3 => 3, $key2 => 4};
2445
$dbi->insert(
2446
    $param,
2447
    primary_key => [$key1, $key2], 
2448
    table => $table1,
2449
    id => [1, 2],
2450
);
2451
is($dbi->select(table => $table1)->one->{$key1}, 1);
2452
is($dbi->select(table => $table1)->one->{$key2}, 4);
2453
is($dbi->select(table => $table1)->one->{$key3}, 3);
2454
is_deeply($param, {$key3 => 3, $key2 => 4});
2455

            
added test
Yuki Kimoto authored on 2011-10-25
2456
$dbi = DBIx::Custom->connect;
2457
eval { $dbi->execute("drop table $table1") };
2458
$dbi->execute($create_table1_2);
2459
$param = {$key3 => 3, $key2 => 4};
2460
$query = $dbi->insert(
2461
    $param,
2462
    primary_key => [$key1, $key2], 
2463
    table => $table1,
2464
    id => [1, 2],
2465
    query => 1
2466
);
2467
is(ref $query, 'DBIx::Custom::Query');
2468
is_deeply($param, {$key3 => 3, $key2 => 4});
2469

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

            
2484
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2485
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2486
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2487
$dbi->model($table1)->insert(
2488
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2489
    id => [1, 2]
2490
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2491
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2492
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2493
is($row->{$key1}, 1);
2494
is($row->{$key2}, 2);
2495
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2496

            
2497
test 'update and id option';
2498
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2499
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2500
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2501
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2502
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2503
    table => $table1,
2504
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2505
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2506
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2507
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2508
is($dbi->select(table => $table1)->one->{$key1}, 1);
2509
is($dbi->select(table => $table1)->one->{$key2}, 2);
2510
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2511

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2512
$dbi->delete_all(table => $table1);
2513
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2514
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2515
    table => $table1,
2516
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2517
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2518
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2519
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2520
is($dbi->select(table => $table1)->one->{$key1}, 0);
2521
is($dbi->select(table => $table1)->one->{$key2}, 2);
2522
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2523

            
2524
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2525
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2526
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2527
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2528
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2529
    {$key3 => 4},
2530
    table => $table1,
2531
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2532
    id => [1, 2]
2533
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2534
is($dbi->select(table => $table1)->one->{$key1}, 1);
2535
is($dbi->select(table => $table1)->one->{$key2}, 2);
2536
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2537

            
2538

            
2539
test 'model update and id option';
2540
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2541
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2542
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2543
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2544
$dbi->model($table1)->update(
cleanup test
Yuki Kimoto authored on 2011-08-10
2545
    id => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2546
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2547
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2548
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2549
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2550
is($row->{$key1}, 1);
2551
is($row->{$key2}, 2);
2552
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2553

            
2554

            
2555
test 'delete and id option';
2556
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2557
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2558
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2559
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2560
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2561
    table => $table1,
2562
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2563
    id => [1, 2],
2564
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2565
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2566

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2567
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2568
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2569
    table => $table1,
2570
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2571
    id => 0,
2572
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2573
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2574

            
2575

            
2576
test 'model delete and id option';
2577
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2578
eval { $dbi->execute("drop table $table1") };
2579
eval { $dbi->execute("drop table $table2") };
2580
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2581
$dbi->execute($create_table1_2);
2582
$dbi->execute($create_table2_2);
2583
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2584
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2585
$dbi->model($table1)->delete(id => [1, 2]);
2586
is_deeply($dbi->select(table => $table1)->all, []);
2587
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2588
$dbi->model($table1)->delete(id => [1, 2]);
2589
is_deeply($dbi->select(table => $table1)->all, []);
2590
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2591
$dbi->model($table3)->delete(id => [1, 2]);
2592
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2593

            
2594

            
2595
test 'select and id option';
2596
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2597
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2598
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2599
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2600
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2601
    table => $table1,
2602
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2603
    id => [1, 2]
2604
);
2605
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2606
is($row->{$key1}, 1);
2607
is($row->{$key2}, 2);
2608
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2609

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2610
$dbi->delete_all(table => $table1);
2611
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2612
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2613
    table => $table1,
2614
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2615
    id => 0,
2616
);
2617
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2618
is($row->{$key1}, 0);
2619
is($row->{$key2}, 2);
2620
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2621

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2622
$dbi->delete_all(table => $table1);
2623
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2624
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2625
    table => $table1,
2626
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2627
    id => [1, 2]
2628
);
2629
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2630
is($row->{$key1}, 1);
2631
is($row->{$key2}, 2);
2632
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2633

            
2634

            
2635
test 'model select_at';
2636
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2637
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2638
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2639
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2640
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2641
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2642
is($row->{$key1}, 1);
2643
is($row->{$key2}, 2);
2644
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2645

            
2646
test 'column separator is default .';
2647
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2648
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2649
eval { $dbi->execute("drop table $table1") };
2650
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2651
$dbi->execute($create_table1);
2652
$dbi->execute($create_table2);
2653
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2654
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2655
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2656
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2657
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2658
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2659
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2660
);
2661
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2662
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2663

            
2664
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2665
    column => [$model->column($table2 => [$key1, $key3])],
2666
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2667
);
2668
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2669
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2670

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2671
test 'separator';
2672
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2673
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2674
eval { $dbi->execute("drop table $table1") };
2675
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2676
$dbi->execute($create_table1);
2677
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2678

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2679
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2680
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2681
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2682
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2683
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2684
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2685
);
2686
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2687
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2688
);
2689
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2690
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2691
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2692
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2693
$result = $model->select(
2694
    column => [
2695
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2696
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2697
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2698
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2699
);
2700
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2701
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2702
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2703

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2704
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2705
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2706
$result = $model->select(
2707
    column => [
2708
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2709
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2710
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2711
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2712
);
2713
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2714
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
2715
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2716

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2717
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2718
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2719
$result = $model->select(
2720
    column => [
2721
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2722
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2723
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2724
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2725
);
2726
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2727
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2728
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2729

            
2730

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2731
test 'filter_off';
2732
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2733
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2734
eval { $dbi->execute("drop table $table1") };
2735
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2736
$dbi->execute($create_table1);
2737
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2738

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2739
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2740
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2741
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2742
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2743
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2744
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2745
);
2746
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2747
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2748
$model = $dbi->model($table1);
2749
$result = $model->select(column => $key1);
2750
$result->filter($key1 => sub { $_[0] * 2 });
2751
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2752

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2753
test 'available_datetype';
2754
$dbi = DBIx::Custom->connect;
2755
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2756

            
2757

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2758
test 'select prefix option';
2759
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2760
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2761
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2762
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2763
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2764
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2765

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

            
added tests
Yuki Kimoto authored on 2011-08-26
2767
test 'mapper';
2768
$dbi = DBIx::Custom->connect;
2769
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2770
    id => {key => "$table1.id"},
2771
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2772
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
2773
);
2774
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2775
  "$table1.price" => 1900});
2776

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

            
added tests
Yuki Kimoto authored on 2011-08-26
2786
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2787
    id => {key => "$table1.id"},
2788
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2789
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
2790
);
2791
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2792

            
2793
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2794
    id => {key => "$table1.id"},
2795
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2796
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
added tests
Yuki Kimoto authored on 2011-08-26
2797
);
2798
is_deeply($param, {});
2799

            
2800
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2801
    id => {key => "$table1.id"},
2802
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2803
);
2804
is_deeply($param, {"$table1.price" => undef});
2805

            
2806
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2807
    id => {key => "$table1.id", condition => 'exists'},
2808
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
2809
);
2810
is_deeply($param, {"$table1.price" => '%a'});
2811

            
2812
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2813
    id => {key => "$table1.id"},
added tests
Yuki Kimoto authored on 2011-08-26
2814
    price => ["$table1.price", sub { '%' . $_[0] }]
2815
);
2816
is_deeply($param, {"$table1.price" => '%a'});
2817

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2818
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2819
    price => sub { '%' . $_[0] },
2820
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2821
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2822
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2823

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2824
eval { $dbi->execute("drop table $table1") };
2825
$dbi->execute($create_table1);
2826
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2827
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
2828

            
2829
$where = $dbi->where;
2830
$where->clause(['and', ":${key1}{=}"]);
2831
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
2832
$where->param($param);
2833
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2834
$row = $result->all;
2835
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2836

            
2837
$where = $dbi->where;
2838
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2839
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
2840
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2841
$row = $result->all;
2842
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2843
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2844
$row = $result->all;
2845
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2846

            
2847
$where = $dbi->where;
2848
$where->clause(['and', ":${key1}{=}"]);
2849
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
2850
$where->param($param);
2851
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2852
$row = $result->all;
2853
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2854
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2855
$row = $result->all;
2856
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2857

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2859
$where = $dbi->where;
2860
$where->clause(['and', ":${key1}{=}"]);
2861
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
2862
  ->pass([$key1, $key2])->map;
2863
$where->param($param);
2864
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2865
$row = $result->all;
2866
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2867

            
2868
$where = $dbi->where;
2869
$where->clause(['and', ":${key1}{=}"]);
2870
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
2871
$where->param($param);
2872
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2873
$row = $result->all;
2874
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2875

            
2876
$where = $dbi->where;
2877
$where->clause(['and', ":${key1}{=}"]);
2878
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
2879
  ->pass([$key1, $key2])->map;
2880
$where->param($param);
2881
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2882
$row = $result->all;
2883
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2884

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2886
$where = $dbi->where;
2887
$where->clause(['and', ":${key1}{=}"]);
2888
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
2889
$where->param($param);
2890
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2891
$row = $result->all;
2892
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2893

            
2894
$where = $dbi->where;
2895
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2896
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2897
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2898
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2899
);
2900
$where->param($param);
2901
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2902
  "$table1.price" => 1900});
2903

            
2904
$where = $dbi->where;
2905
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2906
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2907
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2908
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2909
);
2910
$where->param($param);
2911
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2912

            
2913
$where = $dbi->where;
2914
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2915
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2916
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2917
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2918
);
2919
$where->param($param);
2920
is_deeply($where->param, {});
2921

            
2922
$where = $dbi->where;
2923
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2924
    id => {key => "$table1.id"},
2925
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2926
);
2927
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
2928

            
2929
$where = $dbi->where;
2930
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2931
    id => {key => "$table1.id", condition => 'exists'},
2932
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2933
);
2934
is_deeply($param, {"$table1.price" => '%a'});
2935

            
2936
$where = $dbi->where;
2937
$param = $dbi->mapper(param => {id => [1, 2], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2938
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2939
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2940
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2941
);
2942
is_deeply($param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
2943
  "$table1.price" => 1900});
2944

            
2945
$where = $dbi->where;
2946
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900}, condition => 'length')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2947
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2948
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2949
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2950
);
2951
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2952
  "$table1.price" => 1900});
2953

            
2954
$where = $dbi->where;
2955
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2956
    id => {key => "$table1.id", condition => 'length'},
2957
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
2958
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2959
);
2960
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2961
  "$table1.price" => 1900});
2962

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2968
test 'order';
2969
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2970
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2971
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2972
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2973
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
2974
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
2975
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2976
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2977
$order->prepend($key1, "$key2 desc");
2978
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2979
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
2980
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2981
$order->prepend("$key1 desc");
2982
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2983
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
2984
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2985

            
2986
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2987
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2988
$result = $dbi->select(table => $table1,
2989
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2990
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2991
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
2992
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
2993
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
2994
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2995

            
2996
test 'tag_parse';
2997
$dbi = DBIx::Custom->connect;
2998
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2999
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3000
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3001
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3002
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3003
ok($@);
3004

            
3005
test 'last_sql';
3006
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3007
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3008
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3009
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
3010
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3011

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3043
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3044
$result = $dbi->execute(
3045
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3046
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3047
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3048
);
3049
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3050
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3051

            
3052
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3053
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3054
$dbi->execute($create_table1_highperformance);
3055
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3056
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3057
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3058
];
3059
{
3060
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3061
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3062
      $query ||= $dbi->insert($row, table => $table1, query => 1);
3063
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
3064
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3065
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3066
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3067
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3068
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3069
      ]
3070
    );
3071
}
3072

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3073
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3074
$dbi->execute($create_table1_highperformance);
3075
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3076
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3077
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3078
];
3079
{
3080
    my $query;
3081
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
3082
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3083
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3084
      $sth ||= $query->sth;
3085
      $sth->execute(map { $row->{$_} } sort keys %$row);
3086
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3087
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3088
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3089
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3090
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3091
      ]
3092
    );
3093
}
3094

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3095
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3096
$dbi->execute($create_table1_highperformance);
3097
$rows = [
3098
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
3099
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
3100
];
3101
{
3102
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3103
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3104
    for my $row (@$rows) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3105
      $query ||= $model->insert($row, query => 1);
3106
      $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3107
    }
3108
    is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3109
      [
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3110
          {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3111
          {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3112
      ]
3113
    );
3114
}
3115

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3116
test 'id option more';
3117
eval { $dbi->execute("drop table $table1") };
3118
$dbi->execute($create_table1_highperformance);
3119
$row = {
3120
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3121
};
3122
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3123
$model->insert($row);
3124
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3125
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3126
is_deeply($dbi->select(table => $table1)->one,
3127
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3128
);
3129

            
3130
eval { $dbi->execute("drop table $table1") };
3131
eval { $dbi->execute("drop table $table2") };
3132
$dbi->execute($create_table1);
3133
$dbi->execute($create_table2);
3134
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3135
$model->insert({$key1 => 1, $key2 => 2});
3136
$model = $dbi->create_model(table => $table2, primary_key => $key1,
3137
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
3138
$model->insert({$key1 => 1, $key3 => 3});
3139
$result = $model->select(
3140
    column => {$table1 => ["$key2"]},
3141
    id => 1
3142
);
3143
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3144

            
3145
eval { $dbi->execute("drop table $table1") };
3146
$dbi->execute($create_table1_highperformance);
3147
$row = {
3148
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3149
};
3150
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3151
$model->insert($row);
3152
$query = $model->delete(id => 1, query => 1);
3153
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3154
is_deeply($dbi->select(table => $table1)->all, []);
3155

            
3156
eval { $dbi->execute("drop table $table1") };
3157
eval { $dbi->execute($create_table1_highperformance) };
3158
$row = {
3159
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3160
};
3161
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3162
$model->insert($row);
3163
$query = $model->select(id => 1, query => 1);
3164
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3165
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3166
is_deeply($dbi->select(table => $table1)->one,
3167
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3168
);
3169

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3170
test 'result';
3171
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3172
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3173
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3174
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3175
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3176

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3177
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3178
@rows = ();
3179
while (my $row = $result->fetch) {
3180
    push @rows, [@$row];
3181
}
3182
is_deeply(\@rows, [[1, 2], [3, 4]]);
3183

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3184
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3185
@rows = ();
3186
while (my $row = $result->fetch_hash) {
3187
    push @rows, {%$row};
3188
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3189
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3190

            
3191
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3192
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3193
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3194
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3195
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3196

            
3197
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3198
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3199
$rows = $result->fetch_all;
3200
is_deeply($rows, [[1, 2], [3, 4]]);
3201

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

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

            
3210
$rows = $result->fetch_all;
3211
is_deeply($rows, [[3, 2], [9, 4]], "array");
3212

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

            
3219
test "query_builder";
3220
$datas = [
3221
    # Basic tests
3222
    {   name            => 'placeholder basic',
3223
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3224
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3225
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3226
    },
3227
    {
3228
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3229
        source            => "{in k1 3}",
3230
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3231
        columns_expected   => [qw/k1 k1 k1/]
3232
    },
3233
    
3234
    # Table name
3235
    {
3236
        name            => 'placeholder with table name',
3237
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3238
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3239
        columns_expected  => [qw/a.k1 a.k2/]
3240
    },
3241
    {   
3242
        name            => 'placeholder in with table name',
3243
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3244
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3245
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3246
    },
3247
    {
3248
        name            => 'not contain tag',
3249
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3250
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3251
        columns_expected  => [],
3252
    }
3253
];
3254

            
3255
for (my $i = 0; $i < @$datas; $i++) {
3256
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3257
    my $dbi = DBIx::Custom->new;
3258
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3259
    my $query = $builder->build_query($data->{source});
3260
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3261
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3262
}
3263

            
cleanup
Yuki Kimoto authored on 2011-08-13
3264
$dbi = DBIx::Custom->new;
3265
$builder = $dbi->query_builder;
3266
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3267
    p => sub {
3268
        my @args = @_;
3269
        
3270
        my $expand    = "? $args[0] $args[1]";
3271
        my $columns = [2];
3272
        return [$expand, $columns];
3273
    }
3274
);
3275

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3286
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3287
    q => 'string'
3288
});
3289

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3293
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3294
   r => sub {} 
3295
});
3296

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3300
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3301
   s => sub { return ["a", ""]} 
3302
});
3303

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3307
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3308
    t => sub {return ["a", []]}
3309
);
3310

            
3311

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

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

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

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

            
3327
test 'variouse source';
3328
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3329
$query = $builder->build_query($source);
3330
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3331

            
3332
$source = "abc";
3333
$query = $builder->build_query($source);
3334
is($query->sql, 'abc', "basic : 2");
3335

            
3336
$source = "{= a}";
3337
$query = $builder->build_query($source);
3338
is($query->sql, 'a = ?', "only tag");
3339

            
3340
$source = "000";
3341
$query = $builder->build_query($source);
3342
is($query->sql, '000', "contain 0 value");
3343

            
3344
$source = "a {= b} }";
3345
eval{$builder->build_query($source)};
3346
like($@, qr/unexpected "}"/, "error : 1");
3347

            
3348
$source = "a {= {}";
3349
eval{$builder->build_query($source)};
3350
like($@, qr/unexpected "{"/, "error : 2");
3351

            
3352
test 'select() sqlfilter option';
3353
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3354
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3355
eval { $dbi->execute("drop table $table1") };
3356
$dbi->execute($create_table1);
3357
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3358
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3359
$rows = $dbi->select(
3360
    table => $table1,
3361
    column => $key1,
3362
    sqlfilter => sub {
3363
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
3364
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
3365
        return $sql;
3366
    }
3367
)->all;
3368
is_deeply($rows, [{$key1 => 1}]);
3369

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3370
test 'select() after_build_sql option';
3371
$dbi = DBIx::Custom->connect;
3372
$dbi->user_table_info($user_table_info);
3373
eval { $dbi->execute("drop table $table1") };
3374
$dbi->execute($create_table1);
3375
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3376
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3377
$rows = $dbi->select(
3378
    table => $table1,
3379
    column => $key1,
3380
    after_build_sql => sub {
3381
        my $sql = shift;
3382
        $sql = "select * from ( $sql ) t where $key1 = 1";
3383
        return $sql;
3384
    }
3385
)->all;
3386
is_deeply($rows, [{$key1 => 1}]);
3387

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3388
test 'dbi method from model';
3389
$dbi = MyDBI9->connect;
3390
eval { $dbi->execute("drop table $table1") };
3391
$dbi->execute($create_table1);
3392
$dbi->setup_model;
3393
$model = $dbi->model($table1);
3394
eval{$model->execute("select * from $table1")};
3395
ok(!$@);
3396

            
3397
test 'column table option';
3398
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3399
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3400
eval { $dbi->execute("drop table $table1") };
3401
$dbi->execute($create_table1);
3402
eval { $dbi->execute("drop table $table2") };
3403
$dbi->execute($create_table2);
3404
$dbi->setup_model;
3405
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3406
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3407
$model = $dbi->model($table1);
3408
$result = $model->select(
3409
    column => [
3410
        $model->column($table2, {alias => $table2_alias})
3411
    ],
3412
    where => {"$table2_alias.$key3" => 4}
3413
);
3414
is_deeply($result->one, 
3415
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3416

            
3417
$dbi->separator('__');
3418
$result = $model->select(
3419
    column => [
3420
        $model->column($table2, {alias => $table2_alias})
3421
    ],
3422
    where => {"$table2_alias.$key3" => 4}
3423
);
3424
is_deeply($result->one, 
3425
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3426

            
3427
$dbi->separator('-');
3428
$result = $model->select(
3429
    column => [
3430
        $model->column($table2, {alias => $table2_alias})
3431
    ],
3432
    where => {"$table2_alias.$key3" => 4}
3433
);
3434
is_deeply($result->one, 
3435
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3436

            
3437
test 'create_model';
3438
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3439
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3440
eval { $dbi->execute("drop table $table1") };
3441
eval { $dbi->execute("drop table $table2") };
3442
$dbi->execute($create_table1);
3443
$dbi->execute($create_table2);
3444

            
3445
$dbi->create_model(
3446
    table => $table1,
3447
    join => [
3448
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3449
    ],
3450
    primary_key => [$key1]
3451
);
3452
$model2 = $dbi->create_model(
3453
    table => $table2
3454
);
3455
$dbi->create_model(
3456
    table => $table3,
3457
    filter => [
3458
        $key1 => {in => sub { uc $_[0] }}
3459
    ]
3460
);
3461
$dbi->setup_model;
3462
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3463
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3464
$model = $dbi->model($table1);
3465
$result = $model->select(
3466
    column => [$model->mycolumn, $model->column($table2)],
3467
    where => {"$table1.$key1" => 1}
3468
);
3469
is_deeply($result->one,
3470
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3471
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3472

            
3473
test 'model method';
3474
$dbi = DBIx::Custom->connect;
3475
eval { $dbi->execute("drop table $table2") };
3476
$dbi->execute($create_table2);
3477
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3478
$model = $dbi->create_model(
3479
    table => $table2
3480
);
3481
$model->method(foo => sub { shift->select(@_) });
3482
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3483

            
3484
test 'model helper';
3485
$dbi = DBIx::Custom->connect;
3486
eval { $dbi->execute("drop table $table2") };
3487
$dbi->execute($create_table2);
3488
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3489
$model = $dbi->create_model(
3490
    table => $table2
3491
);
3492
$model->helper(foo => sub { shift->select(@_) });
3493
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3494

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3495
test 'assign_clause';
cleanup test
Yuki Kimoto authored on 2011-08-15
3496
$dbi = DBIx::Custom->connect;
3497
eval { $dbi->execute("drop table $table1") };
3498
$dbi->execute($create_table1_2);
3499
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3500
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3501

            
3502
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3503
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3504
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3505
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3506
where $key1 = 1
3507
EOS
3508
$dbi->execute($sql, param => $param);
3509
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3510
$rows   = $result->all;
3511
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3512
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3513
                  "basic");
3514

            
3515

            
3516
$dbi = DBIx::Custom->connect;
3517
eval { $dbi->execute("drop table $table1") };
3518
$dbi->execute($create_table1_2);
3519
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3520
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3521

            
3522
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3523
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3524
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3525
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3526
where $key1 = 1
3527
EOS
3528
$dbi->execute($sql, param => $param);
3529
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3530
$rows   = $result->all;
3531
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3532
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3533
                  "basic");
3534

            
3535
$dbi = DBIx::Custom->connect;
3536
eval { $dbi->execute("drop table $table1") };
3537
$dbi->execute($create_table1_2);
3538
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3539
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3540

            
3541
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3542
$assign_clause = $dbi->update_param($param, {no_set => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
3543
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3544
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3545
where $key1 = 1
3546
EOS
3547
$dbi->execute($sql, param => $param);
3548
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3549
$rows   = $result->all;
3550
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3551
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3552
                  "update param no_set");
3553

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

            
3558
$dbi = DBIx::Custom->connect;
3559
eval { $dbi->execute("drop table $table1") };
3560
$dbi->execute($create_table1_2);
3561
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3562
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3563

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3564
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3565
$assign_clause = $dbi->assign_param($param);
3566
$sql = <<"EOS";
3567
update $table1 set $assign_clause
3568
where $key1 = 1
3569
EOS
3570
$dbi->execute($sql, param => $param, table => $table1);
3571
$result = $dbi->execute("select * from $table1 order by $key1");
3572
$rows   = $result->all;
3573
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3574
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3575
                  "basic");
3576

            
3577
$param = {$key2 => 11};
3578
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3579
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3580
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3581
where $key1 = 1
3582
EOS
3583
$dbi->execute($sql, param => $param, table => $table1);
3584
$result = $dbi->execute("select * from $table1 order by $key1");
3585
$rows   = $result->all;
3586
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3587
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3588
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3589

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3590
test 'Model class';
3591
$dbi = MyDBI1->connect;
3592
eval { $dbi->execute("drop table $table1") };
3593
$dbi->execute($create_table1);
3594
$model = $dbi->model($table1);
3595
$model->insert({$key1 => 'a', $key2 => 'b'});
3596
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3597
eval { $dbi->execute("drop table $table2") };
3598
$dbi->execute($create_table2);
3599
$model = $dbi->model($table2);
3600
$model->insert({$key1 => 'a'});
3601
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3602
is($dbi->models->{$table1}, $dbi->model($table1));
3603
is($dbi->models->{$table2}, $dbi->model($table2));
3604

            
3605
$dbi = MyDBI4->connect;
3606
eval { $dbi->execute("drop table $table1") };
3607
$dbi->execute($create_table1);
3608
$model = $dbi->model($table1);
3609
$model->insert({$key1 => 'a', $key2 => 'b'});
3610
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3611
eval { $dbi->execute("drop table $table2") };
3612
$dbi->execute($create_table2);
3613
$model = $dbi->model($table2);
3614
$model->insert({$key1 => 'a'});
3615
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3616

            
3617
$dbi = MyDBI5->connect;
3618
eval { $dbi->execute("drop table $table1") };
3619
eval { $dbi->execute("drop table $table2") };
3620
$dbi->execute($create_table1);
3621
$dbi->execute($create_table2);
3622
$model = $dbi->model($table2);
3623
$model->insert({$key1 => 'a'});
3624
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3625
$dbi->insert(table => $table1, param => {$key1 => 1});
3626
$model = $dbi->model($table1);
3627
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3628

            
3629
test 'primary_key';
3630
$dbi = MyDBI1->connect;
3631
$model = $dbi->model($table1);
3632
$model->primary_key([$key1, $key2]);
3633
is_deeply($model->primary_key, [$key1, $key2]);
3634

            
3635
test 'columns';
3636
$dbi = MyDBI1->connect;
3637
$model = $dbi->model($table1);
3638
$model->columns([$key1, $key2]);
3639
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3640

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3641
test 'setup_model';
3642
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3643
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3644
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3645
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3646

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3647
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3648
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3649
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3650
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3651
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3652

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3653
test 'each_column';
3654
$dbi = DBIx::Custom->connect;
3655
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3656
eval { $dbi->execute("drop table $table1") };
3657
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3658
eval { $dbi->execute("drop table $table3") };
3659
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3660
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3661

            
3662
$infos = [];
3663
$dbi->each_column(sub {
3664
    my ($self, $table, $column, $cinfo) = @_;
3665
    
3666
    if ($table =~ /^table\d/i) {
3667
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3668
         push @$infos, $info;
3669
    }
3670
});
3671
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3672
is_deeply($infos, 
3673
    [
3674
        [$table1, $key1, $key1],
3675
        [$table1, $key2, $key2],
3676
        [$table2, $key1, $key1],
3677
        [$table2, $key3, $key3]
3678
    ]
3679
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3680
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3681

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3682
test 'each_table';
3683
$dbi = DBIx::Custom->connect;
3684
eval { $dbi->execute("drop table $table1") };
3685
eval { $dbi->execute("drop table $table2") };
3686
$dbi->execute($create_table2);
3687
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3688

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3689
$infos = [];
3690
$dbi->each_table(sub {
3691
    my ($self, $table, $table_info) = @_;
3692
    
3693
    if ($table =~ /^table\d/i) {
3694
         my $info = [$table, $table_info->{TABLE_NAME}];
3695
         push @$infos, $info;
3696
    }
3697
});
3698
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3699
is_deeply($infos, 
3700
    [
3701
        [$table1, $table1],
3702
        [$table2, $table2],
3703
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3704
);
3705

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3706
$dbi = DBIx::Custom->connect;
3707
eval { $dbi->execute("drop table $table1") };
3708
eval { $dbi->execute("drop table $table2") };
3709
$dbi->execute($create_table2);
3710
$dbi->execute($create_table1_type);
3711

            
3712
$infos = [];
3713
$dbi->user_table_info($user_table_info);
3714
$dbi->each_table(sub {
3715
    my ($self, $table, $table_info) = @_;
3716
    
3717
    if ($table =~ /^table\d/i) {
3718
         my $info = [$table, $table_info->{TABLE_NAME}];
3719
         push @$infos, $info;
3720
    }
3721
});
3722
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3723
is_deeply($infos, 
3724
    [
3725
        [$table1, $table1],
3726
        [$table2, $table2],
3727
        [$table3, $table3],
3728
    ]
3729
);
3730

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3731
test 'type_rule into';
3732
eval { $dbi->execute("drop table $table1") };
3733
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3734
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3735

            
3736

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3737
$dbi = DBIx::Custom->connect;
3738
eval { $dbi->execute("drop table $table1") };
3739
$dbi->execute($create_table1_type);
3740

            
cleanup
Yuki Kimoto authored on 2011-08-16
3741
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3742
$dbi->type_rule(
3743
    into1 => {
3744
        $date_typename => sub { '2010-' . $_[0] }
3745
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3746
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3747
$dbi->insert({$key1 => '01-01'}, table => $table1);
3748
$result = $dbi->select(table => $table1);
3749
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3750

            
3751
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3752
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3753
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3754
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3755
$dbi->type_rule(
3756
    into1 => [
3757
         [$date_typename, $datetime_typename] => sub {
3758
            my $value = shift;
3759
            $value =~ s/02/03/g;
3760
            return $value;
3761
         }
3762
    ]
3763
);
3764
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3765
$result = $dbi->select(table => $table1);
3766
$row = $result->one;
3767
like($row->{$key1}, qr/^2010-01-03/);
3768
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3769

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3770
$dbi = DBIx::Custom->connect;
3771
eval { $dbi->execute("drop table $table1") };
3772
$dbi->execute($create_table1_type);
3773
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3774
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3775
$dbi->type_rule(
3776
    into1 => [
3777
        [$date_typename, $datetime_typename] => sub {
3778
            my $value = shift;
3779
            $value =~ s/02/03/g;
3780
            return $value;
3781
        }
3782
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3783
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3784
$result = $dbi->execute(
3785
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3786
    param => {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
3787
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3788
$row = $result->one;
3789
like($row->{$key1}, qr/^2010-01-03/);
3790
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3791

            
3792
$dbi = DBIx::Custom->connect;
3793
eval { $dbi->execute("drop table $table1") };
3794
$dbi->execute($create_table1_type);
3795
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3796
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3797
$dbi->type_rule(
3798
    into1 => [
3799
        [$date_typename, $datetime_typename] => sub {
3800
            my $value = shift;
3801
            $value =~ s/02/03/g;
3802
            return $value;
3803
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3804
    ]
3805
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3806
$result = $dbi->execute(
3807
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3808
    param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
3809
    table => $table1
3810
);
3811
$row = $result->one;
3812
like($row->{$key1}, qr/^2010-01-03/);
3813
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3814

            
3815
$dbi = DBIx::Custom->connect;
3816
eval { $dbi->execute("drop table $table1") };
3817
$dbi->execute($create_table1_type);
3818
$dbi->register_filter(convert => sub {
3819
    my $value = shift || '';
3820
    $value =~ s/02/03/;
3821
    return $value;
3822
});
cleanup
Yuki Kimoto authored on 2011-08-16
3823
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3824
$dbi->type_rule(
3825
    from1 => {
3826
        $date_datatype => 'convert',
3827
    },
3828
    into1 => {
3829
        $date_typename => 'convert',
3830
    }
3831
);
3832
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3833
$result = $dbi->select(table => $table1);
3834
like($result->fetch->[0], qr/^2010-03-03/);
3835

            
3836
test 'type_rule and filter order';
3837
$dbi = DBIx::Custom->connect;
3838
eval { $dbi->execute("drop table $table1") };
3839
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3840
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3841
$dbi->type_rule(
3842
    into1 => {
3843
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3844
    },
3845
    into2 => {
3846
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3847
    },
3848
    from1 => {
3849
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3850
    },
3851
    from2 => {
3852
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
3853
    }
3854
);
3855
$dbi->insert({$key1 => '2010-01-03'}, 
3856
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
3857
$result = $dbi->select(table => $table1);
3858
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3859
like($result->fetch_first->[0], qr/^2010-01-09/);
3860

            
3861

            
3862
$dbi = DBIx::Custom->connect;
3863
eval { $dbi->execute("drop table $table1") };
3864
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3865
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3866
$dbi->type_rule(
3867
    from1 => {
3868
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3869
    },
3870
    from2 => {
3871
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3872
    },
3873
);
3874
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3875
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3876
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3877
$result->type_rule(
3878
    from1 => {
3879
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3880
    },
3881
    from2 => {
3882
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3883
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3884
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3885
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3886
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3887

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3888
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
3889
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
3890
eval { $dbi->execute("drop table $table1") };
3891
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3892
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3893
$dbi->type_rule(
3894
    from1 => {
3895
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3896
    },
3897
    into1 => {
3898
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3899
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3900
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3901
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3902
$result = $dbi->select(table => $table1, type_rule_off => 1);
3903
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3904

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3905
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3906
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3907
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3908
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3909
$dbi->type_rule(
3910
    from1 => {
3911
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3912
    },
3913
    into1 => {
3914
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3915
    }
3916
);
3917
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3918
$result = $dbi->select(table => $table1, type_rule_off => 1);
3919
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3920

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

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

            
3953
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3954
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3955
$dbi->execute($create_table1_type);
3956
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
3957
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3958
$dbi->type_rule(
3959
    into1 => {
3960
        $date_typename => 'ppp'
3961
    }
3962
);
3963
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3964
$result = $dbi->select(table => $table1);
3965
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3966

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3967
eval{$dbi->type_rule(
3968
    into1 => {
3969
        $date_typename => 'pp'
3970
    }
3971
)};
3972
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3973

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3974
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3975
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3976
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3977
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3978
    $dbi->type_rule(
3979
        from1 => {
3980
            Date => sub { $_[0] * 2 },
3981
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3982
    );
3983
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3984
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3985

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3986
eval {
3987
    $dbi->type_rule(
3988
        into1 => {
3989
            Date => sub { $_[0] * 2 },
3990
        }
3991
    );
3992
};
3993
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3994

            
3995
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3996
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3997
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3998
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3999
$dbi->type_rule(
4000
    from1 => {
4001
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4002
    },
4003
    into1 => {
4004
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4005
    }
4006
);
4007
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4008
$result = $dbi->select(table => $table1);
4009
$result->type_rule_off;
4010
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4011

            
4012
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4013
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4014
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4015
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4016
$dbi->type_rule(
4017
    from1 => {
4018
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4019
        $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4020
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
4021
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4022
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
4023
$result = $dbi->select(table => $table1);
4024
$result->type_rule(
4025
    from1 => {
4026
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4027
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4028
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4029
$row = $result->one;
4030
like($row->{$key1}, qr/^2010-01-05/);
4031
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4032

            
4033
$result = $dbi->select(table => $table1);
4034
$result->type_rule(
4035
    from1 => {
4036
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4037
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4038
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4039
$row = $result->one;
4040
like($row->{$key1}, qr/2010-01-05/);
4041
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4042

            
4043
$result = $dbi->select(table => $table1);
4044
$result->type_rule(
4045
    from1 => {
4046
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4047
    }
4048
);
4049
$row = $result->one;
4050
like($row->{$key1}, qr/2010-01-05/);
4051
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4052

            
4053
$result = $dbi->select(table => $table1);
4054
$result->type_rule(
4055
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
4056
);
4057
$row = $result->one;
4058
like($row->{$key1}, qr/2010-01-05/);
4059
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4060

            
4061
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4062
$result = $dbi->select(table => $table1);
4063
$result->type_rule(
4064
    from1 => [$date_datatype => 'five']
4065
);
4066
$row = $result->one;
4067
like($row->{$key1}, qr/^2010-01-05/);
4068
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4069

            
4070
$result = $dbi->select(table => $table1);
4071
$result->type_rule(
4072
    from1 => [$date_datatype => undef]
4073
);
4074
$row = $result->one;
4075
like($row->{$key1}, qr/^2010-01-03/);
4076
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4077

            
4078
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4079
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4080
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4081
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4082
$dbi->type_rule(
4083
    from1 => {
4084
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4085
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
4086
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4087
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4088
$result = $dbi->select(table => $table1);
4089
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4090
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4091

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4092
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4093
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4094
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4095
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4096
$dbi->type_rule(
4097
    from1 => {
4098
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4099
    },
4100
);
4101
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4102
$result = $dbi->select(table => $table1);
4103
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4104
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4105

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4106
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4107
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4108
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4109
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4110
$dbi->type_rule(
4111
    into1 => {
4112
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4113
    },
4114
    into2 => {
4115
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4116
    },
4117
    from1 => {
4118
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4119
    },
4120
    from2 => {
4121
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4122
    }
4123
);
4124
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4125
$result = $dbi->select(table => $table1);
4126
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/);
4127
$result = $dbi->select(table => $table1);
4128
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4129

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4130
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4131
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4132
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4133
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4134
$dbi->type_rule(
4135
    into1 => {
4136
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4137
    },
4138
    into2 => {
4139
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4140
    },
4141
    from1 => {
4142
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
4143
    },
4144
    from2 => {
4145
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4146
    }
4147
);
4148
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4149
$result = $dbi->select(table => $table1);
4150
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/);
4151
$result = $dbi->select(table => $table1);
4152
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4153

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4154
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4155
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4156
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4157
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4158
$dbi->type_rule(
4159
    into1 => {
4160
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4161
    },
4162
    into2 => {
4163
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4164
    },
4165
    from1 => {
4166
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4167
    },
4168
    from2 => {
4169
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4170
    }
4171
);
4172
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4173
$result = $dbi->select(table => $table1);
4174
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
4175
$result = $dbi->select(table => $table1);
4176
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4177

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4178
test 'join';
4179
$dbi = DBIx::Custom->connect;
4180
eval { $dbi->execute("drop table $table1") };
4181
$dbi->execute($create_table1);
4182
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4183
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
4184
eval { $dbi->execute("drop table $table2") };
4185
$dbi->execute($create_table2);
4186
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4187
eval { $dbi->execute("drop table $table3") };
4188
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
4189
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
4190
$rows = $dbi->select(
4191
    table => $table1,
4192
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4193
    where   => {"$table1.$key2" => 2},
4194
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4195
)->all;
4196
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4197

            
4198
$dbi = DBIx::Custom->connect;
4199
eval { $dbi->execute("drop table $table1") };
4200
$dbi->execute($create_table1);
4201
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4202
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
4203
eval { $dbi->execute("drop table $table2") };
4204
$dbi->execute($create_table2);
4205
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4206
eval { $dbi->execute("drop table $table3") };
4207
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
4208
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
4209
$rows = $dbi->select(
4210
    table => $table1,
4211
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4212
    where   => {"$table1.$key2" => 2},
4213
    join  => {
4214
        clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4215
        table => [$table1, $table2]
4216
    }
4217
)->all;
4218
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4219

            
4220
$rows = $dbi->select(
4221
    table => $table1,
4222
    where   => {$key1 => 1},
4223
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4224
)->all;
4225
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4226

            
4227
$rows = $dbi->select(
4228
    table => $table1,
4229
    where   => {$key1 => 1},
4230
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4231
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4232
)->all;
4233
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4234

            
4235
$rows = $dbi->select(
4236
    column => "$table3.$key4 as ${table3}__$key4",
4237
    table => $table1,
4238
    where   => {"$table1.$key1" => 1},
4239
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4240
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4241
)->all;
4242
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4243

            
4244
$rows = $dbi->select(
4245
    column => "$table1.$key1 as ${table1}__$key1",
4246
    table => $table1,
4247
    where   => {"$table3.$key4" => 4},
4248
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4249
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4250
)->all;
4251
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4252

            
4253
$dbi = DBIx::Custom->connect;
4254
eval { $dbi->execute("drop table $table1") };
4255
$dbi->execute($create_table1);
4256
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4257
eval { $dbi->execute("drop table $table2") };
4258
$dbi->execute($create_table2);
4259
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4260
$rows = $dbi->select(
4261
    table => $table1,
4262
    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",
4263
    where   => {"$table1.$key2" => 2},
4264
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4265
)->all;
4266
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4267
          'quote');
4268

            
4269

            
4270
$dbi = DBIx::Custom->connect;
4271
eval { $dbi->execute("drop table $table1") };
4272
$dbi->execute($create_table1);
4273
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4274
$sql = <<"EOS";
4275
left outer join (
4276
  select * from $table1 t1
4277
  where t1.$key2 = (
4278
    select max(t2.$key2) from $table1 t2
4279
    where t1.$key1 = t2.$key1
4280
  )
4281
) $table3 on $table1.$key1 = $table3.$key1
4282
EOS
4283
$join = [$sql];
4284
$rows = $dbi->select(
4285
    table => $table1,
4286
    column => "$table3.$key1 as ${table3}__$key1",
4287
    join  => $join
4288
)->all;
4289
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4290

            
4291
$dbi = DBIx::Custom->connect;
4292
eval { $dbi->execute("drop table $table1") };
4293
eval { $dbi->execute("drop table $table2") };
4294
$dbi->execute($create_table1);
4295
$dbi->execute($create_table2);
4296
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4297
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4298
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4299
$result = $dbi->select(
4300
    table => $table1,
4301
    join => [
4302
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4303
    ]
4304
);
4305
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4306
$result = $dbi->select(
4307
    table => $table1,
4308
    column => [{$table2 => [$key3]}],
4309
    join => [
4310
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4311
    ]
4312
);
4313
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4314
$result = $dbi->select(
4315
    table => $table1,
4316
    column => [{$table2 => [$key3]}],
4317
    join => [
4318
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4319
    ]
4320
);
4321
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4322

            
4323
$dbi = DBIx::Custom->connect;
4324
eval { $dbi->execute("drop table $table1") };
4325
eval { $dbi->execute("drop table $table2") };
4326
$dbi->execute($create_table1);
4327
$dbi->execute($create_table2);
4328
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4329
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4330
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4331
$result = $dbi->select(
4332
    table => $table1,
4333
    column => [{$table2 => [$key3]}],
4334
    join => [
4335
        {
4336
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4337
            table => [$table1, $table2]
4338
        }
4339
    ]
4340
);
4341
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4342

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4343
$dbi = DBIx::Custom->connect;
4344
eval { $dbi->execute("drop table $table1") };
4345
eval { $dbi->execute("drop table $table2") };
4346
$dbi->execute($create_table1);
4347
$dbi->execute($create_table2);
4348
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4349
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4350
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4351
$result = $dbi->select(
4352
    table => $table1,
4353
    column => [{$table2 => [$key3]}],
4354
    join => [
4355
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4356
    ]
4357
);
4358
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4359

            
4360
$dbi = DBIx::Custom->connect;
4361
eval { $dbi->execute("drop table $table1") };
4362
eval { $dbi->execute("drop table $table2") };
4363
$dbi->execute($create_table1);
4364
$dbi->execute($create_table2);
4365
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4366
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4367
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4368
$result = $dbi->select(
4369
    table => $table1,
4370
    column => [{$table2 => [$key3]}],
4371
    join => [
4372
        "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4373
    ]
4374
);
4375
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4376

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4377
test 'columns';
4378
$dbi = MyDBI1->connect;
4379
$model = $dbi->model($table1);
4380

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4381
test 'count';
4382
$dbi = DBIx::Custom->connect;
4383
eval { $dbi->execute("drop table $table1") };
4384
$dbi->execute($create_table1);
4385
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4386
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 3});
4387
is($dbi->count(table => $table1), 2);
4388
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4389
$model = $dbi->create_model(table => $table1);
4390
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4391

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