DBIx-Custom / t / common.t /
Newer Older
4428 lines | 147.689kb
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) {
test cleanup
Yuki Kimoto authored on 2011-11-01
246
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, 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);
test cleanup
Yuki Kimoto authored on 2011-11-01
271
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
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);
test cleanup
Yuki Kimoto authored on 2011-11-01
301
$ret_val = $dbi->execute($query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
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}";
test cleanup
Yuki Kimoto authored on 2011-11-01
307
$dbi->execute($insert_source, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
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'});
test cleanup
Yuki Kimoto authored on 2011-11-01
320
$dbi->execute($insert_query, {$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
Yuki Kimoto authored on 2011-11-01
329
$dbi->execute($insert_query, {$key1 => 2, $key2 => 4});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
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
Yuki Kimoto authored on 2011-11-01
333
$result = $dbi->execute($select_query, {"$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
Yuki Kimoto authored on 2011-11-01
340
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
341
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
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
Yuki Kimoto authored on 2011-11-01
345
$result = $dbi->execute($query, {$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
Yuki Kimoto authored on 2011-11-01
357
$result = $dbi->execute($query, {$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
Yuki Kimoto authored on 2011-11-01
364
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
365
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
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
Yuki Kimoto authored on 2011-11-01
369
$result = $dbi->execute($query, {$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}";
test cleanup
Yuki Kimoto authored on 2011-11-01
376
$dbi->execute($insert_source, {$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}";
test cleanup
Yuki Kimoto authored on 2011-11-01
385
$dbi->execute($insert_source, {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
386
$dbi->execute($insert_source, {$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}";
test cleanup
Yuki Kimoto authored on 2011-11-01
389
$dbi->execute($update_source, {$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
Yuki Kimoto authored on 2011-11-01
399
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
400
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
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";
test cleanup
Yuki Kimoto authored on 2011-11-01
403
$result = $dbi->execute($source, {$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";
test cleanup
Yuki Kimoto authored on 2011-11-01
408
$result = $dbi->execute($source, {$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";
test cleanup
Yuki Kimoto authored on 2011-11-01
413
$result = $dbi->execute($source, {$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
Yuki Kimoto authored on 2011-11-01
420
    {"$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
Yuki Kimoto authored on 2011-11-01
428
$dbi->insert({$key1 => '2011-10-14 12:19:18', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
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
Yuki Kimoto authored on 2011-11-01
432
    {$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);
test cleanup
Yuki Kimoto authored on 2011-11-01
440
$dbi->insert({$key1 => 'a:b c:d', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
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
Yuki Kimoto authored on 2011-11-01
444
    {$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
Yuki Kimoto authored on 2011-11-01
459
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
460
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
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

            
added tests
Yuki Kimoto authored on 2011-11-01
465
eval { $dbi->execute("drop table $table1") };
466
$dbi->execute($create_table1);
467
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
468
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
469
$result = $dbi->execute("select * from $table1");
470
$rows   = $result->all;
471
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
472

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
473
$dbi->execute("delete from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
474
$dbi->register_filter(
475
    twice       => sub { $_[0] * 2 },
476
    three_times => sub { $_[0] * 3 }
477
);
478
$dbi->default_bind_filter('twice');
test cleanup
Yuki Kimoto authored on 2011-11-01
479
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
cleanup test
Yuki Kimoto authored on 2011-08-15
480
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
481
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
482
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-10
483
$dbi->default_bind_filter(undef);
484

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
485
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
486
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
487
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, append => '   ');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
488
$rows = $dbi->select(table => $table1)->all;
489
is_deeply($rows, [{$key1 => 1, $key2 => 2}], 'insert append');
cleanup test
Yuki Kimoto authored on 2011-08-10
490

            
test cleanup
Yuki Kimoto authored on 2011-11-01
491
eval{$dbi->insert({';' => 1}, table => 'table')};
cleanup test
Yuki Kimoto authored on 2011-08-10
492
like($@, qr/safety/);
493

            
cleanup test
Yuki Kimoto authored on 2011-08-10
494
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
495
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
496
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
test cleanup
Yuki Kimoto authored on 2011-11-01
497
$dbi->insert({select => 1}, table => 'table');
cleanup test
Yuki Kimoto authored on 2011-08-10
498
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
499
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
500
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
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({$key1 => 1, $key2 => 2}, table => $table1);
505
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
510
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
511
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
512
$dbi->insert({$key1 => \"'1'", $key2 => 2}, table => $table1);
513
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
514
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
515
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
516
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
517

            
updated pod
Yuki Kimoto authored on 2011-09-02
518
eval { $dbi->execute("drop table $table1") };
519
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
520
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
updated pod
Yuki Kimoto authored on 2011-09-02
521
  wrap => {$key1 => sub { "$_[0] - 1" }});
test cleanup
Yuki Kimoto authored on 2011-11-01
522
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
updated pod
Yuki Kimoto authored on 2011-09-02
523
$result = $dbi->execute("select * from $table1");
524
$rows   = $result->all;
525
is_deeply($rows, [{$key1 => 0, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
526

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
537
eval { $dbi->execute("drop table $table1") };
538
$dbi->execute($create_table1);
539
$dbi->insert_timestamp(
540
    [$key1, $key2] => sub { 5 }
541
);
542
$dbi->insert(table => $table1, timestamp => 1);
543
$result = $dbi->execute("select * from $table1");
544
$rows   = $result->all;
545
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
546

            
547
eval { $dbi->execute("drop table $table1") };
548
$dbi->execute($create_table1);
549
$dbi->insert_timestamp(
550
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
551
);
552
$dbi->insert(table => $table1, timestamp => 1);
553
$result = $dbi->execute("select * from $table1");
554
$rows   = $result->all;
555
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
556

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
557
eval { $dbi->execute("drop table $table1") };
558
$dbi->execute($create_table1_2);
559
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
560
$dbi->insert($param, table => $table1, created_at => $key2);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
561
$result = $dbi->select(table => $table1);
562
is_deeply($param, {$key1 => 1});
563
$row   = $result->one;
564
is($row->{$key1}, 1);
565
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
566

            
567
eval { $dbi->execute("drop table $table1") };
568
$dbi->execute($create_table1_2);
569
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
570
$dbi->insert($param, table => $table1, updated_at => $key3);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
571
$result = $dbi->select(table => $table1);
572
is_deeply($param, {$key1 => 1});
573
$row   = $result->one;
574
is($row->{$key1}, 1);
575
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
576

            
577
eval { $dbi->execute("drop table $table1") };
578
$dbi->execute($create_table1_2);
579
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
580
$dbi->insert($param, table => $table1, created_at => $key2, updated_at => $key3);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
581
$result = $dbi->select(table => $table1);
582
is_deeply($param, {$key1 => 1});
583
$row   = $result->one;
584
is($row->{$key1}, 1);
585
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
586
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
587
is($row->{$key2}, $row->{$key3});
588

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
589
eval { $dbi->execute("drop table $table1") };
590
$dbi->execute($create_table1_2);
591
$model = $dbi->create_model(table => $table1, created_at => $key2);
592
$param = {$key1 => 1};
593
$model->insert($param);
594
$result = $dbi->select(table => $table1);
595
is_deeply($param, {$key1 => 1});
596
$row   = $result->one;
597
is($row->{$key1}, 1);
598
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
599

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

            
611
eval { $dbi->execute("drop table $table1") };
612
$dbi->execute($create_table1_2);
613
$param = {$key1 => 1};
614
$model = $dbi->create_model(table => $table1, created_at => $key2, updated_at => $key3);
615
$model->insert($param);
616
$result = $dbi->select(table => $table1);
617
is_deeply($param, {$key1 => 1});
618
$row   = $result->one;
619
is($row->{$key1}, 1);
620
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
621
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
622
is($row->{$key2}, $row->{$key3});
623

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
624
test 'update_or_insert';
625
eval { $dbi->execute("drop table $table1") };
626
$dbi->execute($create_table1);
627
$dbi->update_or_insert(
628
    {$key2 => 2},
629
    table => $table1,
630
    primary_key => $key1,
631
    id => 1
632
);
633
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
634
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
635

            
636
$dbi->update_or_insert(
637
    {$key2 => 3},
638
    table => $table1,
639
    primary_key => $key1,
640
    id => 1
641
);
642
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
643
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
644

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
645
eval {
646
    $dbi->update_or_insert(
647
        {$key2 => 3},
648
        table => $table1,
649
    );
650
};
651

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

            
micro optimization
Yuki Kimoto authored on 2011-10-31
654
test 'model update_or_insert';
655
eval { $dbi->execute("drop table $table1") };
656
$dbi->execute($create_table1);
657
$model = $dbi->create_model(
658
    table => $table1,
659
    primary_key => $key1
660
);
661
$model->update_or_insert({$key2 => 2}, id => 1);
662
$row = $model->select(id => 1)->one;
663
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
664

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
665
test 'default_bind_filter';
666
$dbi->execute("delete from $table1");
667
$dbi->register_filter(
668
    twice       => sub { $_[0] * 2 },
669
    three_times => sub { $_[0] * 3 }
670
);
671
$dbi->default_bind_filter('twice');
cleanup
Yuki Kimoto authored on 2011-11-01
672
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
673
$result = $dbi->execute("select * from $table1");
674
$rows   = $result->all;
675
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
676
$dbi->default_bind_filter(undef);
677

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

            
690
eval { $dbi->execute("drop table $table1") };
691
$dbi->execute($create_table1_2);
692
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
693
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
694
$dbi->update(param => {$key2 => 11}, table => $table1, where => {$key1 => 1});
695
$result = $dbi->execute("select * from $table1 order by $key1");
696
$rows   = $result->all;
697
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
698
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
699
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
700
                  
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
701
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
702
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
703
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
704
$dbi->update({$key2 => 12}, table => $table1, where => {$key2 => 2, $key3 => 3});
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 => 12, $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
                  "update key same as search key");
710

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
718
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
719
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
720
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
721
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
722
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
723
              filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
724
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
725
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
726
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
727
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
728
                  "filter");
729

            
cleanup
Yuki Kimoto authored on 2011-11-01
730
$result = $dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1}, append => '   ');
test cleanup
Yuki Kimoto authored on 2011-08-10
731

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
745
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
746
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
747
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
748
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
749
    {$key1 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
750
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
751
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
752
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
753
        {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
754
    ]
755
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
756
$result = $dbi->select(table => $table1);
757
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
758

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
759
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
760
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
761
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
762
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
763
$where->clause(['and', "$key2 = :$key2"]);
764
$where->param({$key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
765
$dbi->update({$key1 => 3}, table => $table1, where => $where);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
766
$result = $dbi->select(table => $table1);
767
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
768

            
cleanup
Yuki Kimoto authored on 2011-11-01
769
eval{$dbi->update({';' => 1}, table => $table1, where => {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
770
like($@, qr/safety/);
771

            
cleanup
Yuki Kimoto authored on 2011-11-01
772
eval{$dbi->update({$key1 => 1}, table => $table1, where => {';' => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
773
like($@, qr/safety/);
774

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
775
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
776
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
777
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
778
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
779
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
780
$dbi->insert({select => 1}, table => 'table');
781
$dbi->update({update => 2}, table => 'table', where => {select => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
782
$result = $dbi->execute("select * from ${q}table$p");
783
$rows   = $result->all;
784
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
785

            
cleanup
Yuki Kimoto authored on 2011-11-01
786
eval {$dbi->update_all({';' => 2}, table => 'table') };
test cleanup
Yuki Kimoto authored on 2011-08-10
787
like($@, qr/safety/);
788

            
789
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
790
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
791
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
792
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
793
$dbi->insert({select => 1}, table => 'table');
794
$dbi->update({update => 2}, table => 'table', where => {'table.select' => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
795
$result = $dbi->execute("select * from ${q}table$p");
796
$rows   = $result->all;
797
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
798

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

            
updated pod
Yuki Kimoto authored on 2011-09-02
810
eval { $dbi->execute("drop table $table1") };
811
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
812
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
813
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
814
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
updated pod
Yuki Kimoto authored on 2011-09-02
815
wrap => {$key2 => sub { "$_[0] - 1" }});
816
$result = $dbi->execute("select * from $table1 order by $key1");
817
$rows   = $result->all;
818
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5},
819
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
820
                  "basic");
821

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
822
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
823
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
824
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
825
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
826
$dbi->update({$key2 => \"'11'"}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
827
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
828
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
829
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
830
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
831
                  "basic");
832

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
833
eval { $dbi->execute("drop table $table1") };
834
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
835
$dbi->update_timestamp(
836
    $key1 => '5'
837
);
test cleanup
Yuki Kimoto authored on 2011-11-01
838
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
839
$dbi->update(table => $table1, timestamp => 1, where => {$key2 => 2});
840
$result = $dbi->execute("select * from $table1");
841
$rows   = $result->all;
842
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
843

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
844
eval { $dbi->execute("drop table $table1") };
845
$dbi->execute($create_table1);
846
$dbi->update_timestamp(
847
    [$key1, $key2] => sub { '5' }
848
);
test cleanup
Yuki Kimoto authored on 2011-11-01
849
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
850
$dbi->update_all(table => $table1, timestamp => 1);
851
$result = $dbi->execute("select * from $table1");
852
$rows   = $result->all;
853
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
854

            
855
eval { $dbi->execute("drop table $table1") };
856
$dbi->execute($create_table1);
857
$dbi->update_timestamp(
858
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
859
);
test cleanup
Yuki Kimoto authored on 2011-11-01
860
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
861
$dbi->update_all(table => $table1, timestamp => 1);
862
$result = $dbi->execute("select * from $table1");
863
$rows   = $result->all;
864
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
865

            
micro optimization and
Yuki Kimoto authored on 2011-10-25
866
eval { $dbi->execute("drop table $table1") };
867
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
868
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
869
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
870
$param = {$key2 => 11};
871
$dbi->update($param, table => $table1, where => {$key1 => 1});
872
is_deeply($param, {$key2 => 11});
873
$result = $dbi->execute("select * from $table1 order by $key1");
874
$rows   = $result->all;
875
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
876
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
877
                  "basic");
878

            
879
eval { $dbi->execute("drop table $table1") };
880
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
881
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
882
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
883
$param = {$key2 => 11};
884
$dbi->update($param, table => $table1, where => {$key2 => 2});
885
is_deeply($param, {$key2 => 11});
886
$result = $dbi->execute("select * from $table1 order by $key1");
887
$rows   = $result->all;
888
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
889
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
890
                  "basic");
891

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
892
eval { $dbi->execute("drop table $table1") };
893
$dbi->execute($create_table1_2);
894
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
895
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
896
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key1 => 1});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
897
$result = $dbi->select(table => $table1);
898
is_deeply($param, {$key3 => 4});
899
$row   = $result->one;
900
is($row->{$key3}, 4);
901
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
902

            
903
eval { $dbi->execute("drop table $table1") };
904
$dbi->execute($create_table1_2);
905
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
906
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
907
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key3 => 3});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
908
$result = $dbi->select(table => $table1);
909
is_deeply($param, {$key3 => 4});
910
$row   = $result->one;
911
is($row->{$key3}, 4);
912
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
913

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
914
eval { $dbi->execute("drop table $table1") };
915
$dbi->execute($create_table1_2);
916
$model = $dbi->create_model(table => $table1, updated_at => $key2);
917
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
918
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
919
$model->update($param, where => {$key1 => 1});
920
$result = $dbi->select(table => $table1);
921
is_deeply($param, {$key3 => 4});
922
$row   = $result->one;
923
is($row->{$key3}, 4);
924
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
925

            
test cleanup
Yuki Kimoto authored on 2011-08-10
926
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
927
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
928
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
929
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
930
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
931
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
932
$dbi->update_all({$key2 => 10}, table => $table1, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
933
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
934
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
935
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
936
                  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
937
                  "filter");
938

            
939

            
940
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
941
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
942
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
943
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
944
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
945
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
946
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
947
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
948
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
949

            
cleanup test
Yuki Kimoto authored on 2011-08-15
950
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
951
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
952
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
953
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
954
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
955
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
956
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
957
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
958

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
961
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
962
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
963
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
964
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
965
$rows = $dbi->select(table => $table1)->all;
966
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
967

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
968
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
969
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
970
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
971
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
972
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
973
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
974
$where->param({ke1 => 1, $key2 => 2});
975
$dbi->delete(table => $table1, where => $where);
976
$result = $dbi->select(table => $table1);
977
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
978

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
979
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
980
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
981
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
982
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
983
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
984
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
985
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
986
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
987
        {ke1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
988
    ]
989
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
990
$result = $dbi->select(table => $table1);
991
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
992

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
993
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
994
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
995
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
996
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
997
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
998
$rows   = $result->all;
999
is_deeply($rows, [], "basic");
1000

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1010
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
1011
$dbi = DBIx::Custom->connect;
1012
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1013
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1014
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1015
$dbi->insert({select => 1}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1016
$dbi->delete(table => 'table', where => {select => 1});
1017
$result = $dbi->execute("select * from ${q}table$p");
1018
$rows   = $result->all;
1019
is_deeply($rows, [], "reserved word");
1020

            
1021
test 'delete_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1022
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1023
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1024
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1025
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1026
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1027
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1028
$rows   = $result->all;
1029
is_deeply($rows, [], "basic");
1030

            
1031

            
1032
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1033
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1034
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1035
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1036
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1037
$rows = $dbi->select(table => $table1)->all;
1038
is_deeply($rows, [{$key1 => 1, $key2 => 2},
1039
                  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
1040

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1055
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1056
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
1057
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1058
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1059
    table => [$table1, $table2],
1060
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
1061
    where   => {"$table1.$key2" => 2},
1062
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1063
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1064
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
1065

            
1066
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1067
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1068
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1069
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1070
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1071
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
1072

            
1073
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
1074
eval { $dbi->execute("drop table ${q}table$p") };
1075
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1076
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1077
$dbi->insert({select => 1, update => 2}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1078
$result = $dbi->select(table => 'table', where => {select => 1});
1079
$rows   = $result->all;
1080
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
1081

            
1082
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1083
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1084
$dbi->register_filter(
1085
    twice       => sub { $_[0] * 2 },
1086
    three_times => sub { $_[0] * 3 }
1087
);
1088
$dbi->default_fetch_filter('twice');
1089
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1090
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1091
$result = $dbi->select(table => $table1);
1092
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1093
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1094
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1095

            
1096
test 'filters';
1097
$dbi = DBIx::Custom->new;
1098

            
1099
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
1100
   'あ', "decode_utf8");
1101

            
1102
is($dbi->filters->{encode_utf8}->('あ'),
1103
   encode_utf8('あ'), "encode_utf8");
1104

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1105
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1106
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1107
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1108
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1109
$dbi->begin_work;
1110
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1111
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1112
$dbi->rollback;
1113
$dbi->dbh->{AutoCommit} = 1;
1114

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

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

            
1119
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1120
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1121
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1122
$dbi->begin_work;
1123
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1124
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1125
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1126
$dbi->commit;
1127
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1128
$result = $dbi->select(table => $table1);
1129
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1130
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1131

            
1132
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1133
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1134
$dbi->execute($create_table1);
1135
{
1136
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1137
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1138
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1139
    like($@, qr/\.t /, "fail : not verbose");
1140
}
1141
{
1142
    local $Carp::Verbose = 1;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1143
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1144
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1145
}
1146

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1147
$query = $dbi->execute("select * from $table1 where $key1 = :$key1", {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1148
$dbi->dbh->disconnect;
cleanup
Yuki Kimoto authored on 2011-11-01
1149
eval{$dbi->execute($query, {$key1 => {a => 1}})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1150
ok($@, "execute fail");
1151

            
1152
{
1153
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1154
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1155
    like($@, qr/\Q.t /, "caller spec : not vebose");
1156
}
1157
{
1158
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1159
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1160
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1161
}
1162

            
1163

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1164
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1165
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1166
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1167
$dbi->execute($create_table1);
1168

            
1169
$dbi->begin_work;
1170

            
1171
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1172
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1173
    die "Error";
test cleanup
Yuki Kimoto authored on 2011-11-01
1174
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1175
};
1176

            
1177
$dbi->rollback if $@;
1178

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

            
1183
$dbi->begin_work;
1184

            
1185
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1186
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1187
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1188
};
1189

            
1190
$dbi->commit unless $@;
1191

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

            
1196
$dbi->dbh->{AutoCommit} = 0;
1197
eval{ $dbi->begin_work };
1198
ok($@, "exception");
1199
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1200

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1201
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1202
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1203
$dbi->cache(1);
1204
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1205
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1206
$dbi->execute($source, {}, query => 1);
1207
is_deeply($dbi->{_cached}->{$source}, 
cleanup test
Yuki Kimoto authored on 2011-08-15
1208
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1209

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1210
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1211
$dbi->execute($create_table1);
1212
$dbi->{_cached} = {};
1213
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1214
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1215
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1216

            
1217
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1218
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1219
$dbi->execute($create_table1);
1220
{
1221
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1222
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1223
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1224
    like($@, qr/\.t /, "fail : not verbose");
1225
}
1226
{
1227
    local $Carp::Verbose = 1;
- removed argument checking ...
Yuki Kimoto authored on 2011-10-21
1228
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1229
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1230
}
1231

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1232
$query = $dbi->execute("select * from $table1 where $key1 = :$key1", {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1233
$dbi->dbh->disconnect;
cleanup
Yuki Kimoto authored on 2011-11-01
1234
eval{$dbi->execute($query, {$key1 => {a => 1}})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1235
ok($@, "execute fail");
1236

            
1237
{
1238
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1239
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1240
    like($@, qr/\Q.t /, "caller spec : not vebose");
1241
}
1242
{
1243
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1244
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1245
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1246
}
1247

            
1248
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1249
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1250
    one => sub { 1 }
1251
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1252
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1253
    two => sub { 2 }
1254
);
1255
$dbi->method({
1256
    twice => sub {
1257
        my $self = shift;
1258
        return $_[0] * 2;
1259
    }
1260
});
1261

            
1262
is($dbi->one, 1, "first");
1263
is($dbi->two, 2, "second");
1264
is($dbi->twice(5), 10 , "second");
1265

            
1266
eval {$dbi->XXXXXX};
1267
ok($@, "not exists");
1268

            
1269
test 'out filter';
1270
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1271
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1272
$dbi->execute($create_table1);
1273
$dbi->register_filter(twice => sub { $_[0] * 2 });
1274
$dbi->register_filter(three_times => sub { $_[0] * 3});
1275
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1276
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1277
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
1278
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
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->fetch_hash_first;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1281
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1282
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1283
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1284
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1285

            
1286
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1287
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1288
$dbi->execute($create_table1);
1289
$dbi->register_filter(twice => sub { $_[0] * 2 });
1290
$dbi->register_filter(three_times => sub { $_[0] * 3});
1291
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1292
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1293
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1294
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1295
    $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1296
); 
test cleanup
Yuki Kimoto authored on 2011-11-01
1297
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1298
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1299
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1300
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1301

            
1302
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1303
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1304
$dbi->execute($create_table1);
1305
$dbi->register_filter(twice => sub { $_[0] * 2 });
1306
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1307
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1308
);
cleanup
Yuki Kimoto authored on 2011-11-01
1309
$dbi->insert({$key1 => 1, $key2 => 2},table => $table1, filter => {$key1 => undef});
1310
$dbi->update({$key1 => 2}, table => $table1, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1311
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1312
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1313
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
test cleanup
Yuki Kimoto authored on 2011-08-10
1314

            
1315
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1316
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1317
$dbi->execute($create_table1);
1318
$dbi->register_filter(twice => sub { $_[0] * 2 });
1319
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1320
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1321
);
cleanup
Yuki Kimoto authored on 2011-11-01
1322
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1=> undef});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1323
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1324
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1325
$rows   = $result->all;
1326
is_deeply($rows, [], "delete");
1327

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

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

            
1355
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1356
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1357
$dbi->execute($create_table1);
1358
$dbi->register_filter(twice => sub { $_[0] * 2 });
1359
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1360
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1361
);
cleanup
Yuki Kimoto authored on 2011-11-01
1362
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1363
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
1364
                        {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1365
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1366
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1367

            
1368
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1369
eval { $dbi->execute("drop table $table1") };
1370
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1371
$dbi->execute($create_table1);
1372
$dbi->execute($create_table2);
1373
$dbi->register_filter(twice => sub { $_[0] * 2 });
1374
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1375
$dbi->apply_filter(
cleanup test
Yuki Kimoto authored on 2011-08-15
1376
    $table1, $key2 => {out => 'twice', in => 'twice'}
1377
);
1378
$dbi->apply_filter(
1379
    $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1380
);
cleanup
Yuki Kimoto authored on 2011-11-01
1381
$dbi->insert({$key1 => 5, $key2 => 2}, table => $table1, filter => {$key2 => undef});
1382
$dbi->insert({$key1 => 5, $key3 => 6}, table => $table2, filter => {$key3 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1383
$result = $dbi->select(
1384
     table => [$table1, $table2],
1385
     column => [$key2, $key3],
1386
     where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1387

            
1388
$result->filter({$key2 => 'twice'});
1389
$rows   = $result->all;
1390
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1391

            
1392
$result = $dbi->select(
1393
     table => [$table1, $table2],
1394
     column => [$key2, $key3],
1395
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1396

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

            
1401
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1402
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1403
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1404
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1405
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1406
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1407

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1408
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1409
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1410
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1411
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1412
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1413
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1414

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1415
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1416
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1417
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1418
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1419
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1420

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

            
1432
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1433
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1434
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1435
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1436
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1437
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1438
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1439
$row = $result->fetch_first;
1440
is_deeply($row, [6, 12]);
1441

            
1442
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1443
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1444
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1445
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1446
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1447
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1448
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1449
$row = $result->fetch_first;
1450
is_deeply($row, [6, 12]);
1451

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

            
1459
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1460
$dbi->apply_filter($table1,
1461
    $key1 => {end => sub { $_[0] * 3 } },
1462
    $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1463
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1464
$result = $dbi->select(table => $table1);
1465
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1466
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1467
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1468

            
1469
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1470
$dbi->apply_filter($table1,
1471
    $key1 => {end => sub { $_[0] * 3 } },
1472
    $key2 => {end => 'five_times'}
1473
);
1474
$result = $dbi->select(table => $table1);
1475
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1476
$result->filter($key1 => undef);
1477
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1478
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1479
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1480

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1481
test 'remove_end_filter and remove_filter';
1482
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1483
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1484
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1485
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1486
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1487
$row = $result
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1488
       ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1489
       ->remove_filter
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1490
       ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1491
       ->remove_end_filter
1492
       ->fetch_first;
1493
is_deeply($row, [1, 2]);
1494

            
1495
test 'empty where select';
1496
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1497
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1498
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1499
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1500
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1501
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1502
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1503

            
1504
test 'select query option';
1505
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1506
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1507
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1508
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1509
is(ref $query, 'DBIx::Custom::Query');
cleanup
Yuki Kimoto authored on 2011-11-01
1510
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1511
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1512
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1513
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1514
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1515
is(ref $query, 'DBIx::Custom::Query');
1516

            
1517
test 'where';
1518
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1519
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1520
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1521
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1522
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1523
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1524
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1525

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

            
1530
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1531
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1532
    where => $where
1533
);
1534
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1535
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1536

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

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

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

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

            
1577
$where = $dbi->where;
1578
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1579
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1580
    where => $where
1581
);
1582
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1583
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1584

            
1585
eval {
1586
$where = $dbi->where
1587
             ->clause(['uuu']);
1588
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1589
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1590
    where => $where
1591
);
1592
};
1593
ok($@);
1594

            
1595
$where = $dbi->where;
1596
is("$where", '');
1597

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1738
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1739
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1740
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists]});
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
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1749
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1750
             ->param({$key1 => [0, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1751
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1752
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1753
    where => $where,
1754
);
1755
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1756
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1757

            
1758
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1759
             ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1760
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1761
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1762
    where => $where,
1763
);
1764
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1765
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1766

            
1767
eval {$dbi->where(ppp => 1) };
1768
like($@, qr/invalid/);
1769

            
1770
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1771
    clause => ['and', ['or'], ['and', "$key1 = :$key1", "$key2 = :$key2"]],
1772
    param => {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
1773
);
1774
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1775
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1776
    where => $where,
1777
);
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

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

            
1793
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1794
$where->clause(['and', ":${key1}{=}"]);
1795
$where->param({$key1 => undef});
1796
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1797
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1798
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1799

            
1800
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1801
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1802
$where->param({$key1 => [undef, undef]});
1803
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1804
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1805
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1806
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1807
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1808
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1809

            
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1810

            
1811
$dbi = DBIx::Custom->connect;
1812
eval { $dbi->execute("drop table $table1") };
1813
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1814
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
1815
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1816
$where = $dbi->where
1817
             ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
1818
             ->param({$key1 => 1});
1819

            
1820
$result = $dbi->select(
1821
    table => $table1,
1822
    where => $where
1823
);
1824
$row = $result->all;
1825
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
1826

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1827
test 'register_tag_processor';
1828
$dbi = DBIx::Custom->connect;
1829
$dbi->register_tag_processor(
1830
    a => sub { 1 }
1831
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1832
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1833

            
1834
test 'register_tag';
1835
$dbi = DBIx::Custom->connect;
1836
$dbi->register_tag(
1837
    b => sub { 2 }
1838
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1839
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1840

            
1841
test 'table not specify exception';
1842
$dbi = DBIx::Custom->connect;
1843
eval {$dbi->select};
1844
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1845

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1846
test 'more tests';
1847
$dbi = DBIx::Custom->connect;
1848
eval{$dbi->apply_filter('table', 'column', [])};
1849
like($@, qr/apply_filter/);
1850

            
1851
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1852
like($@, qr/apply_filter/);
1853

            
1854
$dbi->apply_filter(
1855

            
1856
);
1857
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1858
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1859
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1860
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1861
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1862
$dbi->apply_filter($table1, $key2, 
test cleanup
Yuki Kimoto authored on 2011-08-10
1863
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1864
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
1865
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1866

            
1867
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1868
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1869
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1870
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1871
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1872
$dbi->apply_filter($table1, $key2, {});
1873
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1874
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1875

            
1876
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1877
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1878
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1879
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1880
like($@, qr/not registered/);
1881
$dbi->method({one => sub { 1 }});
1882
is($dbi->one, 1);
1883

            
1884
eval{DBIx::Custom->connect(dsn => undef)};
1885
like($@, qr/_connect/);
1886

            
1887
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1888
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1889
$dbi->execute($create_table1);
1890
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
1891
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1892
             filter => {$key1 => 'twice'});
1893
$row = $dbi->select(table => $table1)->one;
1894
is_deeply($row, {$key1 => 2, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
1895
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1896
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
1897
like($@, qr//);
1898

            
1899
$dbi->register_filter(one => sub { });
1900
$dbi->default_fetch_filter('one');
1901
ok($dbi->default_fetch_filter);
1902
$dbi->default_bind_filter('one');
1903
ok($dbi->default_bind_filter);
1904
eval{$dbi->default_fetch_filter('no')};
1905
like($@, qr/not registered/);
1906
eval{$dbi->default_bind_filter('no')};
1907
like($@, qr/not registered/);
1908
$dbi->default_bind_filter(undef);
1909
ok(!defined $dbi->default_bind_filter);
1910
$dbi->default_fetch_filter(undef);
1911
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1912
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1913
like($@, qr/Tag not finished/);
1914

            
1915
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1916
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1917
$dbi->execute($create_table1);
1918
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1919
$result = $dbi->select(table => $table1);
1920
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1921
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1922
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1923
like($@, qr/not registered/);
1924
$result->default_filter(undef);
1925
ok(!defined $result->default_filter);
1926
$result->default_filter('one');
1927
is($result->default_filter->(), 1);
1928

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1929
test 'option';
1930
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
1931
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
1932
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
1933
ok($dbi->dbh->{PrintError});
1934
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
1935
ok($dbi->dbh->{PrintError});
1936

            
1937
test 'DBIx::Custom::Result stash()';
1938
$result = DBIx::Custom::Result->new;
1939
is_deeply($result->stash, {}, 'default');
1940
$result->stash->{foo} = 1;
1941
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
1942

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1943
test 'delete_at';
1944
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1945
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1946
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
1947
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
1948
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1949
    table => $table1,
1950
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1951
    where => [1, 2],
1952
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1953
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1954

            
cleanup
Yuki Kimoto authored on 2011-11-01
1955
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
1956
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1957
    table => $table1,
1958
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1959
    where => 1,
1960
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1961
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1962

            
1963
test 'insert_at';
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
Yuki Kimoto authored on 2011-11-01
1968
    {$key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1977
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1978
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
1979
$dbi->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
1980
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1981
    primary_key => $key1, 
1982
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1983
    where => 1,
1984
);
1985

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

            
1990
eval {
1991
    $dbi->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
1992
        {$key1 => 1, $key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1993
        table => $table1,
1994
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1995
        where => {},
1996
    );
1997
};
1998
like($@, qr/must be/);
1999

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

            
2013
test 'update_at';
2014
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2015
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2016
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2017
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2018
$dbi->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2019
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2020
    table => $table1,
2021
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2022
    where => [1, 2],
2023
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2024
is($dbi->select(table => $table1)->one->{$key1}, 1);
2025
is($dbi->select(table => $table1)->one->{$key2}, 2);
2026
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2027

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2028
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2029
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2030
$dbi->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2031
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2032
    table => $table1,
2033
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2034
    where => 1,
2035
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2036
is($dbi->select(table => $table1)->one->{$key1}, 1);
2037
is($dbi->select(table => $table1)->one->{$key2}, 2);
2038
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2039

            
2040
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2041
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2042
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2043
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2044
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2045
    {$key3 => 4},
2046
    table => $table1,
2047
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2048
    where => [1, 2]
2049
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2050
is($dbi->select(table => $table1)->one->{$key1}, 1);
2051
is($dbi->select(table => $table1)->one->{$key2}, 2);
2052
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2053

            
2054
test 'select_at';
2055
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2056
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2057
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2058
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2059
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2060
    table => $table1,
2061
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2062
    where => [1, 2]
2063
);
2064
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2065
is($row->{$key1}, 1);
2066
is($row->{$key2}, 2);
2067
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2068

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2069
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2070
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2071
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2072
    table => $table1,
2073
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2074
    where => 1,
2075
);
2076
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2077
is($row->{$key1}, 1);
2078
is($row->{$key2}, 2);
2079
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2080

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2081
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2082
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2083
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2084
    table => $table1,
2085
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2086
    where => [1, 2]
2087
);
2088
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2089
is($row->{$key1}, 1);
2090
is($row->{$key2}, 2);
2091
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2092

            
2093
eval {
2094
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2095
        table => $table1,
2096
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2097
        where => {},
2098
    );
2099
};
2100
like($@, qr/must be/);
2101

            
2102
eval {
2103
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2104
        table => $table1,
2105
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2106
        where => [1],
2107
    );
2108
};
2109
like($@, qr/same/);
2110

            
2111
eval {
2112
    $result = $dbi->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2113
        {$key1 => 1, $key2 => 2},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2114
        table => $table1,
2115
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2116
        where => {},
2117
    );
2118
};
2119
like($@, qr/must be/);
2120

            
2121
eval {
2122
    $result = $dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2123
        table => $table1,
2124
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2125
        where => {},
2126
    );
2127
};
2128
like($@, qr/must be/);
2129

            
2130
test 'model delete_at';
2131
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2132
eval { $dbi->execute("drop table $table1") };
2133
eval { $dbi->execute("drop table $table2") };
2134
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2135
$dbi->execute($create_table1_2);
2136
$dbi->execute($create_table2_2);
2137
$dbi->execute($create_table3);
test cleanup
Yuki Kimoto authored on 2011-11-01
2138
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2139
$dbi->model($table1)->delete_at(where => [1, 2]);
2140
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2141
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2142
$dbi->model($table1)->delete_at(where => [1, 2]);
2143
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2144
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2145
$dbi->model($table3)->delete_at(where => [1, 2]);
2146
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2147

            
2148
test 'model insert_at';
2149
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2150
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2151
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2152
$dbi->model($table1)->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2153
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2154
    where => [1, 2],
2155
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2156
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2157
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2158
is($row->{$key1}, 1);
2159
is($row->{$key2}, 2);
2160
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2161

            
2162
test 'model update_at';
2163
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2164
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2165
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2166
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2167
$dbi->model($table1)->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2168
    {$key3 => 4},
cleanup test
Yuki Kimoto authored on 2011-08-10
2169
    where => [1, 2],
2170
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2171
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2172
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2173
is($row->{$key1}, 1);
2174
is($row->{$key2}, 2);
2175
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2176

            
2177
test 'model select_at';
2178
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2179
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2180
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2181
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2182
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2183
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2184
is($row->{$key1}, 1);
2185
is($row->{$key2}, 2);
2186
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2187

            
2188

            
2189
test 'mycolumn and column';
2190
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2191
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2192
eval { $dbi->execute("drop table $table1") };
2193
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2194
$dbi->execute($create_table1);
2195
$dbi->execute($create_table2);
2196
$dbi->separator('__');
2197
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2198
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2199
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2200
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2201
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2202
    column => [$model->mycolumn, $model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2203
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2204
);
2205
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2206
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2207

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2208
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2209
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2210
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2211
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2212
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2213
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2214
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2215
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2216
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2217
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2218
is($dbi->select(table => $table1)->one->{$key1}, 1);
2219
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2220

            
2221
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2222
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2223
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2224
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2225
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2226
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2227
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2228
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2229
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2230
is($dbi->select(table => $table1)->one->{$key1}, 1);
2231
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2232

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2236
test 'mycolumn';
2237
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2238
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2239
eval { $dbi->execute("drop table $table1") };
2240
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2241
$dbi->execute($create_table1);
2242
$dbi->execute($create_table2);
2243
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2244
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2245
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2246
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2247
$result = $model->select_at(
2248
    column => [
2249
        $model->mycolumn,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2250
        $model->column($table2)
cleanup test
Yuki Kimoto authored on 2011-08-10
2251
    ]
2252
);
2253
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2254
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2255

            
2256
$result = $model->select_at(
2257
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2258
        $model->mycolumn([$key1]),
2259
        $model->column($table2 => [$key1])
cleanup test
Yuki Kimoto authored on 2011-08-10
2260
    ]
2261
);
2262
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2263
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2264
$result = $model->select_at(
2265
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2266
        $model->mycolumn([$key1]),
2267
        {$table2 => [$key1]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2268
    ]
2269
);
2270
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2271
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2272

            
2273
$result = $model->select_at(
2274
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2275
        $model->mycolumn([$key1]),
2276
        ["$table2.$key1", as => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2277
    ]
2278
);
2279
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2280
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2281

            
2282
$result = $model->select_at(
2283
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2284
        $model->mycolumn([$key1]),
2285
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2286
    ]
2287
);
2288
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2289
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2290

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2291
test 'merge_param';
2292
$dbi = DBIx::Custom->new;
2293
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2294
    {$key1 => 1, $key2 => 2, $key3 => 3},
2295
    {$key1 => 1, $key2 => 2},
2296
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2297
];
2298
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2299
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2300

            
2301
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2302
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2303
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2304
];
2305
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2306
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
2307

            
2308
test 'select() param option';
2309
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2310
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2311
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2312
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2313
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2314
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2315
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2316
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
2317
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
2318
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2319
    table => $table1,
2320
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2321
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2322
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
test cleanup
Yuki Kimoto authored on 2011-08-15
2323
              " $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2324
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2325
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2326
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2327

            
cleanup
Yuki Kimoto authored on 2011-10-21
2328
$rows = $dbi->select(
2329
    table => $table1,
2330
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2331
    where   => {"$table1.$key2" => 3},
2332
    join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2333
             " $table2 on $table1.$key1 = $table2.$key1",
2334
    param => {"$table2.$key3" => 5}
2335
)->all;
2336
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2337

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

            
2351
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2352
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2353
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2354
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2355
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2356
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2357
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2358
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2359
        "$key1 = :$key1 and $key2 = :$key2",
2360
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2361
    ]
2362
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2363
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2364

            
cleanup
Yuki Kimoto authored on 2011-10-21
2365
$dbi = DBIx::Custom->connect;
2366
eval { $dbi->execute("drop table $table1") };
2367
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2368
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2369
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
2370
$rows = $dbi->select(
2371
    table => $table1,
2372
    where => [
2373
        "$key1 = :$key1 and $key2 = :$key2",
2374
        {$key1 => 1, $key2 => 2}
2375
    ]
2376
)->all;
2377
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2378

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2379
test 'delete() string where';
2380
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2381
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2382
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2383
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2384
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2385
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2386
    table => $table1,
2387
    where => "$key1 = :$key1 and $key2 = :$key2",
2388
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2389
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2390
$rows = $dbi->select(table => $table1)->all;
2391
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2392

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

            
2408

            
2409
test 'update() string where';
2410
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2411
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2412
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2413
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2414
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2415
    {$key1 => 5},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2416
    table => $table1,
2417
    where => "$key1 = :$key1 and $key2 = :$key2",
2418
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2419
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2420
$rows = $dbi->select(table => $table1)->all;
2421
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2422

            
2423
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2424
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2425
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2426
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2427
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2428
    {$key1 => 5},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2429
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2430
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2431
        "$key1 = :$key1 and $key2 = :$key2",
2432
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2433
    ]
2434
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2435
$rows = $dbi->select(table => $table1)->all;
2436
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2437

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2452
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2453
$dbi->insert(
cleanup
Yuki Kimoto authored on 2011-11-01
2454
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2455
    primary_key => $key1, 
2456
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2457
    id => 0,
2458
);
2459

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

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

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2477
$dbi = DBIx::Custom->connect;
2478
eval { $dbi->execute("drop table $table1") };
2479
$dbi->execute($create_table1_2);
2480
$param = {$key3 => 3, $key2 => 4};
2481
$dbi->insert(
2482
    $param,
2483
    primary_key => [$key1, $key2], 
2484
    table => $table1,
2485
    id => [1, 2],
2486
);
2487
is($dbi->select(table => $table1)->one->{$key1}, 1);
2488
is($dbi->select(table => $table1)->one->{$key2}, 4);
2489
is($dbi->select(table => $table1)->one->{$key3}, 3);
2490
is_deeply($param, {$key3 => 3, $key2 => 4});
2491

            
added test
Yuki Kimoto authored on 2011-10-25
2492
$dbi = DBIx::Custom->connect;
2493
eval { $dbi->execute("drop table $table1") };
2494
$dbi->execute($create_table1_2);
2495
$param = {$key3 => 3, $key2 => 4};
2496
$query = $dbi->insert(
2497
    $param,
2498
    primary_key => [$key1, $key2], 
2499
    table => $table1,
2500
    id => [1, 2],
2501
    query => 1
2502
);
2503
is(ref $query, 'DBIx::Custom::Query');
2504
is_deeply($param, {$key3 => 3, $key2 => 4});
2505

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

            
2520
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2521
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2522
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2523
$dbi->model($table1)->insert(
2524
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2525
    id => [1, 2]
2526
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2527
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2528
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2529
is($row->{$key1}, 1);
2530
is($row->{$key2}, 2);
2531
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2532

            
2533
test 'update and id option';
2534
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2535
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2536
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2537
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2538
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2539
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2540
    table => $table1,
2541
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2542
    id => [1, 2],
2543
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2544
is($dbi->select(table => $table1)->one->{$key1}, 1);
2545
is($dbi->select(table => $table1)->one->{$key2}, 2);
2546
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2547

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2548
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2549
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2550
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2551
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2552
    table => $table1,
2553
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2554
    id => 0,
2555
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2556
is($dbi->select(table => $table1)->one->{$key1}, 0);
2557
is($dbi->select(table => $table1)->one->{$key2}, 2);
2558
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2559

            
2560
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2561
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2562
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2563
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2564
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2565
    {$key3 => 4},
2566
    table => $table1,
2567
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2568
    id => [1, 2]
2569
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2570
is($dbi->select(table => $table1)->one->{$key1}, 1);
2571
is($dbi->select(table => $table1)->one->{$key2}, 2);
2572
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2573

            
2574

            
2575
test 'model update and id option';
2576
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2577
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2578
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2579
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2580
$dbi->model($table1)->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2581
    {$key3 => 4},
cleanup test
Yuki Kimoto authored on 2011-08-10
2582
    id => [1, 2],
2583
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2584
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2585
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2586
is($row->{$key1}, 1);
2587
is($row->{$key2}, 2);
2588
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2589

            
2590

            
2591
test 'delete and id option';
2592
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2593
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2594
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2595
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2596
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2597
    table => $table1,
2598
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2599
    id => [1, 2],
2600
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2601
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2602

            
cleanup
Yuki Kimoto authored on 2011-11-01
2603
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2604
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2605
    table => $table1,
2606
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2607
    id => 0,
2608
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2609
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2610

            
2611

            
2612
test 'model delete and id option';
2613
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2614
eval { $dbi->execute("drop table $table1") };
2615
eval { $dbi->execute("drop table $table2") };
2616
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2617
$dbi->execute($create_table1_2);
2618
$dbi->execute($create_table2_2);
2619
$dbi->execute($create_table3);
cleanup
Yuki Kimoto authored on 2011-11-01
2620
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2621
$dbi->model($table1)->delete(id => [1, 2]);
2622
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2623
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2624
$dbi->model($table1)->delete(id => [1, 2]);
2625
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2626
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2627
$dbi->model($table3)->delete(id => [1, 2]);
2628
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2629

            
2630

            
2631
test 'select and id option';
2632
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2633
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2634
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2635
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2636
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2637
    table => $table1,
2638
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2639
    id => [1, 2]
2640
);
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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2646
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2647
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2648
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2649
    table => $table1,
2650
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2651
    id => 0,
2652
);
2653
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2654
is($row->{$key1}, 0);
2655
is($row->{$key2}, 2);
2656
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2657

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2658
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2659
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2660
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2661
    table => $table1,
2662
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2663
    id => [1, 2]
2664
);
2665
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2666
is($row->{$key1}, 1);
2667
is($row->{$key2}, 2);
2668
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2669

            
2670

            
2671
test 'model select_at';
2672
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2673
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2674
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2675
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2676
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2677
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2678
is($row->{$key1}, 1);
2679
is($row->{$key2}, 2);
2680
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2681

            
2682
test 'column separator is default .';
2683
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2684
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2685
eval { $dbi->execute("drop table $table1") };
2686
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2687
$dbi->execute($create_table1);
2688
$dbi->execute($create_table2);
2689
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2690
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2691
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2692
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2693
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2694
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2695
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2696
);
2697
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2698
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2699

            
2700
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2701
    column => [$model->column($table2 => [$key1, $key3])],
2702
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2703
);
2704
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2705
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2706

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2707
test 'separator';
2708
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2709
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2710
eval { $dbi->execute("drop table $table1") };
2711
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2712
$dbi->execute($create_table1);
2713
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2714

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2715
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2716
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2717
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2718
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2719
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2720
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2721
);
2722
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2723
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2724
);
2725
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2726
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2727
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2728
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2729
$result = $model->select(
2730
    column => [
2731
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2732
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2733
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2734
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2735
);
2736
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2737
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2738
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2739

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2740
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2741
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2742
$result = $model->select(
2743
    column => [
2744
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2745
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2746
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2747
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2748
);
2749
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2750
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
2751
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2752

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2753
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2754
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2755
$result = $model->select(
2756
    column => [
2757
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2758
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2759
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2760
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2761
);
2762
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2763
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2764
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2765

            
2766

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2767
test 'filter_off';
2768
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2769
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2770
eval { $dbi->execute("drop table $table1") };
2771
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2772
$dbi->execute($create_table1);
2773
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2774

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2775
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2776
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2777
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2778
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2779
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2780
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2781
);
2782
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2783
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2784
$model = $dbi->model($table1);
2785
$result = $model->select(column => $key1);
2786
$result->filter($key1 => sub { $_[0] * 2 });
2787
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2788

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2789
test 'available_datetype';
2790
$dbi = DBIx::Custom->connect;
2791
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2792

            
2793

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2794
test 'select prefix option';
2795
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2796
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2797
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2798
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2799
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2800
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2801

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

            
added tests
Yuki Kimoto authored on 2011-08-26
2803
test 'mapper';
2804
$dbi = DBIx::Custom->connect;
2805
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2806
    id => {key => "$table1.id"},
2807
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2808
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
2809
);
2810
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2811
  "$table1.price" => 1900});
2812

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2813
$dbi = DBIx::Custom->connect;
2814
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2815
    id => {key => "$table1.id"},
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2816
    author => ["$table1.author" => $dbi->like_value],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2817
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2818
);
2819
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2820
  "$table1.price" => 1900});
2821

            
added tests
Yuki Kimoto authored on 2011-08-26
2822
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2823
    id => {key => "$table1.id"},
2824
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2825
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
2826
);
2827
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2828

            
2829
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2830
    id => {key => "$table1.id"},
2831
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2832
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
added tests
Yuki Kimoto authored on 2011-08-26
2833
);
2834
is_deeply($param, {});
2835

            
2836
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2837
    id => {key => "$table1.id"},
2838
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2839
);
2840
is_deeply($param, {"$table1.price" => undef});
2841

            
2842
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2843
    id => {key => "$table1.id", condition => 'exists'},
2844
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
2845
);
2846
is_deeply($param, {"$table1.price" => '%a'});
2847

            
2848
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2849
    id => {key => "$table1.id"},
added tests
Yuki Kimoto authored on 2011-08-26
2850
    price => ["$table1.price", sub { '%' . $_[0] }]
2851
);
2852
is_deeply($param, {"$table1.price" => '%a'});
2853

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2854
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2855
    price => sub { '%' . $_[0] },
2856
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2857
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2858
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2859

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2860
eval { $dbi->execute("drop table $table1") };
2861
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2862
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2863
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2864

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

            
2873
$where = $dbi->where;
2874
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2875
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
2876
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2877
$row = $result->all;
2878
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2879
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2880
$row = $result->all;
2881
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2882

            
2883
$where = $dbi->where;
2884
$where->clause(['and', ":${key1}{=}"]);
2885
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
2886
$where->param($param);
2887
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2888
$row = $result->all;
2889
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2890
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2891
$row = $result->all;
2892
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2893

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2895
$where = $dbi->where;
2896
$where->clause(['and', ":${key1}{=}"]);
2897
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
2898
  ->pass([$key1, $key2])->map;
2899
$where->param($param);
2900
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2901
$row = $result->all;
2902
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2903

            
2904
$where = $dbi->where;
2905
$where->clause(['and', ":${key1}{=}"]);
2906
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
2907
$where->param($param);
2908
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2909
$row = $result->all;
2910
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2911

            
2912
$where = $dbi->where;
2913
$where->clause(['and', ":${key1}{=}"]);
2914
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
2915
  ->pass([$key1, $key2])->map;
2916
$where->param($param);
2917
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2918
$row = $result->all;
2919
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2920

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2922
$where = $dbi->where;
2923
$where->clause(['and', ":${key1}{=}"]);
2924
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
2925
$where->param($param);
2926
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2927
$row = $result->all;
2928
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2929

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

            
2940
$where = $dbi->where;
2941
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2942
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2943
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2944
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2945
);
2946
$where->param($param);
2947
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2948

            
2949
$where = $dbi->where;
2950
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2951
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2952
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2953
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2954
);
2955
$where->param($param);
2956
is_deeply($where->param, {});
2957

            
2958
$where = $dbi->where;
2959
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2960
    id => {key => "$table1.id"},
2961
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2962
);
2963
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
2964

            
2965
$where = $dbi->where;
2966
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2967
    id => {key => "$table1.id", condition => 'exists'},
2968
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2969
);
2970
is_deeply($param, {"$table1.price" => '%a'});
2971

            
2972
$where = $dbi->where;
2973
$param = $dbi->mapper(param => {id => [1, 2], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2974
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2975
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2976
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2977
);
2978
is_deeply($param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
2979
  "$table1.price" => 1900});
2980

            
2981
$where = $dbi->where;
2982
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900}, condition => 'length')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2983
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2984
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2985
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2986
);
2987
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2988
  "$table1.price" => 1900});
2989

            
2990
$where = $dbi->where;
2991
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2992
    id => {key => "$table1.id", condition => 'length'},
2993
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
2994
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2995
);
2996
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2997
  "$table1.price" => 1900});
2998

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3004
test 'order';
3005
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3006
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3007
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3008
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3009
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3010
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3011
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3012
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3013
$order->prepend($key1, "$key2 desc");
3014
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3015
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
3016
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3017
$order->prepend("$key1 desc");
3018
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3019
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
3020
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3021

            
3022
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3023
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3024
$result = $dbi->select(table => $table1,
3025
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3026
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3027
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
3028
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
3029
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
3030
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3031

            
3032
test 'tag_parse';
3033
$dbi = DBIx::Custom->connect;
3034
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3035
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3036
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3037
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3038
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3039
ok($@);
3040

            
3041
test 'last_sql';
3042
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3043
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3044
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3045
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
3046
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3047

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

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

            
3058
test 'Named placeholder :name(operater) syntax';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3059
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3060
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
3061
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
3062
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3063

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3064
$source = "select * from $table1 where :${key1}{=} and :${key2}{=}";
cleanup
Yuki Kimoto authored on 2011-11-01
3065
$result = $dbi->execute($source, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
3066
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3067
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3068

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3069
$source = "select * from $table1 where :${key1}{ = } and :${key2}{=}";
cleanup
Yuki Kimoto authored on 2011-11-01
3070
$result = $dbi->execute($source, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
3071
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3072
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3073

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3074
$source = "select * from $table1 where :${key1}{<} and :${key2}{=}";
cleanup
Yuki Kimoto authored on 2011-11-01
3075
$result = $dbi->execute($source, {$key1 => 5, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
3076
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3077
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3078

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3079
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3080
$result = $dbi->execute(
3081
    $source,
cleanup
Yuki Kimoto authored on 2011-11-01
3082
    {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3083
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3084
);
3085
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3086
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3087

            
3088
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3089
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3090
$dbi->execute($create_table1_highperformance);
3091
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3092
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3093
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3094
];
3095
{
3096
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3097
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3098
      $query ||= $dbi->insert($row, table => $table1, query => 1);
3099
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
3100
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3101
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3102
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3103
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3104
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3105
      ]
3106
    );
3107
}
3108

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3109
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3110
$dbi->execute($create_table1_highperformance);
3111
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3112
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3113
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3114
];
3115
{
3116
    my $query;
3117
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
3118
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3119
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3120
      $sth ||= $query->sth;
3121
      $sth->execute(map { $row->{$_} } sort keys %$row);
3122
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3123
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3124
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3125
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3126
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3127
      ]
3128
    );
3129
}
3130

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3131
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3132
$dbi->execute($create_table1_highperformance);
3133
$rows = [
3134
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
3135
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
3136
];
3137
{
3138
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3139
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3140
    for my $row (@$rows) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3141
      $query ||= $model->insert($row, query => 1);
3142
      $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3143
    }
3144
    is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3145
      [
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3146
          {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3147
          {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3148
      ]
3149
    );
3150
}
3151

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

            
3166
eval { $dbi->execute("drop table $table1") };
3167
eval { $dbi->execute("drop table $table2") };
3168
$dbi->execute($create_table1);
3169
$dbi->execute($create_table2);
3170
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3171
$model->insert({$key1 => 1, $key2 => 2});
3172
$model = $dbi->create_model(table => $table2, primary_key => $key1,
3173
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
3174
$model->insert({$key1 => 1, $key3 => 3});
3175
$result = $model->select(
3176
    column => {$table1 => ["$key2"]},
3177
    id => 1
3178
);
3179
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3180

            
3181
eval { $dbi->execute("drop table $table1") };
3182
$dbi->execute($create_table1_highperformance);
3183
$row = {
3184
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3185
};
3186
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3187
$model->insert($row);
3188
$query = $model->delete(id => 1, query => 1);
3189
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3190
is_deeply($dbi->select(table => $table1)->all, []);
3191

            
3192
eval { $dbi->execute("drop table $table1") };
3193
eval { $dbi->execute($create_table1_highperformance) };
3194
$row = {
3195
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3196
};
3197
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3198
$model->insert($row);
3199
$query = $model->select(id => 1, query => 1);
3200
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3201
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3202
is_deeply($dbi->select(table => $table1)->one,
3203
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3204
);
3205

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3206
test 'result';
3207
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3208
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3209
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3210
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3211
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
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
@rows = ();
3215
while (my $row = $result->fetch) {
3216
    push @rows, [@$row];
3217
}
3218
is_deeply(\@rows, [[1, 2], [3, 4]]);
3219

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3220
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3221
@rows = ();
3222
while (my $row = $result->fetch_hash) {
3223
    push @rows, {%$row};
3224
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3225
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3226

            
3227
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3228
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3229
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3230
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3231
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3232

            
3233
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3234
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3235
$rows = $result->fetch_all;
3236
is_deeply($rows, [[1, 2], [3, 4]]);
3237

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

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

            
3246
$rows = $result->fetch_all;
3247
is_deeply($rows, [[3, 2], [9, 4]], "array");
3248

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

            
3255
test "query_builder";
3256
$datas = [
3257
    # Basic tests
3258
    {   name            => 'placeholder basic',
3259
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3260
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3261
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3262
    },
3263
    {
3264
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3265
        source            => "{in k1 3}",
3266
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3267
        columns_expected   => [qw/k1 k1 k1/]
3268
    },
3269
    
3270
    # Table name
3271
    {
3272
        name            => 'placeholder with table name',
3273
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3274
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3275
        columns_expected  => [qw/a.k1 a.k2/]
3276
    },
3277
    {   
3278
        name            => 'placeholder in with table name',
3279
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3280
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3281
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3282
    },
3283
    {
3284
        name            => 'not contain tag',
3285
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3286
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3287
        columns_expected  => [],
3288
    }
3289
];
3290

            
3291
for (my $i = 0; $i < @$datas; $i++) {
3292
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3293
    my $dbi = DBIx::Custom->new;
3294
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3295
    my $query = $builder->build_query($data->{source});
3296
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3297
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3298
}
3299

            
cleanup
Yuki Kimoto authored on 2011-08-13
3300
$dbi = DBIx::Custom->new;
3301
$builder = $dbi->query_builder;
3302
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3303
    p => sub {
3304
        my @args = @_;
3305
        
3306
        my $expand    = "? $args[0] $args[1]";
3307
        my $columns = [2];
3308
        return [$expand, $columns];
3309
    }
3310
);
3311

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3322
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3323
    q => 'string'
3324
});
3325

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3329
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3330
   r => sub {} 
3331
});
3332

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3336
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3337
   s => sub { return ["a", ""]} 
3338
});
3339

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3343
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3344
    t => sub {return ["a", []]}
3345
);
3346

            
3347

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

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

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

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

            
3363
test 'variouse source';
3364
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3365
$query = $builder->build_query($source);
3366
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3367

            
3368
$source = "abc";
3369
$query = $builder->build_query($source);
3370
is($query->sql, 'abc', "basic : 2");
3371

            
3372
$source = "{= a}";
3373
$query = $builder->build_query($source);
3374
is($query->sql, 'a = ?', "only tag");
3375

            
3376
$source = "000";
3377
$query = $builder->build_query($source);
3378
is($query->sql, '000', "contain 0 value");
3379

            
3380
$source = "a {= b} }";
3381
eval{$builder->build_query($source)};
3382
like($@, qr/unexpected "}"/, "error : 1");
3383

            
3384
$source = "a {= {}";
3385
eval{$builder->build_query($source)};
3386
like($@, qr/unexpected "{"/, "error : 2");
3387

            
3388
test 'select() sqlfilter option';
3389
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3390
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3391
eval { $dbi->execute("drop table $table1") };
3392
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3393
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3394
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3395
$rows = $dbi->select(
3396
    table => $table1,
3397
    column => $key1,
3398
    sqlfilter => sub {
3399
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
3400
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
3401
        return $sql;
3402
    }
3403
)->all;
3404
is_deeply($rows, [{$key1 => 1}]);
3405

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3406
test 'select() after_build_sql option';
3407
$dbi = DBIx::Custom->connect;
3408
$dbi->user_table_info($user_table_info);
3409
eval { $dbi->execute("drop table $table1") };
3410
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3411
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3412
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3413
$rows = $dbi->select(
3414
    table => $table1,
3415
    column => $key1,
3416
    after_build_sql => sub {
3417
        my $sql = shift;
3418
        $sql = "select * from ( $sql ) t where $key1 = 1";
3419
        return $sql;
3420
    }
3421
)->all;
3422
is_deeply($rows, [{$key1 => 1}]);
3423

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3424
test 'dbi method from model';
3425
$dbi = MyDBI9->connect;
3426
eval { $dbi->execute("drop table $table1") };
3427
$dbi->execute($create_table1);
3428
$dbi->setup_model;
3429
$model = $dbi->model($table1);
3430
eval{$model->execute("select * from $table1")};
3431
ok(!$@);
3432

            
3433
test 'column table option';
3434
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3435
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3436
eval { $dbi->execute("drop table $table1") };
3437
$dbi->execute($create_table1);
3438
eval { $dbi->execute("drop table $table2") };
3439
$dbi->execute($create_table2);
3440
$dbi->setup_model;
3441
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3442
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3443
$model = $dbi->model($table1);
3444
$result = $model->select(
3445
    column => [
3446
        $model->column($table2, {alias => $table2_alias})
3447
    ],
3448
    where => {"$table2_alias.$key3" => 4}
3449
);
3450
is_deeply($result->one, 
3451
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3452

            
3453
$dbi->separator('__');
3454
$result = $model->select(
3455
    column => [
3456
        $model->column($table2, {alias => $table2_alias})
3457
    ],
3458
    where => {"$table2_alias.$key3" => 4}
3459
);
3460
is_deeply($result->one, 
3461
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3462

            
3463
$dbi->separator('-');
3464
$result = $model->select(
3465
    column => [
3466
        $model->column($table2, {alias => $table2_alias})
3467
    ],
3468
    where => {"$table2_alias.$key3" => 4}
3469
);
3470
is_deeply($result->one, 
3471
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3472

            
3473
test 'create_model';
3474
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3475
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3476
eval { $dbi->execute("drop table $table1") };
3477
eval { $dbi->execute("drop table $table2") };
3478
$dbi->execute($create_table1);
3479
$dbi->execute($create_table2);
3480

            
3481
$dbi->create_model(
3482
    table => $table1,
3483
    join => [
3484
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3485
    ],
3486
    primary_key => [$key1]
3487
);
3488
$model2 = $dbi->create_model(
3489
    table => $table2
3490
);
3491
$dbi->create_model(
3492
    table => $table3,
3493
    filter => [
3494
        $key1 => {in => sub { uc $_[0] }}
3495
    ]
3496
);
3497
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3498
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3499
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3500
$model = $dbi->model($table1);
3501
$result = $model->select(
3502
    column => [$model->mycolumn, $model->column($table2)],
3503
    where => {"$table1.$key1" => 1}
3504
);
3505
is_deeply($result->one,
3506
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3507
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3508

            
3509
test 'model method';
3510
$dbi = DBIx::Custom->connect;
3511
eval { $dbi->execute("drop table $table2") };
3512
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3513
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3514
$model = $dbi->create_model(
3515
    table => $table2
3516
);
3517
$model->method(foo => sub { shift->select(@_) });
3518
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3519

            
3520
test 'model helper';
3521
$dbi = DBIx::Custom->connect;
3522
eval { $dbi->execute("drop table $table2") };
3523
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3524
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3525
$model = $dbi->create_model(
3526
    table => $table2
3527
);
3528
$model->helper(foo => sub { shift->select(@_) });
3529
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3530

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3531
test 'assign_clause';
cleanup test
Yuki Kimoto authored on 2011-08-15
3532
$dbi = DBIx::Custom->connect;
3533
eval { $dbi->execute("drop table $table1") };
3534
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
3535
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
3536
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3537

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

            
3551

            
3552
$dbi = DBIx::Custom->connect;
3553
eval { $dbi->execute("drop table $table1") };
3554
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
3555
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
3556
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3557

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

            
3571
$dbi = DBIx::Custom->connect;
3572
eval { $dbi->execute("drop table $table1") };
3573
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
3574
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
3575
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3576

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

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

            
3594
$dbi = DBIx::Custom->connect;
3595
eval { $dbi->execute("drop table $table1") };
3596
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
3597
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
3598
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3599

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3600
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3601
$assign_clause = $dbi->assign_param($param);
3602
$sql = <<"EOS";
3603
update $table1 set $assign_clause
3604
where $key1 = 1
3605
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3606
$dbi->execute($sql, $param, table => $table1);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3607
$result = $dbi->execute("select * from $table1 order by $key1");
3608
$rows   = $result->all;
3609
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3610
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3611
                  "basic");
3612

            
3613
$param = {$key2 => 11};
3614
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3615
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3616
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3617
where $key1 = 1
3618
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3619
$dbi->execute($sql, $param, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3620
$result = $dbi->execute("select * from $table1 order by $key1");
3621
$rows   = $result->all;
3622
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3623
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3624
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3625

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3626
test 'Model class';
3627
$dbi = MyDBI1->connect;
3628
eval { $dbi->execute("drop table $table1") };
3629
$dbi->execute($create_table1);
3630
$model = $dbi->model($table1);
3631
$model->insert({$key1 => 'a', $key2 => 'b'});
3632
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3633
eval { $dbi->execute("drop table $table2") };
3634
$dbi->execute($create_table2);
3635
$model = $dbi->model($table2);
3636
$model->insert({$key1 => 'a'});
3637
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3638
is($dbi->models->{$table1}, $dbi->model($table1));
3639
is($dbi->models->{$table2}, $dbi->model($table2));
3640

            
3641
$dbi = MyDBI4->connect;
3642
eval { $dbi->execute("drop table $table1") };
3643
$dbi->execute($create_table1);
3644
$model = $dbi->model($table1);
3645
$model->insert({$key1 => 'a', $key2 => 'b'});
3646
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3647
eval { $dbi->execute("drop table $table2") };
3648
$dbi->execute($create_table2);
3649
$model = $dbi->model($table2);
3650
$model->insert({$key1 => 'a'});
3651
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3652

            
3653
$dbi = MyDBI5->connect;
3654
eval { $dbi->execute("drop table $table1") };
3655
eval { $dbi->execute("drop table $table2") };
3656
$dbi->execute($create_table1);
3657
$dbi->execute($create_table2);
3658
$model = $dbi->model($table2);
3659
$model->insert({$key1 => 'a'});
3660
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
3661
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3662
$model = $dbi->model($table1);
3663
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3664

            
3665
test 'primary_key';
3666
$dbi = MyDBI1->connect;
3667
$model = $dbi->model($table1);
3668
$model->primary_key([$key1, $key2]);
3669
is_deeply($model->primary_key, [$key1, $key2]);
3670

            
3671
test 'columns';
3672
$dbi = MyDBI1->connect;
3673
$model = $dbi->model($table1);
3674
$model->columns([$key1, $key2]);
3675
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3676

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3677
test 'setup_model';
3678
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3679
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3680
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3681
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3682

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3683
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3684
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3685
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3686
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3687
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3688

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3689
test 'each_column';
3690
$dbi = DBIx::Custom->connect;
3691
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3692
eval { $dbi->execute("drop table $table1") };
3693
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3694
eval { $dbi->execute("drop table $table3") };
3695
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3696
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3697

            
3698
$infos = [];
3699
$dbi->each_column(sub {
3700
    my ($self, $table, $column, $cinfo) = @_;
3701
    
3702
    if ($table =~ /^table\d/i) {
3703
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3704
         push @$infos, $info;
3705
    }
3706
});
3707
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3708
is_deeply($infos, 
3709
    [
3710
        [$table1, $key1, $key1],
3711
        [$table1, $key2, $key2],
3712
        [$table2, $key1, $key1],
3713
        [$table2, $key3, $key3]
3714
    ]
3715
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3716
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3717

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3718
test 'each_table';
3719
$dbi = DBIx::Custom->connect;
3720
eval { $dbi->execute("drop table $table1") };
3721
eval { $dbi->execute("drop table $table2") };
3722
$dbi->execute($create_table2);
3723
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3724

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3725
$infos = [];
3726
$dbi->each_table(sub {
3727
    my ($self, $table, $table_info) = @_;
3728
    
3729
    if ($table =~ /^table\d/i) {
3730
         my $info = [$table, $table_info->{TABLE_NAME}];
3731
         push @$infos, $info;
3732
    }
3733
});
3734
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3735
is_deeply($infos, 
3736
    [
3737
        [$table1, $table1],
3738
        [$table2, $table2],
3739
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3740
);
3741

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3742
$dbi = DBIx::Custom->connect;
3743
eval { $dbi->execute("drop table $table1") };
3744
eval { $dbi->execute("drop table $table2") };
3745
$dbi->execute($create_table2);
3746
$dbi->execute($create_table1_type);
3747

            
3748
$infos = [];
3749
$dbi->user_table_info($user_table_info);
3750
$dbi->each_table(sub {
3751
    my ($self, $table, $table_info) = @_;
3752
    
3753
    if ($table =~ /^table\d/i) {
3754
         my $info = [$table, $table_info->{TABLE_NAME}];
3755
         push @$infos, $info;
3756
    }
3757
});
3758
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3759
is_deeply($infos, 
3760
    [
3761
        [$table1, $table1],
3762
        [$table2, $table2],
3763
        [$table3, $table3],
3764
    ]
3765
);
3766

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3767
test 'type_rule into';
3768
eval { $dbi->execute("drop table $table1") };
3769
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3770
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3771

            
3772

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3773
$dbi = DBIx::Custom->connect;
3774
eval { $dbi->execute("drop table $table1") };
3775
$dbi->execute($create_table1_type);
3776

            
cleanup
Yuki Kimoto authored on 2011-08-16
3777
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3778
$dbi->type_rule(
3779
    into1 => {
3780
        $date_typename => sub { '2010-' . $_[0] }
3781
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3782
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3783
$dbi->insert({$key1 => '01-01'}, table => $table1);
3784
$result = $dbi->select(table => $table1);
3785
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3786

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3806
$dbi = DBIx::Custom->connect;
3807
eval { $dbi->execute("drop table $table1") };
3808
$dbi->execute($create_table1_type);
3809
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3810
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3811
$dbi->type_rule(
3812
    into1 => [
3813
        [$date_typename, $datetime_typename] => sub {
3814
            my $value = shift;
3815
            $value =~ s/02/03/g;
3816
            return $value;
3817
        }
3818
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3819
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3820
$result = $dbi->execute(
3821
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
3822
    {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
3823
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3824
$row = $result->one;
3825
like($row->{$key1}, qr/^2010-01-03/);
3826
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3827

            
3828
$dbi = DBIx::Custom->connect;
3829
eval { $dbi->execute("drop table $table1") };
3830
$dbi->execute($create_table1_type);
3831
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3832
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3833
$dbi->type_rule(
3834
    into1 => [
3835
        [$date_typename, $datetime_typename] => sub {
3836
            my $value = shift;
3837
            $value =~ s/02/03/g;
3838
            return $value;
3839
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3840
    ]
3841
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3842
$result = $dbi->execute(
3843
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
3844
    {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
cleanup test
Yuki Kimoto authored on 2011-08-15
3845
    table => $table1
3846
);
3847
$row = $result->one;
3848
like($row->{$key1}, qr/^2010-01-03/);
3849
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3850

            
3851
$dbi = DBIx::Custom->connect;
3852
eval { $dbi->execute("drop table $table1") };
3853
$dbi->execute($create_table1_type);
3854
$dbi->register_filter(convert => sub {
3855
    my $value = shift || '';
3856
    $value =~ s/02/03/;
3857
    return $value;
3858
});
cleanup
Yuki Kimoto authored on 2011-08-16
3859
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3860
$dbi->type_rule(
3861
    from1 => {
3862
        $date_datatype => 'convert',
3863
    },
3864
    into1 => {
3865
        $date_typename => 'convert',
3866
    }
3867
);
3868
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3869
$result = $dbi->select(table => $table1);
3870
like($result->fetch->[0], qr/^2010-03-03/);
3871

            
3872
test 'type_rule and filter order';
3873
$dbi = DBIx::Custom->connect;
3874
eval { $dbi->execute("drop table $table1") };
3875
$dbi->execute($create_table1_type);
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
$dbi->type_rule(
3878
    into1 => {
3879
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3880
    },
3881
    into2 => {
3882
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3883
    },
3884
    from1 => {
3885
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3886
    },
3887
    from2 => {
3888
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
3889
    }
3890
);
3891
$dbi->insert({$key1 => '2010-01-03'}, 
3892
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
3893
$result = $dbi->select(table => $table1);
3894
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3895
like($result->fetch_first->[0], qr/^2010-01-09/);
3896

            
3897

            
3898
$dbi = DBIx::Custom->connect;
3899
eval { $dbi->execute("drop table $table1") };
3900
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3901
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3902
$dbi->type_rule(
3903
    from1 => {
3904
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3905
    },
3906
    from2 => {
3907
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3908
    },
3909
);
3910
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3911
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3912
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3913
$result->type_rule(
3914
    from1 => {
3915
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3916
    },
3917
    from2 => {
3918
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3919
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3920
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3921
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3922
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3923

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3924
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
3925
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
3926
eval { $dbi->execute("drop table $table1") };
3927
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3928
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3929
$dbi->type_rule(
3930
    from1 => {
3931
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3932
    },
3933
    into1 => {
3934
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3935
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3936
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3937
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3938
$result = $dbi->select(table => $table1, type_rule_off => 1);
3939
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3940

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

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

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

            
3989
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3990
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3991
$dbi->execute($create_table1_type);
3992
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
3993
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3994
$dbi->type_rule(
3995
    into1 => {
3996
        $date_typename => 'ppp'
3997
    }
3998
);
3999
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4000
$result = $dbi->select(table => $table1);
4001
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4002

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4003
eval{$dbi->type_rule(
4004
    into1 => {
4005
        $date_typename => 'pp'
4006
    }
4007
)};
4008
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4009

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4010
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4011
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4012
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4013
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
4014
    $dbi->type_rule(
4015
        from1 => {
4016
            Date => sub { $_[0] * 2 },
4017
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
4018
    );
4019
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4020
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4021

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4022
eval {
4023
    $dbi->type_rule(
4024
        into1 => {
4025
            Date => sub { $_[0] * 2 },
4026
        }
4027
    );
4028
};
4029
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4030

            
4031
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4032
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4033
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4034
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4035
$dbi->type_rule(
4036
    from1 => {
4037
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4038
    },
4039
    into1 => {
4040
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4041
    }
4042
);
4043
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4044
$result = $dbi->select(table => $table1);
4045
$result->type_rule_off;
4046
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4047

            
4048
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4049
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4050
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4051
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4052
$dbi->type_rule(
4053
    from1 => {
4054
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4055
        $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4056
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
4057
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4058
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
4059
$result = $dbi->select(table => $table1);
4060
$result->type_rule(
4061
    from1 => {
4062
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4063
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4064
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4065
$row = $result->one;
4066
like($row->{$key1}, qr/^2010-01-05/);
4067
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4068

            
4069
$result = $dbi->select(table => $table1);
4070
$result->type_rule(
4071
    from1 => {
4072
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4073
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4074
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4075
$row = $result->one;
4076
like($row->{$key1}, qr/2010-01-05/);
4077
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4078

            
4079
$result = $dbi->select(table => $table1);
4080
$result->type_rule(
4081
    from1 => {
4082
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4083
    }
4084
);
4085
$row = $result->one;
4086
like($row->{$key1}, qr/2010-01-05/);
4087
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4088

            
4089
$result = $dbi->select(table => $table1);
4090
$result->type_rule(
4091
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
4092
);
4093
$row = $result->one;
4094
like($row->{$key1}, qr/2010-01-05/);
4095
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4096

            
4097
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4098
$result = $dbi->select(table => $table1);
4099
$result->type_rule(
4100
    from1 => [$date_datatype => 'five']
4101
);
4102
$row = $result->one;
4103
like($row->{$key1}, qr/^2010-01-05/);
4104
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4105

            
4106
$result = $dbi->select(table => $table1);
4107
$result->type_rule(
4108
    from1 => [$date_datatype => undef]
4109
);
4110
$row = $result->one;
4111
like($row->{$key1}, qr/^2010-01-03/);
4112
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4113

            
4114
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4115
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4116
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4117
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4118
$dbi->type_rule(
4119
    from1 => {
4120
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4121
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
4122
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4123
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4124
$result = $dbi->select(table => $table1);
4125
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4126
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4127

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4128
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4129
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4130
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4131
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4132
$dbi->type_rule(
4133
    from1 => {
4134
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4135
    },
4136
);
4137
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4138
$result = $dbi->select(table => $table1);
4139
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4140
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4141

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4142
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4143
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4144
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4145
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4146
$dbi->type_rule(
4147
    into1 => {
4148
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4149
    },
4150
    into2 => {
4151
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4152
    },
4153
    from1 => {
4154
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4155
    },
4156
    from2 => {
4157
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4158
    }
4159
);
4160
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4161
$result = $dbi->select(table => $table1);
4162
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/);
4163
$result = $dbi->select(table => $table1);
4164
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4165

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4166
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4167
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4168
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4169
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4170
$dbi->type_rule(
4171
    into1 => {
4172
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4173
    },
4174
    into2 => {
4175
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4176
    },
4177
    from1 => {
4178
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
4179
    },
4180
    from2 => {
4181
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4182
    }
4183
);
4184
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4185
$result = $dbi->select(table => $table1);
4186
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/);
4187
$result = $dbi->select(table => $table1);
4188
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4189

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4190
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4191
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4192
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4193
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4194
$dbi->type_rule(
4195
    into1 => {
4196
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4197
    },
4198
    into2 => {
4199
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4200
    },
4201
    from1 => {
4202
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4203
    },
4204
    from2 => {
4205
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4206
    }
4207
);
4208
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4209
$result = $dbi->select(table => $table1);
4210
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
4211
$result = $dbi->select(table => $table1);
4212
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4213

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4214
test 'join';
4215
$dbi = DBIx::Custom->connect;
4216
eval { $dbi->execute("drop table $table1") };
4217
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4218
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4219
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4220
eval { $dbi->execute("drop table $table2") };
4221
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4222
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4223
eval { $dbi->execute("drop table $table3") };
4224
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4225
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4226
$rows = $dbi->select(
4227
    table => $table1,
4228
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4229
    where   => {"$table1.$key2" => 2},
4230
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4231
)->all;
4232
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4233

            
4234
$dbi = DBIx::Custom->connect;
4235
eval { $dbi->execute("drop table $table1") };
4236
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4237
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4238
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4239
eval { $dbi->execute("drop table $table2") };
4240
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4241
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4242
eval { $dbi->execute("drop table $table3") };
4243
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4244
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4245
$rows = $dbi->select(
4246
    table => $table1,
4247
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4248
    where   => {"$table1.$key2" => 2},
4249
    join  => {
4250
        clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4251
        table => [$table1, $table2]
4252
    }
4253
)->all;
4254
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
4255

            
4256
$rows = $dbi->select(
4257
    table => $table1,
4258
    where   => {$key1 => 1},
4259
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4260
)->all;
4261
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4262

            
4263
$rows = $dbi->select(
4264
    table => $table1,
4265
    where   => {$key1 => 1},
4266
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4267
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4268
)->all;
4269
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4270

            
4271
$rows = $dbi->select(
4272
    column => "$table3.$key4 as ${table3}__$key4",
4273
    table => $table1,
4274
    where   => {"$table1.$key1" => 1},
4275
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4276
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4277
)->all;
4278
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4279

            
4280
$rows = $dbi->select(
4281
    column => "$table1.$key1 as ${table1}__$key1",
4282
    table => $table1,
4283
    where   => {"$table3.$key4" => 4},
4284
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4285
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4286
)->all;
4287
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4288

            
4289
$dbi = DBIx::Custom->connect;
4290
eval { $dbi->execute("drop table $table1") };
4291
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4292
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4293
eval { $dbi->execute("drop table $table2") };
4294
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4295
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4296
$rows = $dbi->select(
4297
    table => $table1,
4298
    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",
4299
    where   => {"$table1.$key2" => 2},
4300
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4301
)->all;
4302
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4303
          'quote');
4304

            
4305

            
4306
$dbi = DBIx::Custom->connect;
4307
eval { $dbi->execute("drop table $table1") };
4308
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4309
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4310
$sql = <<"EOS";
4311
left outer join (
4312
  select * from $table1 t1
4313
  where t1.$key2 = (
4314
    select max(t2.$key2) from $table1 t2
4315
    where t1.$key1 = t2.$key1
4316
  )
4317
) $table3 on $table1.$key1 = $table3.$key1
4318
EOS
4319
$join = [$sql];
4320
$rows = $dbi->select(
4321
    table => $table1,
4322
    column => "$table3.$key1 as ${table3}__$key1",
4323
    join  => $join
4324
)->all;
4325
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4326

            
4327
$dbi = DBIx::Custom->connect;
4328
eval { $dbi->execute("drop table $table1") };
4329
eval { $dbi->execute("drop table $table2") };
4330
$dbi->execute($create_table1);
4331
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4332
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4333
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4334
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4335
$result = $dbi->select(
4336
    table => $table1,
4337
    join => [
4338
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4339
    ]
4340
);
4341
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4342
$result = $dbi->select(
4343
    table => $table1,
4344
    column => [{$table2 => [$key3]}],
4345
    join => [
4346
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4347
    ]
4348
);
4349
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4350
$result = $dbi->select(
4351
    table => $table1,
4352
    column => [{$table2 => [$key3]}],
4353
    join => [
4354
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4355
    ]
4356
);
4357
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4358

            
4359
$dbi = DBIx::Custom->connect;
4360
eval { $dbi->execute("drop table $table1") };
4361
eval { $dbi->execute("drop table $table2") };
4362
$dbi->execute($create_table1);
4363
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4364
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4365
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4366
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4367
$result = $dbi->select(
4368
    table => $table1,
4369
    column => [{$table2 => [$key3]}],
4370
    join => [
4371
        {
4372
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4373
            table => [$table1, $table2]
4374
        }
4375
    ]
4376
);
4377
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4378

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4379
$dbi = DBIx::Custom->connect;
4380
eval { $dbi->execute("drop table $table1") };
4381
eval { $dbi->execute("drop table $table2") };
4382
$dbi->execute($create_table1);
4383
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4384
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4385
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4386
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4387
$result = $dbi->select(
4388
    table => $table1,
4389
    column => [{$table2 => [$key3]}],
4390
    join => [
4391
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4392
    ]
4393
);
4394
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4395

            
4396
$dbi = DBIx::Custom->connect;
4397
eval { $dbi->execute("drop table $table1") };
4398
eval { $dbi->execute("drop table $table2") };
4399
$dbi->execute($create_table1);
4400
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4401
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4402
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4403
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4404
$result = $dbi->select(
4405
    table => $table1,
4406
    column => [{$table2 => [$key3]}],
4407
    join => [
4408
        "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4409
    ]
4410
);
4411
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4412

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4413
test 'columns';
4414
$dbi = MyDBI1->connect;
4415
$model = $dbi->model($table1);
4416

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4417
test 'count';
4418
$dbi = DBIx::Custom->connect;
4419
eval { $dbi->execute("drop table $table1") };
4420
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4421
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4422
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4423
is($dbi->count(table => $table1), 2);
4424
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4425
$model = $dbi->create_model(table => $table1);
4426
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4427

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