DBIx-Custom / t / common.t /
Newer Older
4241 lines | 142.524kb
added common test executing ...
Yuki Kimoto authored on 2011-08-07
1
use Test::More;
2
use strict;
3
use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
4
use Encode qw/encode_utf8/;
cleanup test
Yuki Kimoto authored on 2011-08-10
5
use FindBin;
cleanup
Yuki Kimoto authored on 2011-08-13
6
use Scalar::Util 'isweak';
cleanup test
Yuki Kimoto authored on 2011-08-10
7

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

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

            
14
plan 'no_plan';
15

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
16
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
finished oracle test
Yuki Kimoto authored on 2011-08-15
17
sub test { print "# $_[0]\n" }
18

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

            
49
# Variables
50
my $builder;
51
my $datas;
52
my $sth;
53
my $source;
54
my @sources;
55
my $select_source;
56
my $insert_source;
57
my $update_source;
58
my $param;
59
my $params;
60
my $sql;
61
my $result;
62
my $row;
63
my @rows;
64
my $rows;
65
my $query;
66
my @queries;
67
my $select_query;
68
my $insert_query;
69
my $update_query;
70
my $ret_val;
71
my $infos;
72
my $model;
73
my $model2;
74
my $where;
75
my $update_param;
76
my $insert_param;
77
my $join;
78
my $binary;
added test
Yuki Kimoto authored on 2011-08-16
79
my $user_table_info;
cleanup
Yuki Kimoto authored on 2011-08-16
80
my $user_column_info;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
81
my $values_clause;
82
my $assign_clause;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
83
my $reuse;
cleanup test
Yuki Kimoto authored on 2011-08-15
84

            
test cleanup
Yuki Kimoto authored on 2011-08-15
85
require MyDBI1;
test cleanup
Yuki Kimoto authored on 2011-08-10
86
{
87
    package MyDBI4;
88

            
89
    use strict;
90
    use warnings;
91

            
92
    use base 'DBIx::Custom';
93

            
94
    sub connect {
95
        my $self = shift->SUPER::connect(@_);
96
        
97
        $self->include_model(
98
            MyModel2 => [
cleanup test
Yuki Kimoto authored on 2011-08-15
99
                $table1,
100
                {class => $table2, name => $table2}
test cleanup
Yuki Kimoto authored on 2011-08-10
101
            ]
102
        );
103
    }
104

            
105
    package MyModel2::Base1;
106

            
107
    use strict;
108
    use warnings;
109

            
110
    use base 'DBIx::Custom::Model';
111

            
test cleanup
Yuki Kimoto authored on 2011-08-10
112
    package MyModel2::table1;
test cleanup
Yuki Kimoto authored on 2011-08-10
113

            
114
    use strict;
115
    use warnings;
116

            
117
    use base 'MyModel2::Base1';
118

            
119
    sub insert {
120
        my ($self, $param) = @_;
121
        
cleanup
Yuki Kimoto authored on 2011-10-21
122
        return $self->SUPER::insert($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
123
    }
124

            
125
    sub list { shift->select; }
126

            
test cleanup
Yuki Kimoto authored on 2011-08-10
127
    package MyModel2::table2;
test cleanup
Yuki Kimoto authored on 2011-08-10
128

            
129
    use strict;
130
    use warnings;
131

            
132
    use base 'MyModel2::Base1';
133

            
134
    sub insert {
135
        my ($self, $param) = @_;
136
        
cleanup
Yuki Kimoto authored on 2011-10-21
137
        return $self->SUPER::insert($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
138
    }
139

            
140
    sub list { shift->select; }
test cleanup
Yuki Kimoto authored on 2011-08-15
141

            
142
    package MyModel2::TABLE1;
143

            
144
    use strict;
145
    use warnings;
146

            
147
    use base 'MyModel2::Base1';
148

            
149
    sub insert {
150
        my ($self, $param) = @_;
151
        
cleanup
Yuki Kimoto authored on 2011-10-21
152
        return $self->SUPER::insert($param);
test cleanup
Yuki Kimoto authored on 2011-08-15
153
    }
154

            
155
    sub list { shift->select; }
156

            
157
    package MyModel2::TABLE2;
158

            
159
    use strict;
160
    use warnings;
161

            
162
    use base 'MyModel2::Base1';
163

            
164
    sub insert {
165
        my ($self, $param) = @_;
166
        
cleanup
Yuki Kimoto authored on 2011-10-21
167
        return $self->SUPER::insert($param);
test cleanup
Yuki Kimoto authored on 2011-08-15
168
    }
169

            
170
    sub list { shift->select; }
test cleanup
Yuki Kimoto authored on 2011-08-10
171
}
172
{
173
     package MyDBI5;
174

            
175
    use strict;
176
    use warnings;
177

            
178
    use base 'DBIx::Custom';
179

            
180
    sub connect {
181
        my $self = shift->SUPER::connect(@_);
182
        
183
        $self->include_model('MyModel4');
184
    }
185
}
186
{
187
    package MyDBI6;
188
    
189
    use base 'DBIx::Custom';
190
    
191
    sub connect {
192
        my $self = shift->SUPER::connect(@_);
193
        
194
        $self->include_model('MyModel5');
195
        
196
        return $self;
197
    }
198
}
199
{
200
    package MyDBI7;
201
    
202
    use base 'DBIx::Custom';
203
    
204
    sub connect {
205
        my $self = shift->SUPER::connect(@_);
206
        
207
        $self->include_model('MyModel6');
208
        
209
        
210
        return $self;
211
    }
212
}
213
{
214
    package MyDBI8;
215
    
216
    use base 'DBIx::Custom';
217
    
218
    sub connect {
219
        my $self = shift->SUPER::connect(@_);
220
        
221
        $self->include_model('MyModel7');
222
        
223
        return $self;
224
    }
225
}
226

            
227
{
228
    package MyDBI9;
229
    
230
    use base 'DBIx::Custom';
231
    
232
    sub connect {
233
        my $self = shift->SUPER::connect(@_);
234
        
cleanup test
Yuki Kimoto authored on 2011-08-10
235
        $self->include_model('MyModel8');
test cleanup
Yuki Kimoto authored on 2011-08-10
236
        
237
        return $self;
238
    }
239
}
240

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
241
test 'execute reuse option';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
242
eval { $dbi->execute("drop table $table1") };
243
$dbi->execute($create_table1);
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
244
$reuse = {};
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
245
for my $i (1 .. 2) {
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
246
  $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, reuse => $reuse);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
247
}
248
$rows = $dbi->select(table => $table1)->all;
249
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 1, $key2 => 2}]);
250

            
added test
Yuki Kimoto authored on 2011-08-16
251
# Get user table info
252
$dbi = DBIx::Custom->connect;
253
eval { $dbi->execute("drop table $table1") };
254
eval { $dbi->execute("drop table $table2") };
255
eval { $dbi->execute("drop table $table3") };
256
$dbi->execute($create_table1);
257
$dbi->execute($create_table2);
258
$dbi->execute($create_table3);
259
$user_table_info = $dbi->get_table_info(exclude => $dbi->exclude_table);
260

            
cleanup test
Yuki Kimoto authored on 2011-08-15
261
# Create table
test cleanup
Yuki Kimoto authored on 2011-08-10
262
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
263
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
264
$dbi->execute($create_table1);
265
$model = $dbi->create_model(table => $table1);
266
$model->insert({$key1 => 1, $key2 => 2});
267
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-08-15
268

            
cleanup test
Yuki Kimoto authored on 2011-08-15
269
test 'DBIx::Custom::Result test';
270
$dbi->delete_all(table => $table1);
271
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-10-21
272
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
273
$source = "select $key1, $key2 from $table1";
274
$query = $dbi->create_query($source);
275
$result = $dbi->execute($query);
cleanup
Yuki Kimoto authored on 2011-08-15
276

            
cleanup test
Yuki Kimoto authored on 2011-08-15
277
@rows = ();
278
while (my $row = $result->fetch) {
279
    push @rows, [@$row];
280
}
281
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
cleanup
Yuki Kimoto authored on 2011-08-15
282

            
cleanup test
Yuki Kimoto authored on 2011-08-15
283
$result = $dbi->execute($query);
284
@rows = ();
285
while (my $row = $result->fetch_hash) {
286
    push @rows, {%$row};
287
}
288
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
289

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
298
test 'Insert query return value';
299
$source = "insert into $table1 {insert_param $key1 $key2}";
300
$query = $dbi->execute($source, {}, query => 1);
301
$ret_val = $dbi->execute($query, param => {$key1 => 1, $key2 => 2});
302
ok($ret_val);
test cleanup
Yuki Kimoto authored on 2011-08-10
303

            
cleanup test
Yuki Kimoto authored on 2011-08-15
304
test 'Direct query';
305
$dbi->delete_all(table => $table1);
306
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
307
$dbi->execute($insert_source, param => {$key1 => 1, $key2 => 2});
308
$result = $dbi->execute("select * from $table1");
309
$rows = $result->all;
310
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
311

            
312
test 'Filter basic';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
313
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-08
314
$dbi->register_filter(twice       => sub { $_[0] * 2}, 
315
                    three_times => sub { $_[0] * 3});
316

            
cleanup test
Yuki Kimoto authored on 2011-08-15
317
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
318
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
319
$insert_query->filter({$key1 => 'twice'});
320
$dbi->execute($insert_query, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
321
$result = $dbi->execute("select * from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
322
$rows = $result->filter({$key2 => 'three_times'})->all;
323
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
324

            
325
test 'Filter in';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
326
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
327
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
328
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
329
$dbi->execute($insert_query, param => {$key1 => 2, $key2 => 4});
330
$select_source = "select * from $table1 where {in $table1.$key1 2} and {in $table1.$key2 2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
331
$select_query = $dbi->execute($select_source,{}, query => 1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
332
$select_query->filter({"$table1.$key1" => 'twice'});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
333
$result = $dbi->execute($select_query, param => {"$table1.$key1" => [1,5], "$table1.$key2" => [2,4]});
cleanup test
Yuki Kimoto authored on 2011-08-08
334
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
335
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
336

            
cleanup test
Yuki Kimoto authored on 2011-08-08
337
test 'DBIx::Custom::SQLTemplate basic tag';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
338
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
339
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
340
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
341
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
342

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

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

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

            
361
test 'DIB::Custom::SQLTemplate in tag';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
362
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
363
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
364
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
365
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
366

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-08
396
test 'Named placeholder';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
397
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
398
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
399
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
400
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
cleanup test
Yuki Kimoto authored on 2011-08-08
401

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
417
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
418
$result = $dbi->execute(
419
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
420
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
421
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
cleanup test
Yuki Kimoto authored on 2011-08-08
422
);
423
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
424
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
425

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
426
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
427
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
428
$dbi->insert(table => $table1, param => {$key1 => '2011-10-14 12:19:18', $key2 => 2});
429
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
430
$result = $dbi->execute(
431
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
432
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
433
);
434

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
439
$dbi->delete_all(table => $table1);
440
$dbi->insert(table => $table1, param => {$key1 => 'a:b c:d', $key2 => 2});
441
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
442
$result = $dbi->execute(
443
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
444
    param => {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
445
);
446
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
447
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
448

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
465
$dbi->execute("delete from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
466
$dbi->register_filter(
467
    twice       => sub { $_[0] * 2 },
468
    three_times => sub { $_[0] * 3 }
469
);
470
$dbi->default_bind_filter('twice');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
471
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => 'three_times'});
cleanup test
Yuki Kimoto authored on 2011-08-15
472
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
473
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
474
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-10
475
$dbi->default_bind_filter(undef);
476

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
477
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
478
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
479
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, append => '   ');
480
$rows = $dbi->select(table => $table1)->all;
481
is_deeply($rows, [{$key1 => 1, $key2 => 2}], 'insert append');
cleanup test
Yuki Kimoto authored on 2011-08-10
482

            
483
eval{$dbi->insert(table => 'table', param => {';' => 1})};
484
like($@, qr/safety/);
485

            
cleanup test
Yuki Kimoto authored on 2011-08-10
486
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
487
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
488
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
489
$dbi->insert(table => 'table', param => {select => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
490
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
491
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
492
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
cleanup test
Yuki Kimoto authored on 2011-08-10
493

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
494
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
495
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
496
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
497
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
498
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
499
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
500
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
501

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
502
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
503
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
504
$dbi->insert(table => $table1, param => {$key1 => \"'1'", $key2 => 2});
505
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
506
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
507
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
508
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
509

            
updated pod
Yuki Kimoto authored on 2011-09-02
510
eval { $dbi->execute("drop table $table1") };
511
$dbi->execute($create_table1);
512
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
513
  wrap => {$key1 => sub { "$_[0] - 1" }});
514
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
515
$result = $dbi->execute("select * from $table1");
516
$rows   = $result->all;
517
is_deeply($rows, [{$key1 => 0, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
518

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
519
eval { $dbi->execute("drop table $table1") };
520
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
521
$dbi->insert_timestamp(
522
    $key1 => '5'
523
);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
524
$dbi->insert(table => $table1, param => {$key2 => 2}, timestamp => 1);
525
$result = $dbi->execute("select * from $table1");
526
$rows   = $result->all;
527
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
528

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

            
539
eval { $dbi->execute("drop table $table1") };
540
$dbi->execute($create_table1);
541
$dbi->insert_timestamp(
542
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
543
);
544
$dbi->insert(table => $table1, timestamp => 1);
545
$result = $dbi->execute("select * from $table1");
546
$rows   = $result->all;
547
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
548

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
549
test 'update_or_insert';
550
eval { $dbi->execute("drop table $table1") };
551
$dbi->execute($create_table1);
552
$dbi->update_or_insert(
553
    {$key2 => 2},
554
    table => $table1,
555
    primary_key => $key1,
556
    id => 1
557
);
558
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
559
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
560

            
561
$dbi->update_or_insert(
562
    {$key2 => 3},
563
    table => $table1,
564
    primary_key => $key1,
565
    id => 1
566
);
567
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
568
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
569

            
570
eval { $dbi->execute("drop table $table1") };
571
$dbi->execute($create_table1);
572
$dbi->update_or_insert(
573
    {$key1 => 1, $key2 => 2},
574
    table => $table1,
575
    where => {$key1 => 1}
576
);
577
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
578
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
579

            
580
test 'default_bind_filter';
581
$dbi->execute("delete from $table1");
582
$dbi->register_filter(
583
    twice       => sub { $_[0] * 2 },
584
    three_times => sub { $_[0] * 3 }
585
);
586
$dbi->default_bind_filter('twice');
587
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, filter => {$key1 => 'three_times'});
588
$result = $dbi->execute("select * from $table1");
589
$rows   = $result->all;
590
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
591
$dbi->default_bind_filter(undef);
592

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
783

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

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

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

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

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

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

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

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

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

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

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

            
875

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

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

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

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

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

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

            
910
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
911
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
912
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
913
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
914
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
915
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], "relation : no exists where");
test cleanup
Yuki Kimoto authored on 2011-08-10
916

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

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

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

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

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

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

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

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

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

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

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

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

            
1007

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

            
1013
$dbi->begin_work;
1014

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

            
1021
$dbi->rollback if $@;
1022

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

            
1027
$dbi->begin_work;
1028

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

            
1034
$dbi->commit unless $@;
1035

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1631

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

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

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

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

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

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

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

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

            
1687
$dbi->apply_filter(
1688

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2021

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2241

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

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

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

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

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

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

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

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

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

            
2355
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2356
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2357
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2358
$dbi->model($table1)->insert(
2359
    {$key3 => 3},
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
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2363
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2364
is($row->{$key1}, 1);
2365
is($row->{$key2}, 2);
2366
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2367

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

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

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

            
2409

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

            
2425

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

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

            
2446

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

            
2465

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

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

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

            
2505

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2550
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2551
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2552
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2553
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2554
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2555
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2556
);
2557
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2558
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2559
);
2560
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2561
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2562
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2563
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2564
$result = $model->select(
2565
    column => [
2566
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2567
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2568
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2569
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2570
);
2571
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2572
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2573
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2574

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

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

            
2601

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

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

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

            
2628

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3182

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3386

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3607

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

            
cleanup
Yuki Kimoto authored on 2011-08-16
3612
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3613
$dbi->type_rule(
3614
    into1 => {
3615
        $date_typename => sub { '2010-' . $_[0] }
3616
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3617
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3618
$dbi->insert({$key1 => '01-01'}, table => $table1);
3619
$result = $dbi->select(table => $table1);
3620
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3621

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

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

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

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

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

            
3732

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4118

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

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

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

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

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

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

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

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