DBIx-Custom / t / common.t /
Newer Older
3835 lines | 126.447kb
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;
6
use lib "$FindBin::Bin/common";
cleanup
Yuki Kimoto authored on 2011-08-13
7
use Scalar::Util 'isweak';
cleanup test
Yuki Kimoto authored on 2011-08-10
8

            
added common test executing ...
Yuki Kimoto authored on 2011-08-07
9
my $dbi;
10

            
11
plan skip_all => $ENV{DBIX_CUSTOM_SKIP_MESSAGE} || 'common.t is always skipped'
12
  unless $ENV{DBIX_CUSTOM_TEST_RUN}
13
    && eval { $dbi = DBIx::Custom->connect; 1 };
14

            
15
plan 'no_plan';
16

            
cleanup test
Yuki Kimoto authored on 2011-08-15
17
# Constant
18
my $table1 = $dbi->table1;
19
my $table2 = $dbi->table2;
20
my $table2_alias = $dbi->table2_alias;
21
my $table3 = $dbi->table3;
22
my $key1 = $dbi->key1;
23
my $key2 = $dbi->key2;
24
my $key3 = $dbi->key3;
25
my $key4 = $dbi->key4;
26
my $key5 = $dbi->key5;
27
my $key6 = $dbi->key6;
28
my $key7 = $dbi->key7;
29
my $key8 = $dbi->key8;
30
my $key9 = $dbi->key9;
31
my $key10 = $dbi->key10;
32
my $create_table1 = $dbi->create_table1;
33
my $create_table1_2 = $dbi->create_table1_2;
34
my $create_table1_type = $dbi->create_table1_type;
35
my $create_table1_highperformance = $dbi->create_table1_highperformance;
36
my $create_table2 = $dbi->create_table2;
37
my $create_table2_2 = $dbi->create_table2_2;
38
my $create_table3 = $dbi->create_table3;
39
my $create_table_reserved = $dbi->create_table_reserved;
40
my $q = substr($dbi->quote, 0, 1);
41
my $p = substr($dbi->quote, 1, 1) || $q;
42
my $date_typename = $dbi->date_typename;
43
my $datetime_typename = $dbi->datetime_typename;
44
my $date_datatype = $dbi->date_datatype;
45
my $datetime_datatype = $dbi->datetime_datatype;
46

            
47
# Variables
48
my $builder;
49
my $datas;
50
my $sth;
51
my $source;
52
my @sources;
53
my $select_source;
54
my $insert_source;
55
my $update_source;
56
my $param;
57
my $params;
58
my $sql;
59
my $result;
60
my $row;
61
my @rows;
62
my $rows;
63
my $query;
64
my @queries;
65
my $select_query;
66
my $insert_query;
67
my $update_query;
68
my $ret_val;
69
my $infos;
70
my $model;
71
my $model2;
72
my $where;
73
my $update_param;
74
my $insert_param;
75
my $join;
76
my $binary;
77

            
test cleanup
Yuki Kimoto authored on 2011-08-10
78
use MyDBI1;
79
{
80
    package MyDBI4;
81

            
82
    use strict;
83
    use warnings;
84

            
85
    use base 'DBIx::Custom';
86

            
87
    sub connect {
88
        my $self = shift->SUPER::connect(@_);
89
        
90
        $self->include_model(
91
            MyModel2 => [
cleanup test
Yuki Kimoto authored on 2011-08-15
92
                $table1,
93
                {class => $table2, name => $table2}
test cleanup
Yuki Kimoto authored on 2011-08-10
94
            ]
95
        );
96
    }
97

            
98
    package MyModel2::Base1;
99

            
100
    use strict;
101
    use warnings;
102

            
103
    use base 'DBIx::Custom::Model';
104

            
test cleanup
Yuki Kimoto authored on 2011-08-10
105
    package MyModel2::table1;
test cleanup
Yuki Kimoto authored on 2011-08-10
106

            
107
    use strict;
108
    use warnings;
109

            
110
    use base 'MyModel2::Base1';
111

            
112
    sub insert {
113
        my ($self, $param) = @_;
114
        
115
        return $self->SUPER::insert(param => $param);
116
    }
117

            
118
    sub list { shift->select; }
119

            
test cleanup
Yuki Kimoto authored on 2011-08-10
120
    package MyModel2::table2;
test cleanup
Yuki Kimoto authored on 2011-08-10
121

            
122
    use strict;
123
    use warnings;
124

            
125
    use base 'MyModel2::Base1';
126

            
127
    sub insert {
128
        my ($self, $param) = @_;
129
        
130
        return $self->SUPER::insert(param => $param);
131
    }
132

            
133
    sub list { shift->select; }
134
}
135
{
136
     package MyDBI5;
137

            
138
    use strict;
139
    use warnings;
140

            
141
    use base 'DBIx::Custom';
142

            
143
    sub connect {
144
        my $self = shift->SUPER::connect(@_);
145
        
146
        $self->include_model('MyModel4');
147
    }
148
}
149
{
150
    package MyDBI6;
151
    
152
    use base 'DBIx::Custom';
153
    
154
    sub connect {
155
        my $self = shift->SUPER::connect(@_);
156
        
157
        $self->include_model('MyModel5');
158
        
159
        return $self;
160
    }
161
}
162
{
163
    package MyDBI7;
164
    
165
    use base 'DBIx::Custom';
166
    
167
    sub connect {
168
        my $self = shift->SUPER::connect(@_);
169
        
170
        $self->include_model('MyModel6');
171
        
172
        
173
        return $self;
174
    }
175
}
176
{
177
    package MyDBI8;
178
    
179
    use base 'DBIx::Custom';
180
    
181
    sub connect {
182
        my $self = shift->SUPER::connect(@_);
183
        
184
        $self->include_model('MyModel7');
185
        
186
        return $self;
187
    }
188
}
189

            
190
{
191
    package MyDBI9;
192
    
193
    use base 'DBIx::Custom';
194
    
195
    sub connect {
196
        my $self = shift->SUPER::connect(@_);
197
        
cleanup test
Yuki Kimoto authored on 2011-08-10
198
        $self->include_model('MyModel8');
test cleanup
Yuki Kimoto authored on 2011-08-10
199
        
200
        return $self;
201
    }
202
}
203

            
cleanup test
Yuki Kimoto authored on 2011-08-08
204
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
205
sub test { print "# $_[0]\n" }
206

            
cleanup test
Yuki Kimoto authored on 2011-08-15
207
# Create table
test cleanup
Yuki Kimoto authored on 2011-08-10
208
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
209
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
210
$dbi->execute($create_table1);
211
$model = $dbi->create_model(table => $table1);
212
$model->insert({$key1 => 1, $key2 => 2});
213
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-08-15
214

            
cleanup test
Yuki Kimoto authored on 2011-08-15
215
test 'DBIx::Custom::Result test';
216
$dbi->delete_all(table => $table1);
217
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
218
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
219
$source = "select $key1, $key2 from $table1";
220
$query = $dbi->create_query($source);
221
$result = $dbi->execute($query);
cleanup
Yuki Kimoto authored on 2011-08-15
222

            
cleanup test
Yuki Kimoto authored on 2011-08-15
223
@rows = ();
224
while (my $row = $result->fetch) {
225
    push @rows, [@$row];
226
}
227
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
cleanup
Yuki Kimoto authored on 2011-08-15
228

            
cleanup test
Yuki Kimoto authored on 2011-08-15
229
$result = $dbi->execute($query);
230
@rows = ();
231
while (my $row = $result->fetch_hash) {
232
    push @rows, {%$row};
233
}
234
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
235

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
244
test 'Insert query return value';
245
$source = "insert into $table1 {insert_param $key1 $key2}";
246
$query = $dbi->execute($source, {}, query => 1);
247
$ret_val = $dbi->execute($query, param => {$key1 => 1, $key2 => 2});
248
ok($ret_val);
test cleanup
Yuki Kimoto authored on 2011-08-10
249

            
cleanup test
Yuki Kimoto authored on 2011-08-15
250
test 'Direct query';
251
$dbi->delete_all(table => $table1);
252
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
253
$dbi->execute($insert_source, param => {$key1 => 1, $key2 => 2});
254
$result = $dbi->execute("select * from $table1");
255
$rows = $result->all;
256
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
257

            
258
test 'Filter basic';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
259
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-08
260
$dbi->register_filter(twice       => sub { $_[0] * 2}, 
261
                    three_times => sub { $_[0] * 3});
262

            
cleanup test
Yuki Kimoto authored on 2011-08-15
263
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
264
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
265
$insert_query->filter({$key1 => 'twice'});
266
$dbi->execute($insert_query, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
267
$result = $dbi->execute("select * from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
268
$rows = $result->filter({$key2 => 'three_times'})->all;
269
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
270

            
271
test 'Filter in';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
272
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
273
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
274
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
275
$dbi->execute($insert_query, param => {$key1 => 2, $key2 => 4});
276
$select_source = "select * from $table1 where {in $table1.$key1 2} and {in $table1.$key2 2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
277
$select_query = $dbi->execute($select_source,{}, query => 1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
278
$select_query->filter({"$table1.$key1" => 'twice'});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
279
$result = $dbi->execute($select_query, param => {"$table1.$key1" => [1,5], "$table1.$key2" => [2,4]});
cleanup test
Yuki Kimoto authored on 2011-08-08
280
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
281
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
282

            
cleanup test
Yuki Kimoto authored on 2011-08-08
283
test 'DBIx::Custom::SQLTemplate basic tag';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
284
$dbi->execute("drop table $table1");
cleanup test
Yuki Kimoto authored on 2011-08-08
285
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
286
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
287
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
288

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

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

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

            
307
test 'DIB::Custom::SQLTemplate in tag';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
308
$dbi->execute("drop table $table1");
cleanup test
Yuki Kimoto authored on 2011-08-08
309
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
310
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
311
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
312

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-08
342
test 'Named placeholder';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
343
$dbi->execute("drop table $table1");
cleanup test
Yuki Kimoto authored on 2011-08-08
344
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
345
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
346
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
347

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
363
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
364
$result = $dbi->execute(
365
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
366
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
367
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
cleanup test
Yuki Kimoto authored on 2011-08-08
368
);
369
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
370
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
371

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
372
$dbi->execute("drop table $table1");
cleanup test
Yuki Kimoto authored on 2011-08-08
373
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
374
$dbi->insert(table => $table1, param => {$key1 => '2011-10-14 12:19:18', $key2 => 2});
375
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
376
$result = $dbi->execute(
377
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
378
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
379
);
380

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
385
$dbi->delete_all(table => $table1);
386
$dbi->insert(table => $table1, param => {$key1 => 'a:b c:d', $key2 => 2});
387
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
388
$result = $dbi->execute(
389
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
390
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
391
);
392
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
393
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
394

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
402
test 'insert';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
403
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
404
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
405
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
406
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
407
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
408
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
409
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
410

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
411
$dbi->execute("delete from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
412
$dbi->register_filter(
413
    twice       => sub { $_[0] * 2 },
414
    three_times => sub { $_[0] * 3 }
415
);
416
$dbi->default_bind_filter('twice');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
417
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => 'three_times'});
cleanup test
Yuki Kimoto authored on 2011-08-15
418
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
419
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
420
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-10
421
$dbi->default_bind_filter(undef);
422

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
423
$dbi->execute("drop table $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
424
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
425
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, append => '   ');
426
$rows = $dbi->select(table => $table1)->all;
427
is_deeply($rows, [{$key1 => 1, $key2 => 2}], 'insert append');
cleanup test
Yuki Kimoto authored on 2011-08-10
428

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
429
eval{$dbi->insert(table => $table1, noexist => 1)};
cleanup test
Yuki Kimoto authored on 2011-08-10
430
like($@, qr/noexist/, "invalid");
431

            
432
eval{$dbi->insert(table => 'table', param => {';' => 1})};
433
like($@, qr/safety/);
434

            
cleanup test
Yuki Kimoto authored on 2011-08-10
435
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
436
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
437
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
438
$dbi->insert(table => 'table', param => {select => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
439
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
440
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
441
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
cleanup test
Yuki Kimoto authored on 2011-08-10
442

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
443
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
444
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
445
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
446
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
447
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
448
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
449
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
450

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
451
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
452
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
453
$dbi->insert(table => $table1, param => {$key1 => \"'1'", $key2 => 2});
454
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
455
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
456
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
457
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
458

            
test cleanup
Yuki Kimoto authored on 2011-08-10
459
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
460
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
461
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
462
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
463
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
464
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
465
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
466
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
467
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
468
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
469
                  "basic");
470
                  
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
471
$dbi->execute("delete from $table1");
472
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
473
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
474
$dbi->update(table => $table1, param => {$key2 => 12}, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
475
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
476
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
477
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
478
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
479
                  "update key same as search key");
480

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
488
$dbi->execute("delete from $table1");
489
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
490
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
491
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
492
$dbi->update(table => $table1, param => {$key2 => 11}, where => {$key1 => 1},
493
              filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
494
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
495
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
496
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
497
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
498
                  "filter");
499

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
502
eval{$dbi->update(table => $table1, where => {$key1 => 1}, noexist => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
503
like($@, qr/noexist/, "invalid");
504

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
508
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
509
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
510
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
511
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
512
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
513
$where->param({$key1 => 1, $key2 => 2});
514
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
515
$result = $dbi->select(table => $table1);
516
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
517

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
518
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
519
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
520
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
521
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
522
    table => $table1,
523
    param => {$key1 => 3},
test cleanup
Yuki Kimoto authored on 2011-08-10
524
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
525
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
526
        {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
527
    ]
528
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
529
$result = $dbi->select(table => $table1);
530
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
531

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
532
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
533
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
534
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
535
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
536
$where->clause(['and', "$key2 = :$key2"]);
537
$where->param({$key2 => 2});
538
$dbi->update(table => $table1, param => {$key1 => 3}, where => $where);
539
$result = $dbi->select(table => $table1);
540
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
541

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
548
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
549
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
550
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
551
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
552
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
553
$dbi->insert(table => 'table', param => {select => 1});
554
$dbi->update(table => 'table', where => {select => 1}, param => {update => 2});
555
$result = $dbi->execute("select * from ${q}table$p");
556
$rows   = $result->all;
557
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
558

            
559
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
560
like($@, qr/safety/);
561

            
562
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
563
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
564
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
565
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
566
$dbi->insert(table => 'table', param => {select => 1});
567
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
568
$result = $dbi->execute("select * from ${q}table$p");
569
$rows   = $result->all;
570
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
571

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
572
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
573
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
574
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
575
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
576
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
577
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
578
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
579
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
580
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
581
                  "basic");
582

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
583
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
584
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
585
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
586
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
587
$dbi->update(table => $table1, param => {$key2 => \"'11'"}, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
588
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
589
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
590
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
591
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
592
                  "basic");
593

            
594
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
595
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
596
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
597
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
598
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
599
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
600
$dbi->update_all(table => $table1, param => {$key2 => 10}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
601
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
602
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
603
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
604
                  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
605
                  "filter");
606

            
607

            
608
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
609
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
610
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
611
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
612
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
613
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
614
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
615
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
616
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
617

            
cleanup test
Yuki Kimoto authored on 2011-08-15
618
$dbi->execute("delete from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
619
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
620
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
621
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
622
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
623
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
624
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
625
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
626

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
629
$dbi->delete_all(table => $table1);
630
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
631
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
632
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
633
$rows = $dbi->select(table => $table1)->all;
634
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
635

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

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

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

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

            
672
test 'delete error';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
673
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
674
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
675
eval{$dbi->delete(table => $table1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
676
like($@, qr/"where" must be specified/,
677
         "where key-value pairs not specified");
678

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
682
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
683
$dbi = DBIx::Custom->connect;
684
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
685
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
686
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
687
$dbi->insert(table => 'table', param => {select => 1});
688
$dbi->delete(table => 'table', where => {select => 1});
689
$result = $dbi->execute("select * from ${q}table$p");
690
$rows   = $result->all;
691
is_deeply($rows, [], "reserved word");
692

            
693
test 'delete_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
694
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
695
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
696
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
697
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
698
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
699
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
700
$rows   = $result->all;
701
is_deeply($rows, [], "basic");
702

            
703

            
704
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
705
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
706
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
707
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
708
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
709
$rows = $dbi->select(table => $table1)->all;
710
is_deeply($rows, [{$key1 => 1, $key2 => 2},
711
                  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
712

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
727
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
728
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
729
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
test cleanup
Yuki Kimoto authored on 2011-08-10
730
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
731
    table => [$table1, $table2],
732
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
733
    where   => {"$table1.$key2" => 2},
734
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
735
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
736
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
737

            
738
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
739
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
740
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
741
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
742
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
743
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
744

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
745
eval{$dbi->select(table => $table1, noexist => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
746
like($@, qr/noexist/, "invalid");
747

            
748
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
749
eval { $dbi->execute("drop table ${q}table$p") };
750
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
751
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
752
$dbi->insert(table => 'table', param => {select => 1, update => 2});
753
$result = $dbi->select(table => 'table', where => {select => 1});
754
$rows   = $result->all;
755
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
756

            
757
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
758
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
759
$dbi->register_filter(
760
    twice       => sub { $_[0] * 2 },
761
    three_times => sub { $_[0] * 3 }
762
);
763
$dbi->default_fetch_filter('twice');
764
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
765
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
766
$result = $dbi->select(table => $table1);
767
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
768
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
769
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
770

            
771
test 'filters';
772
$dbi = DBIx::Custom->new;
773

            
774
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
775
   'あ', "decode_utf8");
776

            
777
is($dbi->filters->{encode_utf8}->('あ'),
778
   encode_utf8('あ'), "encode_utf8");
779

            
cleanup test
Yuki Kimoto authored on 2011-08-10
780
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
781
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
782
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
783
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
784
$dbi->begin_work;
785
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
786
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
787
$dbi->rollback;
788
$dbi->dbh->{AutoCommit} = 1;
789

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

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

            
794
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
795
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
796
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
797
$dbi->begin_work;
798
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
799
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
800
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
801
$dbi->commit;
802
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
803
$result = $dbi->select(table => $table1);
804
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
805
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
806

            
807
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
808
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
809
$dbi->execute($create_table1);
810
{
811
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
812
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
813
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
814
    like($@, qr/\.t /, "fail : not verbose");
815
}
816
{
817
    local $Carp::Verbose = 1;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
818
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
819
    like($@, qr/Custom.*\.t /s, "fail : verbose");
820
}
821

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
822
eval{$dbi->execute('select * from $table1', no_exists => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
823
like($@, qr/wrong/, "invald SQL");
824

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

            
830
{
831
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
832
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
833
    like($@, qr/\Q.t /, "caller spec : not vebose");
834
}
835
{
836
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
837
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
838
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
839
}
840

            
841

            
cleanup test
Yuki Kimoto authored on 2011-08-10
842
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
843
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
844
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
845
$dbi->execute($create_table1);
846

            
847
$dbi->begin_work;
848

            
849
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
850
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
851
    die "Error";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
852
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
853
};
854

            
855
$dbi->rollback if $@;
856

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

            
861
$dbi->begin_work;
862

            
863
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
864
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
865
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
866
};
867

            
868
$dbi->commit unless $@;
869

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

            
874
$dbi->dbh->{AutoCommit} = 0;
875
eval{ $dbi->begin_work };
876
ok($@, "exception");
877
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
878

            
test cleanup
Yuki Kimoto authored on 2011-08-10
879
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
880
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
881
$dbi->cache(1);
882
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
883
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
884
$dbi->execute($source, {}, query => 1);
885
is_deeply($dbi->{_cached}->{$source}, 
cleanup test
Yuki Kimoto authored on 2011-08-15
886
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
887

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
888
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
889
$dbi->execute($create_table1);
890
$dbi->{_cached} = {};
891
$dbi->cache(0);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
892
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
893
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
894

            
895
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
896
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
897
$dbi->execute($create_table1);
898
{
899
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
900
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
901
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
902
    like($@, qr/\.t /, "fail : not verbose");
903
}
904
{
905
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
906
    eval{$dbi->execute('select * frm $table1')};
test cleanup
Yuki Kimoto authored on 2011-08-10
907
    like($@, qr/Custom.*\.t /s, "fail : verbose");
908
}
909

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
910
eval{$dbi->execute('select * from $table1', no_exists => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
911
like($@, qr/wrong/, "invald SQL");
912

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

            
918
{
919
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
920
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
921
    like($@, qr/\Q.t /, "caller spec : not vebose");
922
}
923
{
924
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
925
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
926
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
927
}
928

            
929
test 'method';
930
$dbi->method(
931
    one => sub { 1 }
932
);
933
$dbi->method(
934
    two => sub { 2 }
935
);
936
$dbi->method({
937
    twice => sub {
938
        my $self = shift;
939
        return $_[0] * 2;
940
    }
941
});
942

            
943
is($dbi->one, 1, "first");
944
is($dbi->two, 2, "second");
945
is($dbi->twice(5), 10 , "second");
946

            
947
eval {$dbi->XXXXXX};
948
ok($@, "not exists");
949

            
950
test 'out filter';
951
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
952
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
953
$dbi->execute($create_table1);
954
$dbi->register_filter(twice => sub { $_[0] * 2 });
955
$dbi->register_filter(three_times => sub { $_[0] * 3});
956
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
957
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
958
              $key2 => {out => 'three_times', in => 'twice'});
959
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
960
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
961
$row   = $result->fetch_hash_first;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
962
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
963
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
964
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
965
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
966

            
967
$dbi = DBIx::Custom->connect;
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);
970
$dbi->register_filter(twice => sub { $_[0] * 2 });
971
$dbi->register_filter(three_times => sub { $_[0] * 3});
972
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
973
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
974
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
975
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
976
    $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
977
); 
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
978
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
979
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
980
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
981
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
982

            
983
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
984
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
985
$dbi->execute($create_table1);
986
$dbi->register_filter(twice => sub { $_[0] * 2 });
987
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
988
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
989
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
990
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => undef});
991
$dbi->update(table => $table1, param => {$key1 => 2}, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
992
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
993
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
994
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
test cleanup
Yuki Kimoto authored on 2011-08-10
995

            
996
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
997
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
998
$dbi->execute($create_table1);
999
$dbi->register_filter(twice => sub { $_[0] * 2 });
1000
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1001
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1002
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1003
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1=> undef});
1004
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1005
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1006
$rows   = $result->all;
1007
is_deeply($rows, [], "delete");
1008

            
1009
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1010
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1011
$dbi->execute($create_table1);
1012
$dbi->register_filter(twice => sub { $_[0] * 2 });
1013
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1014
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1015
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1016
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
1017
$result = $dbi->select(table => $table1, where => {$key1 => 1});
1018
$result->filter({$key2 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1019
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1020
is_deeply($rows, [{$key1 => 4, $key2 => 4}], "select");
test cleanup
Yuki Kimoto authored on 2011-08-10
1021

            
1022
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1023
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1024
$dbi->execute($create_table1);
1025
$dbi->register_filter(twice => sub { $_[0] * 2 });
1026
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1027
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1028
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1029
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1030
$result = $dbi->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1031
                        param => {$key1 => 1, $key2 => 2},
1032
                        table => [$table1]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1033
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1034
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute");
test cleanup
Yuki Kimoto authored on 2011-08-10
1035

            
1036
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1037
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1038
$dbi->execute($create_table1);
1039
$dbi->register_filter(twice => sub { $_[0] * 2 });
1040
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1041
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1042
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1043
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1044
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1045
                        param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1046
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1047
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1048

            
1049
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1050
eval { $dbi->execute("drop table $table1") };
1051
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1052
$dbi->execute($create_table1);
1053
$dbi->execute($create_table2);
1054
$dbi->register_filter(twice => sub { $_[0] * 2 });
1055
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1056
$dbi->apply_filter(
cleanup test
Yuki Kimoto authored on 2011-08-15
1057
    $table1, $key2 => {out => 'twice', in => 'twice'}
1058
);
1059
$dbi->apply_filter(
1060
    $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1061
);
cleanup test
Yuki Kimoto authored on 2011-08-15
1062
$dbi->insert(table => $table1, param => {$key1 => 5, $key2 => 2}, filter => {$key2 => undef});
1063
$dbi->insert(table => $table2, param => {$key1 => 5, $key3 => 6}, filter => {$key3 => undef});
1064
$result = $dbi->select(
1065
     table => [$table1, $table2],
1066
     column => [$key2, $key3],
1067
     where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1068

            
1069
$result->filter({$key2 => 'twice'});
1070
$rows   = $result->all;
1071
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1072

            
1073
$result = $dbi->select(
1074
     table => [$table1, $table2],
1075
     column => [$key2, $key3],
1076
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1077

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

            
1082
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1083
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1084
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1085
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1086
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1087
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1088

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1089
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1090
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1091
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1092
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1093
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1094
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1095

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1096
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1097
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1098
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1099
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1100
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1101

            
1102
test 'end_filter';
1103
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1104
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1105
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1106
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1107
$result = $dbi->select(table => $table1);
1108
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1109
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1110
$row = $result->fetch_first;
1111
is_deeply($row, [6, 40]);
1112

            
1113
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1114
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1115
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1116
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1117
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1118
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1119
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1120
$row = $result->fetch_first;
1121
is_deeply($row, [6, 12]);
1122

            
1123
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1124
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1125
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1126
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1127
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1128
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1129
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1130
$row = $result->fetch_first;
1131
is_deeply($row, [6, 12]);
1132

            
1133
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1134
$result = $dbi->select(table => $table1);
1135
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1136
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1137
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1138
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1139

            
1140
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1141
$dbi->apply_filter($table1,
1142
    $key1 => {end => sub { $_[0] * 3 } },
1143
    $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1144
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1145
$result = $dbi->select(table => $table1);
1146
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1147
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1148
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1149

            
1150
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1151
$dbi->apply_filter($table1,
1152
    $key1 => {end => sub { $_[0] * 3 } },
1153
    $key2 => {end => 'five_times'}
1154
);
1155
$result = $dbi->select(table => $table1);
1156
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1157
$result->filter($key1 => undef);
1158
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1159
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1160
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1161

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1162
test 'remove_end_filter and remove_filter';
1163
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1164
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1165
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1166
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1167
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1168
$row = $result
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1169
       ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1170
       ->remove_filter
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1171
       ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1172
       ->remove_end_filter
1173
       ->fetch_first;
1174
is_deeply($row, [1, 2]);
1175

            
1176
test 'empty where select';
1177
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1178
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1179
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1180
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1181
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1182
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1183
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1184

            
1185
test 'select query option';
1186
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1187
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1188
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1189
$query = $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1190
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1191
$query = $dbi->update(table => $table1, where => {$key1 => 1}, param => {$key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1192
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1193
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1194
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1195
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1196
is(ref $query, 'DBIx::Custom::Query');
1197

            
1198
test 'where';
1199
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1200
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1201
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1202
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1203
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1204
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1205
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1206

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

            
1211
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1212
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1213
    where => $where
1214
);
1215
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1216
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1217

            
1218
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1219
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1220
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1221
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
1222
        {$key1 => 1}
test cleanup
Yuki Kimoto authored on 2011-08-10
1223
    ]
1224
);
1225
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1226
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1227

            
1228
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1229
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1230
             ->param({$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1231
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1232
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1233
    where => $where
1234
);
1235
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1236
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1237

            
1238
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1239
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
test cleanup
Yuki Kimoto authored on 2011-08-10
1240
             ->param({});
1241
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1242
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1243
    where => $where,
1244
);
1245
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1246
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1247

            
1248
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1249
             ->clause(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"])
1250
             ->param({$key1 => [0, 3], $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1251
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1252
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1253
    where => $where,
1254
); 
1255
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1256
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1257

            
1258
$where = $dbi->where;
1259
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1260
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1261
    where => $where
1262
);
1263
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1264
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1265

            
1266
eval {
1267
$where = $dbi->where
1268
             ->clause(['uuu']);
1269
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1270
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1271
    where => $where
1272
);
1273
};
1274
ok($@);
1275

            
1276
$where = $dbi->where;
1277
is("$where", '');
1278

            
1279
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1280
             ->clause(['or', ("$key1 = :$key1") x 2])
1281
             ->param({$key1 => [1, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1282
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1283
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1284
    where => $where,
1285
);
1286
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1287
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1288

            
1289
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1290
             ->clause(['or', ("$key1 = :$key1") x 2])
1291
             ->param({$key1 => [1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1292
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1293
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1294
    where => $where,
1295
);
1296
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1297
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1298

            
1299
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1300
             ->clause(['or', ("$key1 = :$key1") x 2])
1301
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1302
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1303
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1304
    where => $where,
1305
);
1306
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1307
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1308

            
1309
$where = $dbi->where
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1310
             ->clause("$key1 = :$key1")
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1311
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1312
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1313
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1314
    where => $where,
1315
);
1316
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1317
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1318

            
1319
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1320
             ->clause("$key1 = :$key1 $key2 = :$key2")
1321
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1322
eval{$where->to_string};
1323
like($@, qr/one column/);
1324

            
1325
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1326
             ->clause(['or', ("$key1 = :$key1") x 3])
1327
             ->param({$key1 => [$dbi->not_exists, 1, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1328
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1329
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1330
    where => $where,
1331
);
1332
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1333
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1334

            
1335
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1336
             ->clause(['or', ("$key1 = :$key1") x 3])
1337
             ->param({$key1 => [1, $dbi->not_exists, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1338
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1339
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1340
    where => $where,
1341
);
1342
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1343
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1344

            
1345
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1346
             ->clause(['or', ("$key1 = :$key1") x 3])
1347
             ->param({$key1 => [1, 3, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1348
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1349
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1350
    where => $where,
1351
);
1352
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1353
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1354

            
1355
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1356
             ->clause(['or', ("$key1 = :$key1") x 3])
1357
             ->param({$key1 => [1, $dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1358
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1359
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1360
    where => $where,
1361
);
1362
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1363
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1364

            
1365
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1366
             ->clause(['or', ("$key1 = :$key1") x 3])
1367
             ->param({$key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1368
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1369
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1370
    where => $where,
1371
);
1372
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1373
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1374

            
1375
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1376
             ->clause(['or', ("$key1 = :$key1") x 3])
1377
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1378
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1379
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1380
    where => $where,
1381
);
1382
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1383
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1384

            
1385
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1386
             ->clause(['or', ("$key1 = :$key1") x 3])
1387
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1388
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1389
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1390
    where => $where,
1391
);
1392
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1393
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1394

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

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

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

            
1425
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1426
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1427
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1428
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1429
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1430
    where => $where,
1431
);
1432
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1433
is_deeply($row, [{$key1 => 1, $key2 => 2},{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1434

            
1435
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1436
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1437
             ->param({$key1 => [0, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1438
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1439
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1440
    where => $where,
1441
);
1442
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1443
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1444

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

            
1454
eval {$dbi->where(ppp => 1) };
1455
like($@, qr/invalid/);
1456

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

            
1468

            
1469
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1470
    clause => ['and', ['or'], ['or', ":$key1", ":$key2"]],
test cleanup
Yuki Kimoto authored on 2011-08-10
1471
    param => {}
1472
);
1473
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1474
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1475
    where => $where,
1476
);
1477
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1478
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1479

            
1480
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1481
$where->clause(['and', ":${key1}{=}"]);
1482
$where->param({$key1 => undef});
1483
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1484
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1485
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1486

            
1487
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1488
$where->clause(['and', ":${key1}{=}"]);
1489
$where->param({$key1 => undef});
test cleanup
Yuki Kimoto authored on 2011-08-10
1490
$where->if('defined');
1491
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1492
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1493
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1494
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1495

            
1496
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1497
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1498
$where->param({$key1 => [undef, undef]});
1499
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1500
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1501
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1502
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1503
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1504
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1505

            
1506
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1507
$where->clause(['and', ":${key1}{=}"]);
1508
$where->param({$key1 => [undef, undef]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1509
$where->if('defined');
1510
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1511
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1512
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1513
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
1514
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1515
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1516
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1517

            
1518
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1519
$where->clause(['and', ":${key1}{=}"]);
1520
$where->param({$key1 => 0});
test cleanup
Yuki Kimoto authored on 2011-08-10
1521
$where->if('length');
1522
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1523
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1524
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1525
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1526

            
1527
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1528
$where->clause(['and', ":${key1}{=}"]);
1529
$where->param({$key1 => ''});
test cleanup
Yuki Kimoto authored on 2011-08-10
1530
$where->if('length');
1531
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1532
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1533
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1534
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1535

            
1536
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1537
$where->clause(['and', ":${key1}{=}"]);
1538
$where->param({$key1 => 5});
test cleanup
Yuki Kimoto authored on 2011-08-10
1539
$where->if(sub { ($_[0] || '') eq 5 });
1540
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1541
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1542
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1543
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1544

            
1545
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1546
$where->clause(['and', ":${key1}{=}"]);
1547
$where->param({$key1 => 7});
test cleanup
Yuki Kimoto authored on 2011-08-10
1548
$where->if(sub { ($_[0] || '') eq 5 });
1549
$where->map;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1550
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1551
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1552
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1553

            
1554
$where = $dbi->where;
1555
$where->param({id => 1, author => 'Ken', price => 1900});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1556
$where->map(id => "$table1.id",
1557
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
1558
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1559
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1560
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1561
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
1562

            
1563
$where = $dbi->where;
1564
$where->param({id => 0, author => 0, price => 0});
1565
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1566
    id => "$table1.id",
1567
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
1568
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
test cleanup
Yuki Kimoto authored on 2011-08-10
1569
      {if => sub { $_[0] eq 0 }}]
1570
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1571
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1572

            
1573
$where = $dbi->where;
1574
$where->param({id => '', author => '', price => ''});
1575
$where->if('length');
1576
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1577
    id => "$table1.id",
1578
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
1579
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
test cleanup
Yuki Kimoto authored on 2011-08-10
1580
      {if => sub { $_[0] eq 1 }}]
1581
);
1582
is_deeply($where->param, {});
1583

            
1584
$where = $dbi->where;
1585
$where->param({id => undef, author => undef, price => undef});
1586
$where->if('length');
1587
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1588
    id => "$table1.id",
1589
    price => ["$table1.price", {if => 'exists'}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1590
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1591
is_deeply($where->param, {"$table1.price" => undef});
test cleanup
Yuki Kimoto authored on 2011-08-10
1592

            
1593
$where = $dbi->where;
1594
$where->param({price => 'a'});
1595
$where->if('length');
1596
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1597
    id => ["$table1.id", {if => 'exists'}],
1598
    price => ["$table1.price", sub { '%' . $_[0] }, {if => 'exists'}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1599
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1600
is_deeply($where->param, {"$table1.price" => '%a'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1601

            
1602
$where = $dbi->where;
1603
$where->param({id => [1, 2], author => 'Ken', price => 1900});
1604
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1605
    id => "$table1.id",
1606
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
1607
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1608
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1609
is_deeply($where->param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1610
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
1611

            
1612
$where = $dbi->where;
1613
$where->if('length');
1614
$where->param({id => ['', ''], author => 'Ken', price => 1900});
1615
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1616
    id => "$table1.id",
1617
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
1618
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1619
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1620
is_deeply($where->param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1621
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
1622

            
1623
$where = $dbi->where;
1624
$where->param({id => ['', ''], author => 'Ken', price => 1900});
1625
$where->map(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1626
    id => ["$table1.id", {if => 'length'}],
1627
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, {if => 'defined'}],
1628
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
test cleanup
Yuki Kimoto authored on 2011-08-10
1629
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1630
is_deeply($where->param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1631
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
1632

            
1633
test 'register_tag_processor';
1634
$dbi = DBIx::Custom->connect;
1635
$dbi->register_tag_processor(
1636
    a => sub { 1 }
1637
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1638
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1639

            
1640
test 'register_tag';
1641
$dbi = DBIx::Custom->connect;
1642
$dbi->register_tag(
1643
    b => sub { 2 }
1644
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1645
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1646

            
1647
test 'table not specify exception';
1648
$dbi = DBIx::Custom->connect;
1649
eval {$dbi->insert};
1650
like($@, qr/table/);
1651
eval {$dbi->update};
1652
like($@, qr/table/);
1653
eval {$dbi->delete};
1654
like($@, qr/table/);
1655
eval {$dbi->select};
1656
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1657

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1658
test 'more tests';
1659
$dbi = DBIx::Custom->connect;
1660
eval{$dbi->apply_filter('table', 'column', [])};
1661
like($@, qr/apply_filter/);
1662

            
1663
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1664
like($@, qr/apply_filter/);
1665

            
1666
$dbi->apply_filter(
1667

            
1668
);
1669
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1670
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1671
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1672
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1673
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1674
$dbi->apply_filter($table1, $key2, 
test cleanup
Yuki Kimoto authored on 2011-08-10
1675
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1676
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
1677
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1678

            
1679
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1680
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1681
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1682
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1683
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1684
$dbi->apply_filter($table1, $key2, {});
1685
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1686
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1687

            
1688
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1689
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1690
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1691
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1692
like($@, qr/not registered/);
1693
$dbi->method({one => sub { 1 }});
1694
is($dbi->one, 1);
1695

            
1696
eval{DBIx::Custom->connect(dsn => undef)};
1697
like($@, qr/_connect/);
1698

            
1699
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1700
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1701
$dbi->execute($create_table1);
1702
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1703
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1704
             filter => {$key1 => 'twice'});
1705
$row = $dbi->select(table => $table1)->one;
1706
is_deeply($row, {$key1 => 2, $key2 => 2});
1707
eval {$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1708
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
1709
like($@, qr//);
1710

            
1711
$dbi->register_filter(one => sub { });
1712
$dbi->default_fetch_filter('one');
1713
ok($dbi->default_fetch_filter);
1714
$dbi->default_bind_filter('one');
1715
ok($dbi->default_bind_filter);
1716
eval{$dbi->default_fetch_filter('no')};
1717
like($@, qr/not registered/);
1718
eval{$dbi->default_bind_filter('no')};
1719
like($@, qr/not registered/);
1720
$dbi->default_bind_filter(undef);
1721
ok(!defined $dbi->default_bind_filter);
1722
$dbi->default_fetch_filter(undef);
1723
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1724
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1725
like($@, qr/Tag not finished/);
1726

            
1727
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1728
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1729
$dbi->execute($create_table1);
1730
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1731
$result = $dbi->select(table => $table1);
1732
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1733
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1734
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1735
like($@, qr/not registered/);
1736
$result->default_filter(undef);
1737
ok(!defined $result->default_filter);
1738
$result->default_filter('one');
1739
is($result->default_filter->(), 1);
1740

            
1741
test 'dbi_option';
1742
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
1743
ok($dbi->dbh->{PrintError});
1744
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
1745
ok($dbi->dbh->{PrintError});
1746

            
1747
test 'DBIx::Custom::Result stash()';
1748
$result = DBIx::Custom::Result->new;
1749
is_deeply($result->stash, {}, 'default');
1750
$result->stash->{foo} = 1;
1751
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
1752

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1753
test 'delete_at';
1754
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1755
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1756
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1757
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1758
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1759
    table => $table1,
1760
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1761
    where => [1, 2],
1762
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1763
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1764

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1765
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1766
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1767
    table => $table1,
1768
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1769
    where => 1,
1770
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1771
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1772

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

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

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

            
1800
eval {
1801
    $dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1802
        table => $table1,
1803
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1804
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1805
        param => {$key1 => 1, $key2 => 2, $key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
1806
    );
1807
};
1808
like($@, qr/must be/);
1809

            
1810
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1811
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1812
$dbi->execute($create_table1_2);
1813
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1814
    {$key3 => 3},
1815
    primary_key => [$key1, $key2], 
1816
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1817
    where => [1, 2],
1818
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1819
is($dbi->select(table => $table1)->one->{$key1}, 1);
1820
is($dbi->select(table => $table1)->one->{$key2}, 2);
1821
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1822

            
1823
test 'update_at';
1824
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1825
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1826
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1827
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1828
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1829
    table => $table1,
1830
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1831
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1832
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
1833
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1834
is($dbi->select(table => $table1)->one->{$key1}, 1);
1835
is($dbi->select(table => $table1)->one->{$key2}, 2);
1836
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1837

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1838
$dbi->delete_all(table => $table1);
1839
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1840
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1841
    table => $table1,
1842
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1843
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1844
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
1845
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1846
is($dbi->select(table => $table1)->one->{$key1}, 1);
1847
is($dbi->select(table => $table1)->one->{$key2}, 2);
1848
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1849

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

            
1864
test 'select_at';
1865
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1866
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1867
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1868
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1869
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1870
    table => $table1,
1871
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1872
    where => [1, 2]
1873
);
1874
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1875
is($row->{$key1}, 1);
1876
is($row->{$key2}, 2);
1877
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1878

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1879
$dbi->delete_all(table => $table1);
1880
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1881
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1882
    table => $table1,
1883
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1884
    where => 1,
1885
);
1886
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1887
is($row->{$key1}, 1);
1888
is($row->{$key2}, 2);
1889
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1890

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1891
$dbi->delete_all(table => $table1);
1892
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1893
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1894
    table => $table1,
1895
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1896
    where => [1, 2]
1897
);
1898
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1899
is($row->{$key1}, 1);
1900
is($row->{$key2}, 2);
1901
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1902

            
1903
eval {
1904
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1905
        table => $table1,
1906
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1907
        where => {},
1908
    );
1909
};
1910
like($@, qr/must be/);
1911

            
1912
eval {
1913
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1914
        table => $table1,
1915
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1916
        where => [1],
1917
    );
1918
};
1919
like($@, qr/same/);
1920

            
1921
eval {
1922
    $result = $dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1923
        table => $table1,
1924
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1925
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1926
        param => {$key1 => 1, $key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-10
1927
    );
1928
};
1929
like($@, qr/must be/);
1930

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

            
1940
test 'columns';
1941
use MyDBI1;
1942
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
1943
$model = $dbi->model(lc $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
1944

            
1945

            
1946
test 'model delete_at';
1947
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1948
eval { $dbi->execute("drop table $table1") };
1949
eval { $dbi->execute("drop table $table2") };
1950
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1951
$dbi->execute($create_table1_2);
1952
$dbi->execute($create_table2_2);
1953
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1954
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1955
$dbi->model($table1)->delete_at(where => [1, 2]);
1956
is_deeply($dbi->select(table => $table1)->all, []);
1957
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1958
$dbi->model($table1)->delete_at(where => [1, 2]);
1959
is_deeply($dbi->select(table => $table1)->all, []);
1960
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1961
$dbi->model($table3)->delete_at(where => [1, 2]);
1962
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1963

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

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

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

            
2004

            
2005
test 'mycolumn and column';
2006
$dbi = MyDBI7->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2007
eval { $dbi->execute("drop table $table1") };
2008
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2009
$dbi->execute($create_table1);
2010
$dbi->execute($create_table2);
2011
$dbi->separator('__');
2012
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2013
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2014
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2015
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2016
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2017
    column => [$model->mycolumn, $model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2018
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2019
);
2020
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2021
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2022

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2023
test 'insert_param';
2024
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2025
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2026
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2027
$param = {$key1 => 1, $key2 => 2};
test cleanup
Yuki Kimoto authored on 2011-08-10
2028
$insert_param = $dbi->insert_param($param);
2029
$sql = <<"EOS";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2030
insert into $table1 $insert_param
test cleanup
Yuki Kimoto authored on 2011-08-10
2031
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2032
$dbi->execute($sql, param => $param, table => $table1);
2033
is($dbi->select(table => $table1)->one->{$key1}, 1);
2034
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2035

            
2036
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2037
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2038
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2039
$param = {$key1 => 1, $key2 => 2};
test cleanup
Yuki Kimoto authored on 2011-08-10
2040
$insert_param = $dbi->insert_param($param);
2041
$sql = <<"EOS";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2042
insert into $table1 $insert_param
test cleanup
Yuki Kimoto authored on 2011-08-10
2043
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2044
$dbi->execute($sql, param => $param, table => $table1);
2045
is($dbi->select(table => $table1)->one->{$key1}, 1);
2046
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2047

            
2048
eval { $dbi->insert_param({";" => 1}) };
2049
like($@, qr/not safety/);
test cleanup
Yuki Kimoto authored on 2011-08-10
2050

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2051
test 'mycolumn';
2052
$dbi = MyDBI8->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2053
eval { $dbi->execute("drop table $table1") };
2054
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2055
$dbi->execute($create_table1);
2056
$dbi->execute($create_table2);
2057
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2058
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2059
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2060
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2061
$result = $model->select_at(
2062
    column => [
2063
        $model->mycolumn,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2064
        $model->column($table2)
cleanup test
Yuki Kimoto authored on 2011-08-10
2065
    ]
2066
);
2067
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2068
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2069

            
2070
$result = $model->select_at(
2071
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2072
        $model->mycolumn([$key1]),
2073
        $model->column($table2 => [$key1])
cleanup test
Yuki Kimoto authored on 2011-08-10
2074
    ]
2075
);
2076
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2077
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2078
$result = $model->select_at(
2079
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2080
        $model->mycolumn([$key1]),
2081
        {$table2 => [$key1]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2082
    ]
2083
);
2084
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2085
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2086

            
2087
$result = $model->select_at(
2088
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2089
        $model->mycolumn([$key1]),
2090
        ["$table2.$key1", as => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2091
    ]
2092
);
2093
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2094
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2095

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2105
test 'merge_param';
2106
$dbi = DBIx::Custom->new;
2107
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2108
    {$key1 => 1, $key2 => 2, $key3 => 3},
2109
    {$key1 => 1, $key2 => 2},
2110
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2111
];
2112
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2113
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2114

            
2115
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2116
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2117
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2118
];
2119
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2120
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
2121

            
2122
test 'select() param option';
2123
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2124
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2125
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2126
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2127
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2128
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2129
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2130
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
2131
$dbi->insert(table => $table2, param => {$key1 => 2, $key3 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-10
2132
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2133
    table => $table1,
2134
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2135
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2136
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
2137
              " as $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2138
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2139
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2140
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2141

            
2142
test 'select() string where';
2143
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2144
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2145
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2146
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2147
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2148
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2149
    table => $table1,
2150
    where => "$key1 = :$key1 and $key2 = :$key2",
2151
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2152
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2153
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2154

            
2155
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2156
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2157
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2158
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2159
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2160
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2161
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2162
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2163
        "$key1 = :$key1 and $key2 = :$key2",
2164
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2165
    ]
2166
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2167
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2168

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

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

            
2198

            
2199
test 'update() string where';
2200
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2201
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2202
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2203
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2204
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2205
    table => $table1,
2206
    param => {$key1 => 5},
2207
    where => "$key1 = :$key1 and $key2 = :$key2",
2208
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2209
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2210
$rows = $dbi->select(table => $table1)->all;
2211
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2212

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2242
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2243
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2244
    primary_key => $key1, 
2245
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2246
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2247
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2248
);
2249

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

            
2254
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2255
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2256
$dbi->execute($create_table1_2);
2257
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2258
    {$key3 => 3},
2259
    primary_key => [$key1, $key2], 
2260
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2261
    id => [1, 2],
2262
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2263
is($dbi->select(table => $table1)->one->{$key1}, 1);
2264
is($dbi->select(table => $table1)->one->{$key2}, 2);
2265
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2266

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

            
2281
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2282
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2283
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2284
$dbi->model($table1)->insert(
2285
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2286
    id => [1, 2]
2287
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2288
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2289
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2290
is($row->{$key1}, 1);
2291
is($row->{$key2}, 2);
2292
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2293

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2309
$dbi->delete_all(table => $table1);
2310
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2311
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2312
    table => $table1,
2313
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2314
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2315
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2316
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2317
is($dbi->select(table => $table1)->one->{$key1}, 0);
2318
is($dbi->select(table => $table1)->one->{$key2}, 2);
2319
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2320

            
2321
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2322
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2323
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2324
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2325
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2326
    {$key3 => 4},
2327
    table => $table1,
2328
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2329
    id => [1, 2]
2330
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2331
is($dbi->select(table => $table1)->one->{$key1}, 1);
2332
is($dbi->select(table => $table1)->one->{$key2}, 2);
2333
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2334

            
2335

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

            
2351

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2364
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2365
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2366
    table => $table1,
2367
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2368
    id => 0,
2369
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2370
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2371

            
2372

            
2373
test 'model delete and id option';
2374
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2375
eval { $dbi->execute("drop table $table1") };
2376
eval { $dbi->execute("drop table $table2") };
2377
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2378
$dbi->execute($create_table1_2);
2379
$dbi->execute($create_table2_2);
2380
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2381
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2382
$dbi->model($table1)->delete(id => [1, 2]);
2383
is_deeply($dbi->select(table => $table1)->all, []);
2384
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2385
$dbi->model($table1)->delete(id => [1, 2]);
2386
is_deeply($dbi->select(table => $table1)->all, []);
2387
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2388
$dbi->model($table3)->delete(id => [1, 2]);
2389
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2390

            
2391

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2407
$dbi->delete_all(table => $table1);
2408
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2409
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2410
    table => $table1,
2411
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2412
    id => 0,
2413
);
2414
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2415
is($row->{$key1}, 0);
2416
is($row->{$key2}, 2);
2417
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2418

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2419
$dbi->delete_all(table => $table1);
2420
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2421
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2422
    table => $table1,
2423
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2424
    id => [1, 2]
2425
);
2426
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2427
is($row->{$key1}, 1);
2428
is($row->{$key2}, 2);
2429
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2430

            
2431

            
2432
test 'model select_at';
2433
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2434
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2435
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2436
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2437
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2438
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2439
is($row->{$key1}, 1);
2440
is($row->{$key2}, 2);
2441
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2442

            
2443
test 'column separator is default .';
2444
$dbi = MyDBI7->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2445
eval { $dbi->execute("drop table $table1") };
2446
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2447
$dbi->execute($create_table1);
2448
$dbi->execute($create_table2);
2449
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2450
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2451
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2452
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2453
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2454
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2455
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2456
);
2457
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2458
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2459

            
2460
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2461
    column => [$model->column($table2 => [$key1, $key3])],
2462
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2463
);
2464
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2465
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2466

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2467
test 'separator';
2468
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2469
eval { $dbi->execute("drop table $table1") };
2470
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2471
$dbi->execute($create_table1);
2472
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2473

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2474
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2475
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2476
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2477
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2478
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2479
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2480
);
2481
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2482
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2483
);
2484
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2485
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2486
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2487
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2488
$result = $model->select(
2489
    column => [
2490
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2491
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2492
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2493
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2494
);
2495
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2496
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2497
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2498

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2499
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2500
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2501
$result = $model->select(
2502
    column => [
2503
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2504
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2505
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2506
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2507
);
2508
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2509
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
2510
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2511

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2512
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2513
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2514
$result = $model->select(
2515
    column => [
2516
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2517
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2518
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2519
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2520
);
2521
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2522
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2523
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2524

            
2525

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2533
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2534
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2535
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2536
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2537
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2538
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2539
);
2540
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2541
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2542
$model = $dbi->model($table1);
2543
$result = $model->select(column => $key1);
2544
$result->filter($key1 => sub { $_[0] * 2 });
2545
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2546

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2547
test 'available_datetype';
2548
$dbi = DBIx::Custom->connect;
2549
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2550

            
2551

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2552
test 'select prefix option';
2553
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2554
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2555
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2556
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2557
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2558
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2559

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2560
test 'map_param';
2561
$dbi = DBIx::Custom->connect;
2562
$param = $dbi->map_param(
2563
    {id => 1, author => 'Ken', price => 1900},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2564
    id => "$table1.id",
2565
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2566
    price => ["$table1.price", {if => sub { $_[0] eq 1900 }}]
cleanup test
Yuki Kimoto authored on 2011-08-10
2567
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2568
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2569
  "$table1.price" => 1900});
test cleanup
Yuki Kimoto authored on 2011-08-10
2570

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2571
$param = $dbi->map_param(
2572
    {id => 0, author => 0, price => 0},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2573
    id => "$table1.id",
2574
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2575
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
cleanup test
Yuki Kimoto authored on 2011-08-10
2576
      {if => sub { $_[0] eq 0 }}]
2577
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2578
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
test cleanup
Yuki Kimoto authored on 2011-08-10
2579

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2580
$param = $dbi->map_param(
2581
    {id => '', author => '', price => ''},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2582
    id => "$table1.id",
2583
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
2584
    price => ["$table1.price", sub { '%' . $_[0] . '%' },
cleanup test
Yuki Kimoto authored on 2011-08-10
2585
      {if => sub { $_[0] eq 1 }}]
2586
);
2587
is_deeply($param, {});
test cleanup
Yuki Kimoto authored on 2011-08-10
2588

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2589
$param = $dbi->map_param(
2590
    {id => undef, author => undef, price => undef},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2591
    id => "$table1.id",
2592
    price => ["$table1.price", {if => 'exists'}]
cleanup test
Yuki Kimoto authored on 2011-08-10
2593
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2594
is_deeply($param, {"$table1.price" => undef});
test cleanup
Yuki Kimoto authored on 2011-08-10
2595

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2596
$param = $dbi->map_param(
2597
    {price => 'a'},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2598
    id => ["$table1.id", {if => 'exists'}],
2599
    price => ["$table1.price", sub { '%' . $_[0] }, {if => 'exists'}]
cleanup test
Yuki Kimoto authored on 2011-08-10
2600
);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2601
is_deeply($param, {"$table1.price" => '%a'});
test cleanup
Yuki Kimoto authored on 2011-08-10
2602

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2603
test 'order';
2604
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2605
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2606
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2607
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2608
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
2609
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
2610
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2611
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2612
$order->prepend($key1, "$key2 desc");
2613
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2614
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
2615
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2616
$order->prepend("$key1 desc");
2617
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2618
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
2619
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2620

            
2621
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2622
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2623
$result = $dbi->select(table => $table1,
2624
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2625
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2626
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
2627
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
2628
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
2629
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2630

            
2631
test 'tag_parse';
2632
$dbi = DBIx::Custom->connect;
2633
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2634
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2635
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2636
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2637
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2638
ok($@);
2639

            
2640
test 'last_sql';
2641
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2642
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2643
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2644
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
2645
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2646

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

            
2650
test 'DBIx::Custom header';
2651
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2652
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2653
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2654
$result = $dbi->execute("select $key1 as h1, $key2 as h2 from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2655
is_deeply($result->header, [qw/h1 h2/]);
2656

            
2657
test 'Named placeholder :name(operater) syntax';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2658
$dbi->execute("drop table $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2659
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2660
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
2661
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
2662

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2678
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
2679
$result = $dbi->execute(
2680
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2681
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2682
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
2683
);
2684
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2685
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2686

            
2687
test 'high perfomance way';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2688
$dbi->execute("drop table $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2689
$dbi->execute($create_table1_highperformance);
2690
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2691
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2692
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2693
];
2694
{
2695
    my $query;
2696
    foreach my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2697
      $query ||= $dbi->insert($row, table => $table1, query => 1);
2698
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
2699
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2700
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2701
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2702
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2703
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2704
      ]
2705
    );
2706
}
2707

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2708
$dbi->execute("drop table $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2709
$dbi->execute($create_table1_highperformance);
2710
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2711
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2712
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2713
];
2714
{
2715
    my $query;
2716
    my $sth;
2717
    foreach my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2718
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2719
      $sth ||= $query->sth;
2720
      $sth->execute(map { $row->{$_} } sort keys %$row);
2721
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2722
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2723
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2724
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2725
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2726
      ]
2727
    );
2728
}
2729

            
2730
test 'result';
2731
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2732
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2733
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2734
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2735
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2736

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2737
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2738
@rows = ();
2739
while (my $row = $result->fetch) {
2740
    push @rows, [@$row];
2741
}
2742
is_deeply(\@rows, [[1, 2], [3, 4]]);
2743

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2744
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2745
@rows = ();
2746
while (my $row = $result->fetch_hash) {
2747
    push @rows, {%$row};
2748
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2749
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2750

            
2751
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2752
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2753
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2754
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2755
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2756

            
2757
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2758
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2759
$rows = $result->fetch_all;
2760
is_deeply($rows, [[1, 2], [3, 4]]);
2761

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

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

            
2770
$rows = $result->fetch_all;
2771
is_deeply($rows, [[3, 2], [9, 4]], "array");
2772

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

            
2779
test "query_builder";
2780
$datas = [
2781
    # Basic tests
2782
    {   name            => 'placeholder basic',
2783
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
2784
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
2785
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
2786
    },
2787
    {
2788
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
2789
        source            => "{in k1 3}",
2790
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
2791
        columns_expected   => [qw/k1 k1 k1/]
2792
    },
2793
    
2794
    # Table name
2795
    {
2796
        name            => 'placeholder with table name',
2797
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
2798
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
2799
        columns_expected  => [qw/a.k1 a.k2/]
2800
    },
2801
    {   
2802
        name            => 'placeholder in with table name',
2803
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
2804
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
2805
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
2806
    },
2807
    {
2808
        name            => 'not contain tag',
2809
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
2810
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
2811
        columns_expected  => [],
2812
    }
2813
];
2814

            
2815
for (my $i = 0; $i < @$datas; $i++) {
2816
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
2817
    my $dbi = DBIx::Custom->new;
2818
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
2819
    my $query = $builder->build_query($data->{source});
2820
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
2821
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
2822
}
2823

            
cleanup
Yuki Kimoto authored on 2011-08-13
2824
$dbi = DBIx::Custom->new;
2825
$builder = $dbi->query_builder;
2826
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
2827
    p => sub {
2828
        my @args = @_;
2829
        
2830
        my $expand    = "? $args[0] $args[1]";
2831
        my $columns = [2];
2832
        return [$expand, $columns];
2833
    }
2834
);
2835

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
2846
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
2847
    q => 'string'
2848
});
2849

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
2853
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
2854
   r => sub {} 
2855
});
2856

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
2860
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
2861
   s => sub { return ["a", ""]} 
2862
});
2863

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
2867
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
2868
    t => sub {return ["a", []]}
2869
);
2870

            
2871

            
cleanup
Yuki Kimoto authored on 2011-08-13
2872
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
2873
    a => sub {
2874
        return ["? ? ?", ['']];
2875
    }
2876
);
2877
eval{$builder->build_query("{a}")};
2878
like($@, qr/\QPlaceholder count/, "placeholder count is invalid");
2879

            
2880

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

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

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

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

            
2896
test 'variouse source';
2897
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
2898
$query = $builder->build_query($source);
2899
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
2900

            
2901
$source = "abc";
2902
$query = $builder->build_query($source);
2903
is($query->sql, 'abc', "basic : 2");
2904

            
2905
$source = "{= a}";
2906
$query = $builder->build_query($source);
2907
is($query->sql, 'a = ?', "only tag");
2908

            
2909
$source = "000";
2910
$query = $builder->build_query($source);
2911
is($query->sql, '000', "contain 0 value");
2912

            
2913
$source = "a {= b} }";
2914
eval{$builder->build_query($source)};
2915
like($@, qr/unexpected "}"/, "error : 1");
2916

            
2917
$source = "a {= {}";
2918
eval{$builder->build_query($source)};
2919
like($@, qr/unexpected "{"/, "error : 2");
2920

            
2921
test 'select() wrap option';
2922
$dbi = DBIx::Custom->connect;
2923
eval { $dbi->execute("drop table $table1") };
2924
$dbi->execute($create_table1);
2925
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2926
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
2927
$rows = $dbi->select(
2928
    table => $table1,
2929
    column => $key1,
2930
    wrap => ["select * from (", ") as t where $key1 = 1"]
2931
)->all;
2932
is_deeply($rows, [{$key1 => 1}]);
2933

            
2934
eval {
2935
$dbi->select(
2936
    table => $table1,
2937
    column => $key1,
2938
    wrap => 'select * from ('
2939
)
2940
};
2941
like($@, qr/array/);
2942

            
2943
test 'select() sqlfilter option';
2944
$dbi = DBIx::Custom->connect;
2945
eval { $dbi->execute("drop table $table1") };
2946
$dbi->execute($create_table1);
2947
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2948
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
2949
$rows = $dbi->select(
2950
    table => $table1,
2951
    column => $key1,
2952
    sqlfilter => sub {
2953
        my $sql = shift;
2954
        $sql = "select * from ( $sql ) as t where $key1 = 1";
2955
        return $sql;
2956
    }
2957
)->all;
2958
is_deeply($rows, [{$key1 => 1}]);
2959

            
2960
test 'dbi method from model';
2961
$dbi = MyDBI9->connect;
2962
eval { $dbi->execute("drop table $table1") };
2963
$dbi->execute($create_table1);
2964
$dbi->setup_model;
2965
$model = $dbi->model($table1);
2966
eval{$model->execute("select * from $table1")};
2967
ok(!$@);
2968

            
2969
test 'column table option';
2970
$dbi = MyDBI9->connect;
2971
eval { $dbi->execute("drop table $table1") };
2972
$dbi->execute($create_table1);
2973
eval { $dbi->execute("drop table $table2") };
2974
$dbi->execute($create_table2);
2975
$dbi->setup_model;
2976
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
2977
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
2978
$model = $dbi->model($table1);
2979
$result = $model->select(
2980
    column => [
2981
        $model->column($table2, {alias => $table2_alias})
2982
    ],
2983
    where => {"$table2_alias.$key3" => 4}
2984
);
2985
is_deeply($result->one, 
2986
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
2987

            
2988
$dbi->separator('__');
2989
$result = $model->select(
2990
    column => [
2991
        $model->column($table2, {alias => $table2_alias})
2992
    ],
2993
    where => {"$table2_alias.$key3" => 4}
2994
);
2995
is_deeply($result->one, 
2996
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
2997

            
2998
$dbi->separator('-');
2999
$result = $model->select(
3000
    column => [
3001
        $model->column($table2, {alias => $table2_alias})
3002
    ],
3003
    where => {"$table2_alias.$key3" => 4}
3004
);
3005
is_deeply($result->one, 
3006
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3007

            
3008
test 'create_model';
3009
$dbi = DBIx::Custom->connect;
3010
eval { $dbi->execute("drop table $table1") };
3011
eval { $dbi->execute("drop table $table2") };
3012
$dbi->execute($create_table1);
3013
$dbi->execute($create_table2);
3014

            
3015
$dbi->create_model(
3016
    table => $table1,
3017
    join => [
3018
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3019
    ],
3020
    primary_key => [$key1]
3021
);
3022
$model2 = $dbi->create_model(
3023
    table => $table2
3024
);
3025
$dbi->create_model(
3026
    table => $table3,
3027
    filter => [
3028
        $key1 => {in => sub { uc $_[0] }}
3029
    ]
3030
);
3031
$dbi->setup_model;
3032
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3033
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3034
$model = $dbi->model($table1);
3035
$result = $model->select(
3036
    column => [$model->mycolumn, $model->column($table2)],
3037
    where => {"$table1.$key1" => 1}
3038
);
3039
is_deeply($result->one,
3040
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3041
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3042

            
3043
test 'model method';
3044
$dbi = DBIx::Custom->connect;
3045
eval { $dbi->execute("drop table $table2") };
3046
$dbi->execute($create_table2);
3047
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3048
$model = $dbi->create_model(
3049
    table => $table2
3050
);
3051
$model->method(foo => sub { shift->select(@_) });
3052
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
3053

            
3054
test 'update_param';
3055
$dbi = DBIx::Custom->connect;
3056
eval { $dbi->execute("drop table $table1") };
3057
$dbi->execute($create_table1_2);
3058
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3059
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3060

            
3061
$param = {$key2 => 11};
3062
$update_param = $dbi->update_param($param);
3063
$sql = <<"EOS";
3064
update $table1 $update_param
3065
where $key1 = 1
3066
EOS
3067
$dbi->execute($sql, param => $param);
3068
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3069
$rows   = $result->all;
3070
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3071
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3072
                  "basic");
3073

            
3074

            
3075
$dbi = DBIx::Custom->connect;
3076
eval { $dbi->execute("drop table $table1") };
3077
$dbi->execute($create_table1_2);
3078
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3079
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3080

            
3081
$param = {$key2 => 11, $key3 => 33};
3082
$update_param = $dbi->update_param($param);
3083
$sql = <<"EOS";
3084
update $table1 $update_param
3085
where $key1 = 1
3086
EOS
3087
$dbi->execute($sql, param => $param);
3088
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3089
$rows   = $result->all;
3090
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3091
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3092
                  "basic");
3093

            
3094
$dbi = DBIx::Custom->connect;
3095
eval { $dbi->execute("drop table $table1") };
3096
$dbi->execute($create_table1_2);
3097
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3098
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3099

            
3100
$param = {$key2 => 11, $key3 => 33};
3101
$update_param = $dbi->update_param($param, {no_set => 1});
3102
$sql = <<"EOS";
3103
update $table1 set $update_param
3104
where $key1 = 1
3105
EOS
3106
$dbi->execute($sql, param => $param);
3107
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3108
$rows   = $result->all;
3109
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3110
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3111
                  "update param no_set");
3112

            
3113
            
3114
eval { $dbi->update_param({";" => 1}) };
3115
like($@, qr/not safety/);
3116

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3118
test 'update_param';
3119
$dbi = DBIx::Custom->connect;
3120
eval { $dbi->execute("drop table $table1") };
3121
$dbi->execute($create_table1_2);
3122
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3123
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3124

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3125
$param = {$key2 => 11};
3126
$update_param = $dbi->assign_param($param);
3127
$sql = <<"EOS";
3128
update $table1 set $update_param
3129
where $key1 = 1
3130
EOS
3131
$dbi->execute($sql, param => $param, table => $table1);
3132
$result = $dbi->execute("select * from $table1 order by $key1");
3133
$rows   = $result->all;
3134
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3135
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3136
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3137

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3138
test 'join';
3139
$dbi = DBIx::Custom->connect;
3140
eval { $dbi->execute("drop table $table1") };
3141
$dbi->execute($create_table1);
3142
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3143
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
3144
eval { $dbi->execute("drop table $table2") };
3145
$dbi->execute($create_table2);
3146
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3147
eval { $dbi->execute("drop table $table3") };
3148
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
3149
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
3150
$rows = $dbi->select(
3151
    table => $table1,
3152
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3153
    where   => {"$table1.$key2" => 2},
3154
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
3155
)->all;
3156
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3157

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3158
$rows = $dbi->select(
3159
    table => $table1,
3160
    where   => {$key1 => 1},
3161
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
3162
)->all;
3163
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3164

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3165
eval {
3166
    $rows = $dbi->select(
3167
        table => $table1,
3168
        column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
3169
        where   => {"$table1.$key2" => 2},
3170
        join  => {"$table1.$key1" => "$table2.$key1"}
3171
    );
3172
};
3173
like ($@, qr/array/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3174

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3175
$rows = $dbi->select(
3176
    table => $table1,
3177
    where   => {$key1 => 1},
3178
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3179
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
3180
)->all;
3181
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3182

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3183
$rows = $dbi->select(
3184
    column => "$table3.$key4 as ${table3}__$key4",
3185
    table => $table1,
3186
    where   => {"$table1.$key1" => 1},
3187
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3188
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
3189
)->all;
3190
is_deeply($rows, [{"${table3}__$key4" => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3191

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3192
$rows = $dbi->select(
3193
    column => "$table1.$key1 as ${table1}__$key1",
3194
    table => $table1,
3195
    where   => {"$table3.$key4" => 4},
3196
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
3197
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
3198
)->all;
3199
is_deeply($rows, [{"${table1}__$key1" => 1}]);
3200

            
3201
$dbi = DBIx::Custom->connect;
3202
eval { $dbi->execute("drop table $table1") };
3203
$dbi->execute($create_table1);
3204
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3205
eval { $dbi->execute("drop table $table2") };
3206
$dbi->execute($create_table2);
3207
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3208
$rows = $dbi->select(
3209
    table => $table1,
3210
    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",
3211
    where   => {"$table1.$key2" => 2},
3212
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
3213
)->all;
3214
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
3215
          'quote');
test cleanup
Yuki Kimoto authored on 2011-08-10
3216

            
3217

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3218
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3219
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3220
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3221
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
3222
$sql = <<"EOS";
3223
left outer join (
3224
  select * from $table1 as t1
3225
  where t1.$key2 = (
3226
    select max(t2.$key2) from $table1 as t2
3227
    where t1.$key1 = t2.$key1
3228
  )
3229
) as latest_$table1 on $table1.$key1 = latest_$table1.$key1
3230
EOS
3231
$join = [$sql];
cleanup test
Yuki Kimoto authored on 2011-08-10
3232
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3233
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-15
3234
    column => "latest_$table1.$key1 as latest_${table1}__$key1",
3235
    join  => $join
cleanup test
Yuki Kimoto authored on 2011-08-10
3236
)->all;
cleanup test
Yuki Kimoto authored on 2011-08-15
3237
is_deeply($rows, [{"latest_${table1}__$key1" => 1}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3238

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3239
$dbi = DBIx::Custom->connect;
3240
eval { $dbi->execute("drop table $table1") };
3241
eval { $dbi->execute("drop table $table2") };
3242
$dbi->execute($create_table1);
3243
$dbi->execute($create_table2);
3244
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3245
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
3246
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3247
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3248
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-15
3249
    join => [
3250
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
3251
    ]
3252
);
3253
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
3254
$result = $dbi->select(
3255
    table => $table1,
3256
    column => [{$table2 => [$key3]}],
3257
    join => [
3258
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
3259
    ]
3260
);
3261
is_deeply($result->all, [{"$table2.$key3" => 4}]);
3262
$result = $dbi->select(
3263
    table => $table1,
3264
    column => [{$table2 => [$key3]}],
3265
    join => [
3266
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
3267
    ]
3268
);
3269
is_deeply($result->all, [{"$table2.$key3" => 4}]);
3270

            
3271
$dbi = DBIx::Custom->connect;
3272
eval { $dbi->execute("drop table $table1") };
3273
eval { $dbi->execute("drop table $table2") };
3274
$dbi->execute($create_table1);
3275
$dbi->execute($create_table2);
3276
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3277
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
3278
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
3279
$result = $dbi->select(
3280
    table => $table1,
3281
    column => [{$table2 => [$key3]}],
3282
    join => [
3283
        {
3284
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
3285
            table => [$table1, $table2]
3286
        }
3287
    ]
3288
);
3289
is_deeply($result->all, [{"$table2.$key3" => 4}]);
3290

            
3291
test 'Model class';
3292
use MyDBI1;
3293
$dbi = MyDBI1->connect;
3294
eval { $dbi->execute("drop table $table1") };
3295
$dbi->execute($create_table1);
3296
$model = $dbi->model($table1);
3297
$model->insert({$key1 => 'a', $key2 => 'b'});
3298
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3299
eval { $dbi->execute("drop table $table2") };
3300
$dbi->execute($create_table2);
3301
$model = $dbi->model($table2);
3302
$model->insert({$key1 => 'a'});
3303
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3304
is($dbi->models->{$table1}, $dbi->model($table1));
3305
is($dbi->models->{$table2}, $dbi->model($table2));
3306

            
3307
$dbi = MyDBI4->connect;
3308
eval { $dbi->execute("drop table $table1") };
3309
$dbi->execute($create_table1);
3310
$model = $dbi->model($table1);
3311
$model->insert({$key1 => 'a', $key2 => 'b'});
3312
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3313
eval { $dbi->execute("drop table $table2") };
3314
$dbi->execute($create_table2);
3315
$model = $dbi->model($table2);
3316
$model->insert({$key1 => 'a'});
3317
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3318

            
3319
$dbi = MyDBI5->connect;
3320
eval { $dbi->execute("drop table $table1") };
3321
eval { $dbi->execute("drop table $table2") };
3322
$dbi->execute($create_table1);
3323
$dbi->execute($create_table2);
3324
$model = $dbi->model($table2);
3325
$model->insert({$key1 => 'a'});
3326
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3327
$dbi->insert(table => $table1, param => {$key1 => 1});
3328
$model = $dbi->model($table1);
3329
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3330

            
3331
test 'primary_key';
3332
use MyDBI1;
3333
$dbi = MyDBI1->connect;
3334
$model = $dbi->model($table1);
3335
$model->primary_key([$key1, $key2]);
3336
is_deeply($model->primary_key, [$key1, $key2]);
3337

            
3338
test 'columns';
3339
use MyDBI1;
3340
$dbi = MyDBI1->connect;
3341
$model = $dbi->model($table1);
3342
$model->columns([$key1, $key2]);
3343
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3344

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3345
test 'setup_model';
3346
use MyDBI1;
3347
$dbi = MyDBI1->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3348
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3349
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3350

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3351
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3352
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3353
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3354
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3355
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3356

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3357
test 'each_column';
3358
$dbi = DBIx::Custom->connect;
3359
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3360
eval { $dbi->execute("drop table $table1") };
3361
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3362
eval { $dbi->execute("drop table $table3") };
3363
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3364
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3365

            
3366
$infos = [];
3367
$dbi->each_column(sub {
3368
    my ($self, $table, $column, $cinfo) = @_;
3369
    
3370
    if ($table =~ /^table\d/i) {
3371
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3372
         push @$infos, $info;
3373
    }
3374
});
3375
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3376
$DB::single = 1;
3377
is_deeply($infos, 
3378
    [
3379
        [$table1, $key1, $key1],
3380
        [$table1, $key2, $key2],
3381
        [$table2, $key1, $key1],
3382
        [$table2, $key3, $key3]
3383
    ]
3384
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3385
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3386
test 'each_table';
3387
$dbi = DBIx::Custom->connect;
3388
eval { $dbi->execute("drop table $table1") };
3389
eval { $dbi->execute("drop table $table2") };
3390
$dbi->execute($create_table2);
3391
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3392

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3393
$infos = [];
3394
$dbi->each_table(sub {
3395
    my ($self, $table, $table_info) = @_;
3396
    
3397
    if ($table =~ /^table\d/i) {
3398
         my $info = [$table, $table_info->{TABLE_NAME}];
3399
         push @$infos, $info;
3400
    }
3401
});
3402
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3403
is_deeply($infos, 
3404
    [
3405
        [$table1, $table1],
3406
        [$table2, $table2],
3407
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3408
);
3409

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3410
test 'type_rule into';
3411
eval { $dbi->execute("drop table $table1") };
3412
$dbi->execute($create_table1_type);
3413
$dbi = DBIx::Custom->connect;
3414
eval { $dbi->execute("drop table $table1") };
3415
$dbi->execute($create_table1_type);
3416

            
3417
$dbi->type_rule(
3418
    into1 => {
3419
        $date_typename => sub { '2010-' . $_[0] }
3420
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3421
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3422
$dbi->insert({$key1 => '01-01'}, table => $table1);
3423
$result = $dbi->select(table => $table1);
3424
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3425

            
3426
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3427
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3428
$dbi->execute($create_table1_type);
3429
$dbi->type_rule(
3430
    into1 => [
3431
         [$date_typename, $datetime_typename] => sub {
3432
            my $value = shift;
3433
            $value =~ s/02/03/g;
3434
            return $value;
3435
         }
3436
    ]
3437
);
3438
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3439
$result = $dbi->select(table => $table1);
3440
$row = $result->one;
3441
like($row->{$key1}, qr/^2010-01-03/);
3442
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3443

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3444
$dbi = DBIx::Custom->connect;
3445
eval { $dbi->execute("drop table $table1") };
3446
$dbi->execute($create_table1_type);
3447
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3448
$dbi->type_rule(
3449
    into1 => [
3450
        [$date_typename, $datetime_typename] => sub {
3451
            my $value = shift;
3452
            $value =~ s/02/03/g;
3453
            return $value;
3454
        }
3455
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3456
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3457
$result = $dbi->execute(
3458
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3459
    param => {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
3460
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3461
$row = $result->one;
3462
like($row->{$key1}, qr/^2010-01-03/);
3463
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3464

            
3465
$dbi = DBIx::Custom->connect;
3466
eval { $dbi->execute("drop table $table1") };
3467
$dbi->execute($create_table1_type);
3468
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3469
$dbi->type_rule(
3470
    into1 => [
3471
        [$date_typename, $datetime_typename] => sub {
3472
            my $value = shift;
3473
            $value =~ s/02/03/g;
3474
            return $value;
3475
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3476
    ]
3477
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3478
$result = $dbi->execute(
3479
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3480
    param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
3481
    table => $table1
3482
);
3483
$row = $result->one;
3484
like($row->{$key1}, qr/^2010-01-03/);
3485
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3486

            
3487
$dbi = DBIx::Custom->connect;
3488
eval { $dbi->execute("drop table $table1") };
3489
$dbi->execute($create_table1_type);
3490
$dbi->register_filter(convert => sub {
3491
    my $value = shift || '';
3492
    $value =~ s/02/03/;
3493
    return $value;
3494
});
3495
$dbi->type_rule(
3496
    from1 => {
3497
        $date_datatype => 'convert',
3498
    },
3499
    into1 => {
3500
        $date_typename => 'convert',
3501
    }
3502
);
3503
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3504
$result = $dbi->select(table => $table1);
3505
like($result->fetch->[0], qr/^2010-03-03/);
3506

            
3507
test 'type_rule and filter order';
3508
$dbi = DBIx::Custom->connect;
3509
eval { $dbi->execute("drop table $table1") };
3510
$dbi->execute($create_table1_type);
3511
$dbi->type_rule(
3512
    into1 => {
3513
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3514
    },
3515
    into2 => {
3516
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3517
    },
3518
    from1 => {
3519
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3520
    },
3521
    from2 => {
3522
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
3523
    }
3524
);
3525
$dbi->insert({$key1 => '2010-01-03'}, 
3526
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
3527
$result = $dbi->select(table => $table1);
3528
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3529
like($result->fetch_first->[0], qr/^2010-01-09/);
3530

            
3531

            
3532
$dbi = DBIx::Custom->connect;
3533
eval { $dbi->execute("drop table $table1") };
3534
$dbi->execute($create_table1_type);
3535
$dbi->type_rule(
3536
    from1 => {
3537
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3538
    },
3539
    from2 => {
3540
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3541
    },
3542
);
3543
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3544
$result = $dbi->select(table => $table1);
3545
$result->type_rule(
3546
    from1 => {
3547
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3548
    },
3549
    from2 => {
3550
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3551
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3552
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3553
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3554
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3555

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3556
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
3557
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
3558
eval { $dbi->execute("drop table $table1") };
3559
$dbi->execute($create_table1_type);
3560
$dbi->type_rule(
3561
    from1 => {
3562
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3563
    },
3564
    into1 => {
3565
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3566
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3567
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3568
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3569
$result = $dbi->select(table => $table1, type_rule_off => 1);
3570
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3571

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3572
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3573
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3574
$dbi->execute($create_table1_type);
3575
$dbi->type_rule(
3576
    from1 => {
3577
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3578
    },
3579
    into1 => {
3580
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3581
    }
3582
);
3583
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3584
$result = $dbi->select(table => $table1, type_rule_off => 1);
3585
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3586

            
3587
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3588
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3589
$dbi->execute($create_table1_type);
3590
$dbi->type_rule(
3591
    from1 => {
3592
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3593
    },
3594
    into1 => {
3595
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3596
    }
3597
);
3598
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3599
$result = $dbi->select(table => $table1);
3600
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3601

            
3602
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3603
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3604
$dbi->execute($create_table1_type);
3605
$dbi->type_rule(
3606
    from1 => {
3607
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3608
    },
3609
    into1 => {
3610
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3611
    }
3612
);
3613
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3614
$result = $dbi->select(table => $table1);
3615
like($result->fetch->[0], qr/2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3616

            
3617
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3618
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3619
$dbi->execute($create_table1_type);
3620
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
3621
$dbi->type_rule(
3622
    into1 => {
3623
        $date_typename => 'ppp'
3624
    }
3625
);
3626
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3627
$result = $dbi->select(table => $table1);
3628
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3629

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3630
eval{$dbi->type_rule(
3631
    into1 => {
3632
        $date_typename => 'pp'
3633
    }
3634
)};
3635
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3636

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3637
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3638
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3639
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3640
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3641
    $dbi->type_rule(
3642
        from1 => {
3643
            Date => sub { $_[0] * 2 },
3644
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3645
    );
3646
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3647
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3648

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3649
eval {
3650
    $dbi->type_rule(
3651
        into1 => {
3652
            Date => sub { $_[0] * 2 },
3653
        }
3654
    );
3655
};
3656
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3657

            
3658
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3659
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3660
$dbi->execute($create_table1_type);
3661
$dbi->type_rule(
3662
    from1 => {
3663
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3664
    },
3665
    into1 => {
3666
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3667
    }
3668
);
3669
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3670
$result = $dbi->select(table => $table1);
3671
$result->type_rule_off;
3672
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3673

            
3674
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3675
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3676
$dbi->execute($create_table1_type);
3677
$dbi->type_rule(
3678
    from1 => {
3679
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3680
        $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3681
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3682
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3683
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
3684
$result = $dbi->select(table => $table1);
3685
$result->type_rule(
3686
    from1 => {
3687
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3688
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3689
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3690
$row = $result->one;
3691
like($row->{$key1}, qr/^2010-01-05/);
3692
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3693

            
3694
$result = $dbi->select(table => $table1);
3695
$result->type_rule(
3696
    from1 => {
3697
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3698
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3699
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3700
$row = $result->one;
3701
like($row->{$key1}, qr/2010-01-05/);
3702
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3703

            
3704
$result = $dbi->select(table => $table1);
3705
$result->type_rule(
3706
    from1 => {
3707
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3708
    }
3709
);
3710
$row = $result->one;
3711
like($row->{$key1}, qr/2010-01-05/);
3712
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3713

            
3714
$result = $dbi->select(table => $table1);
3715
$result->type_rule(
3716
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
3717
);
3718
$row = $result->one;
3719
like($row->{$key1}, qr/2010-01-05/);
3720
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3721

            
3722
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
3723
$result = $dbi->select(table => $table1);
3724
$result->type_rule(
3725
    from1 => [$date_datatype => 'five']
3726
);
3727
$row = $result->one;
3728
like($row->{$key1}, qr/^2010-01-05/);
3729
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3730

            
3731
$result = $dbi->select(table => $table1);
3732
$result->type_rule(
3733
    from1 => [$date_datatype => undef]
3734
);
3735
$row = $result->one;
3736
like($row->{$key1}, qr/^2010-01-03/);
3737
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3738

            
3739
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3740
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3741
$dbi->execute($create_table1_type);
3742
$dbi->type_rule(
3743
    from1 => {
3744
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
3745
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
3746
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3747
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3748
$result = $dbi->select(table => $table1);
3749
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3750
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3751

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3752
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3753
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3754
$dbi->execute($create_table1_type);
3755
$dbi->type_rule(
3756
    from1 => {
3757
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3758
    },
3759
);
3760
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3761
$result = $dbi->select(table => $table1);
3762
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3763
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3764

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3765
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3766
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3767
$dbi->execute($create_table1_type);
3768
$dbi->type_rule(
3769
    into1 => {
3770
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3771
    },
3772
    into2 => {
3773
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3774
    },
3775
    from1 => {
3776
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3777
    },
3778
    from2 => {
3779
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
3780
    }
3781
);
3782
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3783
$result = $dbi->select(table => $table1);
3784
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/);
3785
$result = $dbi->select(table => $table1);
3786
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3787

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3811
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3812
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3813
$dbi->execute($create_table1_type);
3814
$dbi->type_rule(
3815
    into1 => {
3816
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3817
    },
3818
    into2 => {
3819
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3820
    },
3821
    from1 => {
3822
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3823
    },
3824
    from2 => {
3825
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
3826
    }
3827
);
3828
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
3829
$result = $dbi->select(table => $table1);
3830
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
3831
$result = $dbi->select(table => $table1);
3832
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
3833

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

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