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

            
micro optimization and
Yuki Kimoto authored on 2011-10-25
770
eval { $dbi->execute("drop table $table1") };
771
$dbi->execute($create_table1_2);
772
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
773
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
774
$param = {$key2 => 11};
775
$dbi->update($param, table => $table1, where => {$key1 => 1});
776
is_deeply($param, {$key2 => 11});
777
$result = $dbi->execute("select * from $table1 order by $key1");
778
$rows   = $result->all;
779
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
780
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
781
                  "basic");
782

            
783
eval { $dbi->execute("drop table $table1") };
784
$dbi->execute($create_table1_2);
785
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
786
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
787
$param = {$key2 => 11};
788
$dbi->update($param, table => $table1, where => {$key2 => 2});
789
is_deeply($param, {$key2 => 11});
790
$result = $dbi->execute("select * from $table1 order by $key1");
791
$rows   = $result->all;
792
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
793
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
794
                  "basic");
795

            
test cleanup
Yuki Kimoto authored on 2011-08-10
796
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
797
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
798
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
799
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
800
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
801
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
802
$dbi->update_all(table => $table1, param => {$key2 => 10}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
803
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
804
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
805
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
806
                  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
807
                  "filter");
808

            
809

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
820
$dbi->execute("delete from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
821
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
822
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
823
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
824
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
825
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
826
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
827
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
828

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
831
$dbi->delete_all(table => $table1);
832
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
833
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
834
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
835
$rows = $dbi->select(table => $table1)->all;
836
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
837

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
838
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
839
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
840
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
841
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
842
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
843
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
844
$where->param({ke1 => 1, $key2 => 2});
845
$dbi->delete(table => $table1, where => $where);
846
$result = $dbi->select(table => $table1);
847
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
848

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
849
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
850
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
851
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
852
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
853
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
854
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
855
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
856
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
857
        {ke1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
858
    ]
859
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
860
$result = $dbi->select(table => $table1);
861
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
862

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
880
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
881
$dbi = DBIx::Custom->connect;
882
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
883
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
884
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
885
$dbi->insert(table => 'table', param => {select => 1});
886
$dbi->delete(table => 'table', where => {select => 1});
887
$result = $dbi->execute("select * from ${q}table$p");
888
$rows   = $result->all;
889
is_deeply($rows, [], "reserved word");
890

            
891
test 'delete_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
892
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
893
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
894
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
895
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
896
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
897
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
898
$rows   = $result->all;
899
is_deeply($rows, [], "basic");
900

            
901

            
902
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
903
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
904
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
905
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
906
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
907
$rows = $dbi->select(table => $table1)->all;
908
is_deeply($rows, [{$key1 => 1, $key2 => 2},
909
                  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
910

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
925
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
926
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
927
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
test cleanup
Yuki Kimoto authored on 2011-08-10
928
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
929
    table => [$table1, $table2],
930
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
931
    where   => {"$table1.$key2" => 2},
932
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
933
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
934
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
935

            
936
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
937
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
938
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
939
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
940
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
941
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
942

            
943
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
944
eval { $dbi->execute("drop table ${q}table$p") };
945
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
946
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
947
$dbi->insert(table => 'table', param => {select => 1, update => 2});
948
$result = $dbi->select(table => 'table', where => {select => 1});
949
$rows   = $result->all;
950
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
951

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

            
966
test 'filters';
967
$dbi = DBIx::Custom->new;
968

            
969
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
970
   'あ', "decode_utf8");
971

            
972
is($dbi->filters->{encode_utf8}->('あ'),
973
   encode_utf8('あ'), "encode_utf8");
974

            
cleanup test
Yuki Kimoto authored on 2011-08-10
975
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
976
$dbi = DBIx::Custom->connect;
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);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
979
$dbi->begin_work;
980
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
981
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
982
$dbi->rollback;
983
$dbi->dbh->{AutoCommit} = 1;
984

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

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

            
989
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
990
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
991
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
992
$dbi->begin_work;
993
$dbi->dbh->{AutoCommit} = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
994
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
995
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
fixed transaction test
Yuki Kimoto authored on 2011-08-14
996
$dbi->commit;
997
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
998
$result = $dbi->select(table => $table1);
999
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1000
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1001

            
1002
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1003
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1004
$dbi->execute($create_table1);
1005
{
1006
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1007
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1008
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1009
    like($@, qr/\.t /, "fail : not verbose");
1010
}
1011
{
1012
    local $Carp::Verbose = 1;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1013
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1014
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1015
}
1016

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

            
1022
{
1023
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1024
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1025
    like($@, qr/\Q.t /, "caller spec : not vebose");
1026
}
1027
{
1028
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1029
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1030
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1031
}
1032

            
1033

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1034
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1035
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1036
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1037
$dbi->execute($create_table1);
1038

            
1039
$dbi->begin_work;
1040

            
1041
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1042
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1043
    die "Error";
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1044
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1045
};
1046

            
1047
$dbi->rollback if $@;
1048

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

            
1053
$dbi->begin_work;
1054

            
1055
eval {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1056
    $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1057
    $dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
test cleanup
Yuki Kimoto authored on 2011-08-10
1058
};
1059

            
1060
$dbi->commit unless $@;
1061

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

            
1066
$dbi->dbh->{AutoCommit} = 0;
1067
eval{ $dbi->begin_work };
1068
ok($@, "exception");
1069
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1070

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1071
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1072
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1073
$dbi->cache(1);
1074
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1075
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1076
$dbi->execute($source, {}, query => 1);
1077
is_deeply($dbi->{_cached}->{$source}, 
cleanup test
Yuki Kimoto authored on 2011-08-15
1078
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1079

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1080
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1081
$dbi->execute($create_table1);
1082
$dbi->{_cached} = {};
1083
$dbi->cache(0);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1084
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1085
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1086

            
1087
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1088
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1089
$dbi->execute($create_table1);
1090
{
1091
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1092
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1093
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1094
    like($@, qr/\.t /, "fail : not verbose");
1095
}
1096
{
1097
    local $Carp::Verbose = 1;
- removed argument checking ...
Yuki Kimoto authored on 2011-10-21
1098
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1099
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1100
}
1101

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

            
1107
{
1108
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1109
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1110
    like($@, qr/\Q.t /, "caller spec : not vebose");
1111
}
1112
{
1113
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1114
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1115
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1116
}
1117

            
1118
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1119
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1120
    one => sub { 1 }
1121
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1122
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1123
    two => sub { 2 }
1124
);
1125
$dbi->method({
1126
    twice => sub {
1127
        my $self = shift;
1128
        return $_[0] * 2;
1129
    }
1130
});
1131

            
1132
is($dbi->one, 1, "first");
1133
is($dbi->two, 2, "second");
1134
is($dbi->twice(5), 10 , "second");
1135

            
1136
eval {$dbi->XXXXXX};
1137
ok($@, "not exists");
1138

            
1139
test 'out filter';
1140
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1141
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1142
$dbi->execute($create_table1);
1143
$dbi->register_filter(twice => sub { $_[0] * 2 });
1144
$dbi->register_filter(three_times => sub { $_[0] * 3});
1145
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1146
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1147
              $key2 => {out => 'three_times', in => 'twice'});
1148
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1149
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1150
$row   = $result->fetch_hash_first;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1151
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1152
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1153
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1154
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1155

            
1156
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1157
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1158
$dbi->execute($create_table1);
1159
$dbi->register_filter(twice => sub { $_[0] * 2 });
1160
$dbi->register_filter(three_times => sub { $_[0] * 3});
1161
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1162
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1163
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1164
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1165
    $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1166
); 
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1167
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
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
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1170
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
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 => 1, $key2 => 2}, filter => {$key1 => undef});
1180
$dbi->update(table => $table1, param => {$key1 => 2}, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1181
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1182
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1183
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
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});
1193
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1194
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1195
$rows   = $result->all;
1196
is_deeply($rows, [], "delete");
1197

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

            
1211
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1212
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1213
$dbi->execute($create_table1);
1214
$dbi->register_filter(twice => sub { $_[0] * 2 });
1215
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1216
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1217
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1218
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1219
$result = $dbi->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1220
                        param => {$key1 => 1, $key2 => 2},
1221
                        table => [$table1]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1222
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1223
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute");
test cleanup
Yuki Kimoto authored on 2011-08-10
1224

            
1225
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1226
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1227
$dbi->execute($create_table1);
1228
$dbi->register_filter(twice => sub { $_[0] * 2 });
1229
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1230
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1231
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1232
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 2}, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1233
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1234
                        param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1235
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1236
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1237

            
1238
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1239
eval { $dbi->execute("drop table $table1") };
1240
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1241
$dbi->execute($create_table1);
1242
$dbi->execute($create_table2);
1243
$dbi->register_filter(twice => sub { $_[0] * 2 });
1244
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1245
$dbi->apply_filter(
cleanup test
Yuki Kimoto authored on 2011-08-15
1246
    $table1, $key2 => {out => 'twice', in => 'twice'}
1247
);
1248
$dbi->apply_filter(
1249
    $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1250
);
cleanup test
Yuki Kimoto authored on 2011-08-15
1251
$dbi->insert(table => $table1, param => {$key1 => 5, $key2 => 2}, filter => {$key2 => undef});
1252
$dbi->insert(table => $table2, param => {$key1 => 5, $key3 => 6}, filter => {$key3 => undef});
1253
$result = $dbi->select(
1254
     table => [$table1, $table2],
1255
     column => [$key2, $key3],
1256
     where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1257

            
1258
$result->filter({$key2 => 'twice'});
1259
$rows   = $result->all;
1260
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1261

            
1262
$result = $dbi->select(
1263
     table => [$table1, $table2],
1264
     column => [$key2, $key3],
1265
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1266

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

            
1271
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1272
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1273
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1274
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1275
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1276
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1277

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1278
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1279
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1280
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1281
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1282
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1283
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1284

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1285
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1286
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1287
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1288
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1289
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1290

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

            
1302
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1303
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1304
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1305
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1306
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1307
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1308
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1309
$row = $result->fetch_first;
1310
is_deeply($row, [6, 12]);
1311

            
1312
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1313
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1314
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1315
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1316
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1317
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1318
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1319
$row = $result->fetch_first;
1320
is_deeply($row, [6, 12]);
1321

            
1322
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1323
$result = $dbi->select(table => $table1);
1324
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1325
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1326
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1327
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1328

            
1329
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1330
$dbi->apply_filter($table1,
1331
    $key1 => {end => sub { $_[0] * 3 } },
1332
    $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1333
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1334
$result = $dbi->select(table => $table1);
1335
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1336
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1337
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1338

            
1339
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1340
$dbi->apply_filter($table1,
1341
    $key1 => {end => sub { $_[0] * 3 } },
1342
    $key2 => {end => 'five_times'}
1343
);
1344
$result = $dbi->select(table => $table1);
1345
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1346
$result->filter($key1 => undef);
1347
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1348
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1349
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1350

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1351
test 'remove_end_filter and remove_filter';
1352
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1353
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1354
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1355
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1356
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1357
$row = $result
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1358
       ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1359
       ->remove_filter
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1360
       ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1361
       ->remove_end_filter
1362
       ->fetch_first;
1363
is_deeply($row, [1, 2]);
1364

            
1365
test 'empty where select';
1366
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1367
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1368
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1369
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1370
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1371
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1372
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1373

            
1374
test 'select query option';
1375
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1376
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1377
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1378
$query = $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1379
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1380
$query = $dbi->update(table => $table1, where => {$key1 => 1}, param => {$key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1381
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1382
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1383
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1384
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1385
is(ref $query, 'DBIx::Custom::Query');
1386

            
1387
test 'where';
1388
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1389
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1390
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1391
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1392
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1393
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1394
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1395

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

            
1400
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1401
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1402
    where => $where
1403
);
1404
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1405
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1406

            
1407
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1408
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1409
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1410
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
1411
        {$key1 => 1}
test cleanup
Yuki Kimoto authored on 2011-08-10
1412
    ]
1413
);
1414
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1415
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1416

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

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

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

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

            
1455
eval {
1456
$where = $dbi->where
1457
             ->clause(['uuu']);
1458
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1459
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1460
    where => $where
1461
);
1462
};
1463
ok($@);
1464

            
1465
$where = $dbi->where;
1466
is("$where", '');
1467

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

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

            
1488
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1489
             ->clause(['or', ("$key1 = :$key1") x 2])
1490
             ->param({$key1 => 1});
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}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1497

            
1498
$where = $dbi->where
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1499
             ->clause("$key1 = :$key1")
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1500
             ->param({$key1 => 1});
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}]);
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("$key1 = :$key1 $key2 = :$key2")
1510
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1511
eval{$where->to_string};
1512
like($@, qr/one column/);
1513

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

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

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

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

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

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

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

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

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

            
1604
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1605
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1606
             ->param({$key1 => [$dbi->not_exists, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1607
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1608
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1609
    where => $where,
1610
);
1611
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1612
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1613

            
1614
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1615
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1616
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1617
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1618
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1619
    where => $where,
1620
);
1621
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1622
is_deeply($row, [{$key1 => 1, $key2 => 2},{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1623

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

            
1634
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1635
             ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
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}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1642

            
1643
eval {$dbi->where(ppp => 1) };
1644
like($@, qr/invalid/);
1645

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

            
1657

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

            
1669
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1670
$where->clause(['and', ":${key1}{=}"]);
1671
$where->param({$key1 => undef});
1672
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1673
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1674
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1675

            
1676
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1677
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1678
$where->param({$key1 => [undef, undef]});
1679
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1680
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1681
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1682
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1683
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1684
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1685

            
1686
test 'register_tag_processor';
1687
$dbi = DBIx::Custom->connect;
1688
$dbi->register_tag_processor(
1689
    a => sub { 1 }
1690
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1691
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1692

            
1693
test 'register_tag';
1694
$dbi = DBIx::Custom->connect;
1695
$dbi->register_tag(
1696
    b => sub { 2 }
1697
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1698
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1699

            
1700
test 'table not specify exception';
1701
$dbi = DBIx::Custom->connect;
1702
eval {$dbi->select};
1703
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1704

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1705
test 'more tests';
1706
$dbi = DBIx::Custom->connect;
1707
eval{$dbi->apply_filter('table', 'column', [])};
1708
like($@, qr/apply_filter/);
1709

            
1710
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1711
like($@, qr/apply_filter/);
1712

            
1713
$dbi->apply_filter(
1714

            
1715
);
1716
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1717
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1718
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1719
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1720
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1721
$dbi->apply_filter($table1, $key2, 
test cleanup
Yuki Kimoto authored on 2011-08-10
1722
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1723
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
1724
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1725

            
1726
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1727
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1728
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1729
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
1730
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
1731
$dbi->apply_filter($table1, $key2, {});
1732
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1733
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1734

            
1735
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1736
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1737
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1738
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1739
like($@, qr/not registered/);
1740
$dbi->method({one => sub { 1 }});
1741
is($dbi->one, 1);
1742

            
1743
eval{DBIx::Custom->connect(dsn => undef)};
1744
like($@, qr/_connect/);
1745

            
1746
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1747
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1748
$dbi->execute($create_table1);
1749
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1750
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1751
             filter => {$key1 => 'twice'});
1752
$row = $dbi->select(table => $table1)->one;
1753
is_deeply($row, {$key1 => 2, $key2 => 2});
1754
eval {$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2},
1755
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
1756
like($@, qr//);
1757

            
1758
$dbi->register_filter(one => sub { });
1759
$dbi->default_fetch_filter('one');
1760
ok($dbi->default_fetch_filter);
1761
$dbi->default_bind_filter('one');
1762
ok($dbi->default_bind_filter);
1763
eval{$dbi->default_fetch_filter('no')};
1764
like($@, qr/not registered/);
1765
eval{$dbi->default_bind_filter('no')};
1766
like($@, qr/not registered/);
1767
$dbi->default_bind_filter(undef);
1768
ok(!defined $dbi->default_bind_filter);
1769
$dbi->default_fetch_filter(undef);
1770
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1771
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1772
like($@, qr/Tag not finished/);
1773

            
1774
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1775
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1776
$dbi->execute($create_table1);
1777
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1778
$result = $dbi->select(table => $table1);
1779
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1780
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1781
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1782
like($@, qr/not registered/);
1783
$result->default_filter(undef);
1784
ok(!defined $result->default_filter);
1785
$result->default_filter('one');
1786
is($result->default_filter->(), 1);
1787

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1788
test 'option';
1789
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
1790
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
1791
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
1792
ok($dbi->dbh->{PrintError});
1793
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
1794
ok($dbi->dbh->{PrintError});
1795

            
1796
test 'DBIx::Custom::Result stash()';
1797
$result = DBIx::Custom::Result->new;
1798
is_deeply($result->stash, {}, 'default');
1799
$result->stash->{foo} = 1;
1800
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
1801

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1802
test 'delete_at';
1803
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1804
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1805
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1806
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1807
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1808
    table => $table1,
1809
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1810
    where => [1, 2],
1811
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1812
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1813

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1814
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1815
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1816
    table => $table1,
1817
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1818
    where => 1,
1819
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1820
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1821

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1836
$dbi->delete_all(table => $table1);
1837
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1838
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1839
    primary_key => $key1, 
1840
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1841
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1842
    param => {$key2 => 2, $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
1843
);
1844

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

            
1849
eval {
1850
    $dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1851
        table => $table1,
1852
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1853
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1854
        param => {$key1 => 1, $key2 => 2, $key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
1855
    );
1856
};
1857
like($@, qr/must be/);
1858

            
1859
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1860
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1861
$dbi->execute($create_table1_2);
1862
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1863
    {$key3 => 3},
1864
    primary_key => [$key1, $key2], 
1865
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1866
    where => [1, 2],
1867
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1868
is($dbi->select(table => $table1)->one->{$key1}, 1);
1869
is($dbi->select(table => $table1)->one->{$key2}, 2);
1870
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1871

            
1872
test 'update_at';
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
    table => $table1,
1879
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1880
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1881
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1887
$dbi->delete_all(table => $table1);
1888
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1889
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1890
    table => $table1,
1891
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1892
    where => 1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1893
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
1894
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1895
is($dbi->select(table => $table1)->one->{$key1}, 1);
1896
is($dbi->select(table => $table1)->one->{$key2}, 2);
1897
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1898

            
1899
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1900
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1901
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1902
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1903
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1904
    {$key3 => 4},
1905
    table => $table1,
1906
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1907
    where => [1, 2]
1908
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1909
is($dbi->select(table => $table1)->one->{$key1}, 1);
1910
is($dbi->select(table => $table1)->one->{$key2}, 2);
1911
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
1912

            
1913
test 'select_at';
1914
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1915
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1916
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1917
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1918
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1919
    table => $table1,
1920
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1921
    where => [1, 2]
1922
);
1923
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1924
is($row->{$key1}, 1);
1925
is($row->{$key2}, 2);
1926
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1927

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1928
$dbi->delete_all(table => $table1);
1929
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
1930
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1931
    table => $table1,
1932
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1933
    where => 1,
1934
);
1935
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1936
is($row->{$key1}, 1);
1937
is($row->{$key2}, 2);
1938
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1939

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

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

            
1961
eval {
1962
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1963
        table => $table1,
1964
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1965
        where => [1],
1966
    );
1967
};
1968
like($@, qr/same/);
1969

            
1970
eval {
1971
    $result = $dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1972
        table => $table1,
1973
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1974
        where => {},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1975
        param => {$key1 => 1, $key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-10
1976
    );
1977
};
1978
like($@, qr/must be/);
1979

            
1980
eval {
1981
    $result = $dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1982
        table => $table1,
1983
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1984
        where => {},
1985
    );
1986
};
1987
like($@, qr/must be/);
1988

            
1989
test 'model delete_at';
1990
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1991
eval { $dbi->execute("drop table $table1") };
1992
eval { $dbi->execute("drop table $table2") };
1993
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1994
$dbi->execute($create_table1_2);
1995
$dbi->execute($create_table2_2);
1996
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1997
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
1998
$dbi->model($table1)->delete_at(where => [1, 2]);
1999
is_deeply($dbi->select(table => $table1)->all, []);
2000
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2001
$dbi->model($table1)->delete_at(where => [1, 2]);
2002
is_deeply($dbi->select(table => $table1)->all, []);
2003
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2004
$dbi->model($table3)->delete_at(where => [1, 2]);
2005
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2006

            
2007
test 'model insert_at';
2008
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2009
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2010
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2011
$dbi->model($table1)->insert_at(
cleanup test
Yuki Kimoto authored on 2011-08-10
2012
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2013
    param => {$key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2014
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2015
$result = $dbi->model($table1)->select;
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
test 'model update_at';
2022
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2023
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2024
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2025
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2026
$dbi->model($table1)->update_at(
cleanup test
Yuki Kimoto authored on 2011-08-10
2027
    where => [1, 2],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2028
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2029
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2030
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2031
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2032
is($row->{$key1}, 1);
2033
is($row->{$key2}, 2);
2034
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2035

            
2036
test 'model select_at';
2037
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2038
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2039
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2040
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2041
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2042
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2043
is($row->{$key1}, 1);
2044
is($row->{$key2}, 2);
2045
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2046

            
2047

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2067
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2068
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2069
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2070
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2071
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2072
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2073
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2074
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2075
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2076
$dbi->execute($sql, param => $param, table => $table1);
2077
is($dbi->select(table => $table1)->one->{$key1}, 1);
2078
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2079

            
2080
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2081
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2082
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2083
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2084
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2085
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2086
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2087
EOS
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2088
$dbi->execute($sql, param => $param, table => $table1);
2089
is($dbi->select(table => $table1)->one->{$key1}, 1);
2090
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2091

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2095
test 'mycolumn';
2096
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2097
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2098
eval { $dbi->execute("drop table $table1") };
2099
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2100
$dbi->execute($create_table1);
2101
$dbi->execute($create_table2);
2102
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2103
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2104
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2105
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2106
$result = $model->select_at(
2107
    column => [
2108
        $model->mycolumn,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2109
        $model->column($table2)
cleanup test
Yuki Kimoto authored on 2011-08-10
2110
    ]
2111
);
2112
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2113
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
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
        $model->column($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
$result = $model->select_at(
2124
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2125
        $model->mycolumn([$key1]),
2126
        {$table2 => [$key1]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2127
    ]
2128
);
2129
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2130
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2131

            
2132
$result = $model->select_at(
2133
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2134
        $model->mycolumn([$key1]),
2135
        ["$table2.$key1", as => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2136
    ]
2137
);
2138
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2139
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2140

            
2141
$result = $model->select_at(
2142
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2143
        $model->mycolumn([$key1]),
2144
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2145
    ]
2146
);
2147
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2148
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2149

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2150
test 'merge_param';
2151
$dbi = DBIx::Custom->new;
2152
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2153
    {$key1 => 1, $key2 => 2, $key3 => 3},
2154
    {$key1 => 1, $key2 => 2},
2155
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2156
];
2157
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2158
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2159

            
2160
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2161
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2162
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2163
];
2164
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2165
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
2166

            
2167
test 'select() param option';
2168
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2169
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2170
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2171
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2172
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2173
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2174
$dbi->execute($create_table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2175
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
2176
$dbi->insert(table => $table2, param => {$key1 => 2, $key3 => 5});
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
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2180
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2181
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
test cleanup
Yuki Kimoto authored on 2011-08-15
2182
              " $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2183
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2184
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2185
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2186

            
cleanup
Yuki Kimoto authored on 2011-10-21
2187
$rows = $dbi->select(
2188
    table => $table1,
2189
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2190
    where   => {"$table1.$key2" => 3},
2191
    join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2192
             " $table2 on $table1.$key1 = $table2.$key1",
2193
    param => {"$table2.$key3" => 5}
2194
)->all;
2195
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2196

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
2224
$dbi = DBIx::Custom->connect;
2225
eval { $dbi->execute("drop table $table1") };
2226
$dbi->execute($create_table1);
2227
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2228
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
2229
$rows = $dbi->select(
2230
    table => $table1,
2231
    where => [
2232
        "$key1 = :$key1 and $key2 = :$key2",
2233
        {$key1 => 1, $key2 => 2}
2234
    ]
2235
)->all;
2236
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2237

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

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

            
2267

            
2268
test 'update() string where';
2269
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2270
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2271
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2272
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2273
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2274
    table => $table1,
2275
    param => {$key1 => 5},
2276
    where => "$key1 = :$key1 and $key2 = :$key2",
2277
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2278
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2279
$rows = $dbi->select(table => $table1)->all;
2280
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2281

            
2282
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2283
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2284
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2285
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-10
2286
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2287
    table => $table1,
2288
    param => {$key1 => 5},
cleanup test
Yuki Kimoto authored on 2011-08-10
2289
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2290
        "$key1 = :$key1 and $key2 = :$key2",
2291
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2292
    ]
2293
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2294
$rows = $dbi->select(table => $table1)->all;
2295
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2296

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

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

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

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

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2336
$dbi = DBIx::Custom->connect;
2337
eval { $dbi->execute("drop table $table1") };
2338
$dbi->execute($create_table1_2);
2339
$param = {$key3 => 3, $key2 => 4};
2340
$dbi->insert(
2341
    $param,
2342
    primary_key => [$key1, $key2], 
2343
    table => $table1,
2344
    id => [1, 2],
2345
);
2346
is($dbi->select(table => $table1)->one->{$key1}, 1);
2347
is($dbi->select(table => $table1)->one->{$key2}, 4);
2348
is($dbi->select(table => $table1)->one->{$key3}, 3);
2349
is_deeply($param, {$key3 => 3, $key2 => 4});
2350

            
added test
Yuki Kimoto authored on 2011-10-25
2351
$dbi = DBIx::Custom->connect;
2352
eval { $dbi->execute("drop table $table1") };
2353
$dbi->execute($create_table1_2);
2354
$param = {$key3 => 3, $key2 => 4};
2355
$query = $dbi->insert(
2356
    $param,
2357
    primary_key => [$key1, $key2], 
2358
    table => $table1,
2359
    id => [1, 2],
2360
    query => 1
2361
);
2362
is(ref $query, 'DBIx::Custom::Query');
2363
is_deeply($param, {$key3 => 3, $key2 => 4});
2364

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

            
2379
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2380
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2381
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2382
$dbi->model($table1)->insert(
2383
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2384
    id => [1, 2]
2385
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2386
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2387
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2388
is($row->{$key1}, 1);
2389
is($row->{$key2}, 2);
2390
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2391

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

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

            
2419
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2420
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2421
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2422
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2423
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2424
    {$key3 => 4},
2425
    table => $table1,
2426
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2427
    id => [1, 2]
2428
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2429
is($dbi->select(table => $table1)->one->{$key1}, 1);
2430
is($dbi->select(table => $table1)->one->{$key2}, 2);
2431
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2432

            
2433

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

            
2449

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2462
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2463
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2464
    table => $table1,
2465
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2466
    id => 0,
2467
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2468
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2469

            
2470

            
2471
test 'model delete and id option';
2472
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2473
eval { $dbi->execute("drop table $table1") };
2474
eval { $dbi->execute("drop table $table2") };
2475
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2476
$dbi->execute($create_table1_2);
2477
$dbi->execute($create_table2_2);
2478
$dbi->execute($create_table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2479
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2480
$dbi->model($table1)->delete(id => [1, 2]);
2481
is_deeply($dbi->select(table => $table1)->all, []);
2482
$dbi->insert(table => $table2, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2483
$dbi->model($table1)->delete(id => [1, 2]);
2484
is_deeply($dbi->select(table => $table1)->all, []);
2485
$dbi->insert(table => $table3, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2486
$dbi->model($table3)->delete(id => [1, 2]);
2487
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2488

            
2489

            
2490
test 'select and id option';
2491
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2492
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2493
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2505
$dbi->delete_all(table => $table1);
2506
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2507
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2508
    table => $table1,
2509
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2510
    id => 0,
2511
);
2512
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2513
is($row->{$key1}, 0);
2514
is($row->{$key2}, 2);
2515
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2516

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2517
$dbi->delete_all(table => $table1);
2518
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2519
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2520
    table => $table1,
2521
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2522
    id => [1, 2]
2523
);
2524
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2525
is($row->{$key1}, 1);
2526
is($row->{$key2}, 2);
2527
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2528

            
2529

            
2530
test 'model select_at';
2531
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2532
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2533
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2534
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3});
2535
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2536
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2537
is($row->{$key1}, 1);
2538
is($row->{$key2}, 2);
2539
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2540

            
2541
test 'column separator is default .';
2542
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2543
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2544
eval { $dbi->execute("drop table $table1") };
2545
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2546
$dbi->execute($create_table1);
2547
$dbi->execute($create_table2);
2548
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2549
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2550
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2551
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2552
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2553
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2554
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2555
);
2556
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2557
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2558

            
2559
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2560
    column => [$model->column($table2 => [$key1, $key3])],
2561
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2562
);
2563
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2564
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2565

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2566
test 'separator';
2567
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2568
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2569
eval { $dbi->execute("drop table $table1") };
2570
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2571
$dbi->execute($create_table1);
2572
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2573

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2574
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2575
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2576
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2577
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2578
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2579
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2580
);
2581
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2582
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2583
);
2584
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2585
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2586
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
2587
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2588
$result = $model->select(
2589
    column => [
2590
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2591
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2592
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2593
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2594
);
2595
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2596
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2597
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2598

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2599
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2600
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2601
$result = $model->select(
2602
    column => [
2603
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2604
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2605
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2606
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2607
);
2608
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2609
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
2610
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2611

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2612
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2613
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2614
$result = $model->select(
2615
    column => [
2616
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2617
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2618
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2619
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2620
);
2621
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2622
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2623
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2624

            
2625

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2626
test 'filter_off';
2627
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2628
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2629
eval { $dbi->execute("drop table $table1") };
2630
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2631
$dbi->execute($create_table1);
2632
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2633

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2634
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2635
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2636
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2637
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2638
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2639
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2640
);
2641
$dbi->setup_model;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2642
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2643
$model = $dbi->model($table1);
2644
$result = $model->select(column => $key1);
2645
$result->filter($key1 => sub { $_[0] * 2 });
2646
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2647

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2648
test 'available_datetype';
2649
$dbi = DBIx::Custom->connect;
2650
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2651

            
2652

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2653
test 'select prefix option';
2654
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2655
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2656
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2657
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2658
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2659
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2660

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

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

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2672
$dbi = DBIx::Custom->connect;
2673
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2674
    id => {key => "$table1.id"},
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2675
    author => ["$table1.author" => $dbi->like_value],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2676
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2677
);
2678
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2679
  "$table1.price" => 1900});
2680

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

            
2688
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2689
    id => {key => "$table1.id"},
2690
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2691
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
added tests
Yuki Kimoto authored on 2011-08-26
2692
);
2693
is_deeply($param, {});
2694

            
2695
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2696
    id => {key => "$table1.id"},
2697
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2698
);
2699
is_deeply($param, {"$table1.price" => undef});
2700

            
2701
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2702
    id => {key => "$table1.id", condition => 'exists'},
2703
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
2704
);
2705
is_deeply($param, {"$table1.price" => '%a'});
2706

            
2707
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2708
    id => {key => "$table1.id"},
added tests
Yuki Kimoto authored on 2011-08-26
2709
    price => ["$table1.price", sub { '%' . $_[0] }]
2710
);
2711
is_deeply($param, {"$table1.price" => '%a'});
2712

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2713
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2714
    price => sub { '%' . $_[0] },
2715
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2716
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2717
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2718

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2719
eval { $dbi->execute("drop table $table1") };
2720
$dbi->execute($create_table1);
2721
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
2722
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
2723

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

            
2732
$where = $dbi->where;
2733
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2734
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
2735
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2736
$row = $result->all;
2737
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2738
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2739
$row = $result->all;
2740
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2741

            
2742
$where = $dbi->where;
2743
$where->clause(['and', ":${key1}{=}"]);
2744
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
2745
$where->param($param);
2746
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2747
$row = $result->all;
2748
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2749
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2750
$row = $result->all;
2751
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2752

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

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

            
2763
$where = $dbi->where;
2764
$where->clause(['and', ":${key1}{=}"]);
2765
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
2766
$where->param($param);
2767
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2768
$row = $result->all;
2769
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2770

            
2771
$where = $dbi->where;
2772
$where->clause(['and', ":${key1}{=}"]);
2773
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
2774
  ->pass([$key1, $key2])->map;
2775
$where->param($param);
2776
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2777
$row = $result->all;
2778
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2779

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2781
$where = $dbi->where;
2782
$where->clause(['and', ":${key1}{=}"]);
2783
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
2784
$where->param($param);
2785
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2786
$row = $result->all;
2787
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2788

            
2789
$where = $dbi->where;
2790
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2791
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2792
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2793
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2794
);
2795
$where->param($param);
2796
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2797
  "$table1.price" => 1900});
2798

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

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

            
2817
$where = $dbi->where;
2818
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2819
    id => {key => "$table1.id"},
2820
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2821
);
2822
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
2823

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

            
2831
$where = $dbi->where;
2832
$param = $dbi->mapper(param => {id => [1, 2], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2833
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2834
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2835
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2836
);
2837
is_deeply($param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
2838
  "$table1.price" => 1900});
2839

            
2840
$where = $dbi->where;
2841
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900}, condition => 'length')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2842
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2843
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2844
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2845
);
2846
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2847
  "$table1.price" => 1900});
2848

            
2849
$where = $dbi->where;
2850
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2851
    id => {key => "$table1.id", condition => 'length'},
2852
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
2853
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2854
);
2855
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2856
  "$table1.price" => 1900});
2857

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2863
test 'order';
2864
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2865
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2866
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2867
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2868
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
2869
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
2870
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2871
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2872
$order->prepend($key1, "$key2 desc");
2873
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2874
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
2875
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2876
$order->prepend("$key1 desc");
2877
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2878
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
2879
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2880

            
2881
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2882
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2883
$result = $dbi->select(table => $table1,
2884
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2885
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2886
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
2887
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
2888
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
2889
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2890

            
2891
test 'tag_parse';
2892
$dbi = DBIx::Custom->connect;
2893
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2894
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2895
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2896
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2897
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2898
ok($@);
2899

            
2900
test 'last_sql';
2901
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2902
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2903
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2904
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
2905
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
2906

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2938
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
2939
$result = $dbi->execute(
2940
    $source,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2941
    param => {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2942
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
2943
);
2944
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2945
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2946

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

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2968
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2969
$dbi->execute($create_table1_highperformance);
2970
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2971
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2972
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2973
];
2974
{
2975
    my $query;
2976
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
2977
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2978
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2979
      $sth ||= $query->sth;
2980
      $sth->execute(map { $row->{$_} } sort keys %$row);
2981
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2982
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
2983
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2984
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
2985
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
2986
      ]
2987
    );
2988
}
2989

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2990
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2991
$dbi->execute($create_table1_highperformance);
2992
$rows = [
2993
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
2994
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
2995
];
2996
{
2997
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
2998
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
2999
    for my $row (@$rows) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3000
      $query ||= $model->insert($row, query => 1);
3001
      $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3002
    }
3003
    is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3004
      [
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3005
          {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3006
          {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3007
      ]
3008
    );
3009
}
3010

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3011
test 'id option more';
3012
eval { $dbi->execute("drop table $table1") };
3013
$dbi->execute($create_table1_highperformance);
3014
$row = {
3015
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3016
};
3017
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3018
$model->insert($row);
3019
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3020
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3021
is_deeply($dbi->select(table => $table1)->one,
3022
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3023
);
3024

            
3025
eval { $dbi->execute("drop table $table1") };
3026
eval { $dbi->execute("drop table $table2") };
3027
$dbi->execute($create_table1);
3028
$dbi->execute($create_table2);
3029
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3030
$model->insert({$key1 => 1, $key2 => 2});
3031
$model = $dbi->create_model(table => $table2, primary_key => $key1,
3032
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
3033
$model->insert({$key1 => 1, $key3 => 3});
3034
$result = $model->select(
3035
    column => {$table1 => ["$key2"]},
3036
    id => 1
3037
);
3038
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3039

            
3040
eval { $dbi->execute("drop table $table1") };
3041
$dbi->execute($create_table1_highperformance);
3042
$row = {
3043
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3044
};
3045
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3046
$model->insert($row);
3047
$query = $model->delete(id => 1, query => 1);
3048
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3049
is_deeply($dbi->select(table => $table1)->all, []);
3050

            
3051
eval { $dbi->execute("drop table $table1") };
3052
eval { $dbi->execute($create_table1_highperformance) };
3053
$row = {
3054
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3055
};
3056
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3057
$model->insert($row);
3058
$query = $model->select(id => 1, query => 1);
3059
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3060
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3061
is_deeply($dbi->select(table => $table1)->one,
3062
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3063
);
3064

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3072
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3073
@rows = ();
3074
while (my $row = $result->fetch) {
3075
    push @rows, [@$row];
3076
}
3077
is_deeply(\@rows, [[1, 2], [3, 4]]);
3078

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3079
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3080
@rows = ();
3081
while (my $row = $result->fetch_hash) {
3082
    push @rows, {%$row};
3083
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3084
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3085

            
3086
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3087
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3088
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3089
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3090
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3091

            
3092
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3093
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3094
$rows = $result->fetch_all;
3095
is_deeply($rows, [[1, 2], [3, 4]]);
3096

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

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

            
3105
$rows = $result->fetch_all;
3106
is_deeply($rows, [[3, 2], [9, 4]], "array");
3107

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

            
3114
test "query_builder";
3115
$datas = [
3116
    # Basic tests
3117
    {   name            => 'placeholder basic',
3118
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3119
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3120
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3121
    },
3122
    {
3123
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3124
        source            => "{in k1 3}",
3125
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3126
        columns_expected   => [qw/k1 k1 k1/]
3127
    },
3128
    
3129
    # Table name
3130
    {
3131
        name            => 'placeholder with table name',
3132
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3133
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3134
        columns_expected  => [qw/a.k1 a.k2/]
3135
    },
3136
    {   
3137
        name            => 'placeholder in with table name',
3138
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3139
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3140
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3141
    },
3142
    {
3143
        name            => 'not contain tag',
3144
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3145
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3146
        columns_expected  => [],
3147
    }
3148
];
3149

            
3150
for (my $i = 0; $i < @$datas; $i++) {
3151
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3152
    my $dbi = DBIx::Custom->new;
3153
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3154
    my $query = $builder->build_query($data->{source});
3155
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3156
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3157
}
3158

            
cleanup
Yuki Kimoto authored on 2011-08-13
3159
$dbi = DBIx::Custom->new;
3160
$builder = $dbi->query_builder;
3161
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3162
    p => sub {
3163
        my @args = @_;
3164
        
3165
        my $expand    = "? $args[0] $args[1]";
3166
        my $columns = [2];
3167
        return [$expand, $columns];
3168
    }
3169
);
3170

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3181
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3182
    q => 'string'
3183
});
3184

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3188
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3189
   r => sub {} 
3190
});
3191

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3195
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3196
   s => sub { return ["a", ""]} 
3197
});
3198

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3202
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3203
    t => sub {return ["a", []]}
3204
);
3205

            
3206

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

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

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

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

            
3222
test 'variouse source';
3223
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3224
$query = $builder->build_query($source);
3225
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3226

            
3227
$source = "abc";
3228
$query = $builder->build_query($source);
3229
is($query->sql, 'abc', "basic : 2");
3230

            
3231
$source = "{= a}";
3232
$query = $builder->build_query($source);
3233
is($query->sql, 'a = ?', "only tag");
3234

            
3235
$source = "000";
3236
$query = $builder->build_query($source);
3237
is($query->sql, '000', "contain 0 value");
3238

            
3239
$source = "a {= b} }";
3240
eval{$builder->build_query($source)};
3241
like($@, qr/unexpected "}"/, "error : 1");
3242

            
3243
$source = "a {= {}";
3244
eval{$builder->build_query($source)};
3245
like($@, qr/unexpected "{"/, "error : 2");
3246

            
3247
test 'select() sqlfilter option';
3248
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3249
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3250
eval { $dbi->execute("drop table $table1") };
3251
$dbi->execute($create_table1);
3252
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3253
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3254
$rows = $dbi->select(
3255
    table => $table1,
3256
    column => $key1,
3257
    sqlfilter => sub {
3258
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
3259
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
3260
        return $sql;
3261
    }
3262
)->all;
3263
is_deeply($rows, [{$key1 => 1}]);
3264

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3265
test 'select() after_build_sql option';
3266
$dbi = DBIx::Custom->connect;
3267
$dbi->user_table_info($user_table_info);
3268
eval { $dbi->execute("drop table $table1") };
3269
$dbi->execute($create_table1);
3270
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3271
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
3272
$rows = $dbi->select(
3273
    table => $table1,
3274
    column => $key1,
3275
    after_build_sql => sub {
3276
        my $sql = shift;
3277
        $sql = "select * from ( $sql ) t where $key1 = 1";
3278
        return $sql;
3279
    }
3280
)->all;
3281
is_deeply($rows, [{$key1 => 1}]);
3282

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3283
test 'dbi method from model';
3284
$dbi = MyDBI9->connect;
3285
eval { $dbi->execute("drop table $table1") };
3286
$dbi->execute($create_table1);
3287
$dbi->setup_model;
3288
$model = $dbi->model($table1);
3289
eval{$model->execute("select * from $table1")};
3290
ok(!$@);
3291

            
3292
test 'column table option';
3293
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3294
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3295
eval { $dbi->execute("drop table $table1") };
3296
$dbi->execute($create_table1);
3297
eval { $dbi->execute("drop table $table2") };
3298
$dbi->execute($create_table2);
3299
$dbi->setup_model;
3300
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3301
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3302
$model = $dbi->model($table1);
3303
$result = $model->select(
3304
    column => [
3305
        $model->column($table2, {alias => $table2_alias})
3306
    ],
3307
    where => {"$table2_alias.$key3" => 4}
3308
);
3309
is_deeply($result->one, 
3310
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3311

            
3312
$dbi->separator('__');
3313
$result = $model->select(
3314
    column => [
3315
        $model->column($table2, {alias => $table2_alias})
3316
    ],
3317
    where => {"$table2_alias.$key3" => 4}
3318
);
3319
is_deeply($result->one, 
3320
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3321

            
3322
$dbi->separator('-');
3323
$result = $model->select(
3324
    column => [
3325
        $model->column($table2, {alias => $table2_alias})
3326
    ],
3327
    where => {"$table2_alias.$key3" => 4}
3328
);
3329
is_deeply($result->one, 
3330
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3331

            
3332
test 'create_model';
3333
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3334
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3335
eval { $dbi->execute("drop table $table1") };
3336
eval { $dbi->execute("drop table $table2") };
3337
$dbi->execute($create_table1);
3338
$dbi->execute($create_table2);
3339

            
3340
$dbi->create_model(
3341
    table => $table1,
3342
    join => [
3343
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3344
    ],
3345
    primary_key => [$key1]
3346
);
3347
$model2 = $dbi->create_model(
3348
    table => $table2
3349
);
3350
$dbi->create_model(
3351
    table => $table3,
3352
    filter => [
3353
        $key1 => {in => sub { uc $_[0] }}
3354
    ]
3355
);
3356
$dbi->setup_model;
3357
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
3358
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3359
$model = $dbi->model($table1);
3360
$result = $model->select(
3361
    column => [$model->mycolumn, $model->column($table2)],
3362
    where => {"$table1.$key1" => 1}
3363
);
3364
is_deeply($result->one,
3365
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3366
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3367

            
3368
test 'model method';
3369
$dbi = DBIx::Custom->connect;
3370
eval { $dbi->execute("drop table $table2") };
3371
$dbi->execute($create_table2);
3372
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3373
$model = $dbi->create_model(
3374
    table => $table2
3375
);
3376
$model->method(foo => sub { shift->select(@_) });
3377
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3378

            
3379
test 'model helper';
3380
$dbi = DBIx::Custom->connect;
3381
eval { $dbi->execute("drop table $table2") };
3382
$dbi->execute($create_table2);
3383
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3384
$model = $dbi->create_model(
3385
    table => $table2
3386
);
3387
$model->helper(foo => sub { shift->select(@_) });
3388
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3389

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3390
test 'assign_clause';
cleanup test
Yuki Kimoto authored on 2011-08-15
3391
$dbi = DBIx::Custom->connect;
3392
eval { $dbi->execute("drop table $table1") };
3393
$dbi->execute($create_table1_2);
3394
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3395
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
3396

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

            
3410

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

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

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

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

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

            
3453
$dbi = DBIx::Custom->connect;
3454
eval { $dbi->execute("drop table $table1") };
3455
$dbi->execute($create_table1_2);
3456
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5});
3457
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10});
test cleanup
Yuki Kimoto authored on 2011-08-10
3458

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3459
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3460
$assign_clause = $dbi->assign_param($param);
3461
$sql = <<"EOS";
3462
update $table1 set $assign_clause
3463
where $key1 = 1
3464
EOS
3465
$dbi->execute($sql, param => $param, table => $table1);
3466
$result = $dbi->execute("select * from $table1 order by $key1");
3467
$rows   = $result->all;
3468
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3469
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3470
                  "basic");
3471

            
3472
$param = {$key2 => 11};
3473
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3474
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3475
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3476
where $key1 = 1
3477
EOS
3478
$dbi->execute($sql, param => $param, table => $table1);
3479
$result = $dbi->execute("select * from $table1 order by $key1");
3480
$rows   = $result->all;
3481
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3482
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3483
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3484

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3485
test 'Model class';
3486
$dbi = MyDBI1->connect;
3487
eval { $dbi->execute("drop table $table1") };
3488
$dbi->execute($create_table1);
3489
$model = $dbi->model($table1);
3490
$model->insert({$key1 => 'a', $key2 => 'b'});
3491
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3492
eval { $dbi->execute("drop table $table2") };
3493
$dbi->execute($create_table2);
3494
$model = $dbi->model($table2);
3495
$model->insert({$key1 => 'a'});
3496
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3497
is($dbi->models->{$table1}, $dbi->model($table1));
3498
is($dbi->models->{$table2}, $dbi->model($table2));
3499

            
3500
$dbi = MyDBI4->connect;
3501
eval { $dbi->execute("drop table $table1") };
3502
$dbi->execute($create_table1);
3503
$model = $dbi->model($table1);
3504
$model->insert({$key1 => 'a', $key2 => 'b'});
3505
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3506
eval { $dbi->execute("drop table $table2") };
3507
$dbi->execute($create_table2);
3508
$model = $dbi->model($table2);
3509
$model->insert({$key1 => 'a'});
3510
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3511

            
3512
$dbi = MyDBI5->connect;
3513
eval { $dbi->execute("drop table $table1") };
3514
eval { $dbi->execute("drop table $table2") };
3515
$dbi->execute($create_table1);
3516
$dbi->execute($create_table2);
3517
$model = $dbi->model($table2);
3518
$model->insert({$key1 => 'a'});
3519
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3520
$dbi->insert(table => $table1, param => {$key1 => 1});
3521
$model = $dbi->model($table1);
3522
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3523

            
3524
test 'primary_key';
3525
$dbi = MyDBI1->connect;
3526
$model = $dbi->model($table1);
3527
$model->primary_key([$key1, $key2]);
3528
is_deeply($model->primary_key, [$key1, $key2]);
3529

            
3530
test 'columns';
3531
$dbi = MyDBI1->connect;
3532
$model = $dbi->model($table1);
3533
$model->columns([$key1, $key2]);
3534
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3535

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3536
test 'setup_model';
3537
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3538
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3539
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3540
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3541

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3542
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3543
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3544
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3545
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3546
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3547

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3548
test 'each_column';
3549
$dbi = DBIx::Custom->connect;
3550
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3551
eval { $dbi->execute("drop table $table1") };
3552
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3553
eval { $dbi->execute("drop table $table3") };
3554
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3555
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3556

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3584
$infos = [];
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
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3599
);
3600

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3601
$dbi = DBIx::Custom->connect;
3602
eval { $dbi->execute("drop table $table1") };
3603
eval { $dbi->execute("drop table $table2") };
3604
$dbi->execute($create_table2);
3605
$dbi->execute($create_table1_type);
3606

            
3607
$infos = [];
3608
$dbi->user_table_info($user_table_info);
3609
$dbi->each_table(sub {
3610
    my ($self, $table, $table_info) = @_;
3611
    
3612
    if ($table =~ /^table\d/i) {
3613
         my $info = [$table, $table_info->{TABLE_NAME}];
3614
         push @$infos, $info;
3615
    }
3616
});
3617
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3618
is_deeply($infos, 
3619
    [
3620
        [$table1, $table1],
3621
        [$table2, $table2],
3622
        [$table3, $table3],
3623
    ]
3624
);
3625

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3626
test 'type_rule into';
3627
eval { $dbi->execute("drop table $table1") };
3628
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3629
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3630

            
3631

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3632
$dbi = DBIx::Custom->connect;
3633
eval { $dbi->execute("drop table $table1") };
3634
$dbi->execute($create_table1_type);
3635

            
cleanup
Yuki Kimoto authored on 2011-08-16
3636
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3637
$dbi->type_rule(
3638
    into1 => {
3639
        $date_typename => sub { '2010-' . $_[0] }
3640
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3641
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3642
$dbi->insert({$key1 => '01-01'}, table => $table1);
3643
$result = $dbi->select(table => $table1);
3644
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3645

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

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

            
3687
$dbi = DBIx::Custom->connect;
3688
eval { $dbi->execute("drop table $table1") };
3689
$dbi->execute($create_table1_type);
3690
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3691
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3692
$dbi->type_rule(
3693
    into1 => [
3694
        [$date_typename, $datetime_typename] => sub {
3695
            my $value = shift;
3696
            $value =~ s/02/03/g;
3697
            return $value;
3698
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3699
    ]
3700
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3701
$result = $dbi->execute(
3702
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
3703
    param => {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
3704
    table => $table1
3705
);
3706
$row = $result->one;
3707
like($row->{$key1}, qr/^2010-01-03/);
3708
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3709

            
3710
$dbi = DBIx::Custom->connect;
3711
eval { $dbi->execute("drop table $table1") };
3712
$dbi->execute($create_table1_type);
3713
$dbi->register_filter(convert => sub {
3714
    my $value = shift || '';
3715
    $value =~ s/02/03/;
3716
    return $value;
3717
});
cleanup
Yuki Kimoto authored on 2011-08-16
3718
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3719
$dbi->type_rule(
3720
    from1 => {
3721
        $date_datatype => 'convert',
3722
    },
3723
    into1 => {
3724
        $date_typename => 'convert',
3725
    }
3726
);
3727
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3728
$result = $dbi->select(table => $table1);
3729
like($result->fetch->[0], qr/^2010-03-03/);
3730

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

            
3756

            
3757
$dbi = DBIx::Custom->connect;
3758
eval { $dbi->execute("drop table $table1") };
3759
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3760
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3761
$dbi->type_rule(
3762
    from1 => {
3763
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3764
    },
3765
    from2 => {
3766
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3767
    },
3768
);
3769
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3770
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3771
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3772
$result->type_rule(
3773
    from1 => {
3774
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3775
    },
3776
    from2 => {
3777
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3778
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3779
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3780
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3781
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3782

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3783
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
3784
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
3785
eval { $dbi->execute("drop table $table1") };
3786
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3787
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3788
$dbi->type_rule(
3789
    from1 => {
3790
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3791
    },
3792
    into1 => {
3793
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3794
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3795
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3796
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3797
$result = $dbi->select(table => $table1, type_rule_off => 1);
3798
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3799

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3800
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3801
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3802
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3803
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3804
$dbi->type_rule(
3805
    from1 => {
3806
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3807
    },
3808
    into1 => {
3809
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3810
    }
3811
);
3812
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3813
$result = $dbi->select(table => $table1, type_rule_off => 1);
3814
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3815

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

            
3832
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3833
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3834
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3835
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3836
$dbi->type_rule(
3837
    from1 => {
3838
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3839
    },
3840
    into1 => {
3841
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3842
    }
3843
);
3844
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3845
$result = $dbi->select(table => $table1);
3846
like($result->fetch->[0], qr/2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3847

            
3848
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3849
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3850
$dbi->execute($create_table1_type);
3851
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
3852
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3853
$dbi->type_rule(
3854
    into1 => {
3855
        $date_typename => 'ppp'
3856
    }
3857
);
3858
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3859
$result = $dbi->select(table => $table1);
3860
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3861

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3862
eval{$dbi->type_rule(
3863
    into1 => {
3864
        $date_typename => 'pp'
3865
    }
3866
)};
3867
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3868

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3869
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3870
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3871
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3872
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
3873
    $dbi->type_rule(
3874
        from1 => {
3875
            Date => sub { $_[0] * 2 },
3876
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3877
    );
3878
};
cleanup test
Yuki Kimoto authored on 2011-08-15
3879
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3880

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3881
eval {
3882
    $dbi->type_rule(
3883
        into1 => {
3884
            Date => sub { $_[0] * 2 },
3885
        }
3886
    );
3887
};
3888
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3889

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

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

            
3928
$result = $dbi->select(table => $table1);
3929
$result->type_rule(
3930
    from1 => {
3931
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3932
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3933
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3934
$row = $result->one;
3935
like($row->{$key1}, qr/2010-01-05/);
3936
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3937

            
3938
$result = $dbi->select(table => $table1);
3939
$result->type_rule(
3940
    from1 => {
3941
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3942
    }
3943
);
3944
$row = $result->one;
3945
like($row->{$key1}, qr/2010-01-05/);
3946
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3947

            
3948
$result = $dbi->select(table => $table1);
3949
$result->type_rule(
3950
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
3951
);
3952
$row = $result->one;
3953
like($row->{$key1}, qr/2010-01-05/);
3954
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3955

            
3956
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
3957
$result = $dbi->select(table => $table1);
3958
$result->type_rule(
3959
    from1 => [$date_datatype => 'five']
3960
);
3961
$row = $result->one;
3962
like($row->{$key1}, qr/^2010-01-05/);
3963
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3964

            
3965
$result = $dbi->select(table => $table1);
3966
$result->type_rule(
3967
    from1 => [$date_datatype => undef]
3968
);
3969
$row = $result->one;
3970
like($row->{$key1}, qr/^2010-01-03/);
3971
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3972

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3987
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3988
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3989
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3990
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3991
$dbi->type_rule(
3992
    from1 => {
3993
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3994
    },
3995
);
3996
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3997
$result = $dbi->select(table => $table1);
3998
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
3999
like($result->fetch->[0], qr/^2010-01-05/);
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/6/; return $v }
4014
    },
4015
    from2 => {
4016
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4017
    }
4018
);
4019
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4020
$result = $dbi->select(table => $table1);
4021
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/);
4022
$result = $dbi->select(table => $table1);
4023
like($result->type_rule_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/4/; return $v }
4032
    },
4033
    into2 => {
4034
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4035
    },
4036
    from1 => {
4037
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
4038
    },
4039
    from2 => {
4040
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4041
    }
4042
);
4043
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4044
$result = $dbi->select(table => $table1);
4045
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/);
4046
$result = $dbi->select(table => $table1);
4047
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4048

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4049
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4050
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4051
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4052
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4053
$dbi->type_rule(
4054
    into1 => {
4055
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4056
    },
4057
    into2 => {
4058
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4059
    },
4060
    from1 => {
4061
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4062
    },
4063
    from2 => {
4064
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4065
    }
4066
);
4067
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4068
$result = $dbi->select(table => $table1);
4069
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
4070
$result = $dbi->select(table => $table1);
4071
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4072

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4073
test 'join';
4074
$dbi = DBIx::Custom->connect;
4075
eval { $dbi->execute("drop table $table1") };
4076
$dbi->execute($create_table1);
4077
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4078
$dbi->insert(table => $table1, param => {$key1 => 3, $key2 => 4});
4079
eval { $dbi->execute("drop table $table2") };
4080
$dbi->execute($create_table2);
4081
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4082
eval { $dbi->execute("drop table $table3") };
4083
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
4084
$dbi->insert(table => $table3, param => {$key3 => 5, $key4 => 4});
4085
$rows = $dbi->select(
4086
    table => $table1,
4087
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4088
    where   => {"$table1.$key2" => 2},
4089
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4090
)->all;
4091
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
4092

            
4093
$rows = $dbi->select(
4094
    table => $table1,
4095
    where   => {$key1 => 1},
4096
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4097
)->all;
4098
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4099

            
4100
$rows = $dbi->select(
4101
    table => $table1,
4102
    where   => {$key1 => 1},
4103
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4104
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4105
)->all;
4106
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4107

            
4108
$rows = $dbi->select(
4109
    column => "$table3.$key4 as ${table3}__$key4",
4110
    table => $table1,
4111
    where   => {"$table1.$key1" => 1},
4112
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4113
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4114
)->all;
4115
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4116

            
4117
$rows = $dbi->select(
4118
    column => "$table1.$key1 as ${table1}__$key1",
4119
    table => $table1,
4120
    where   => {"$table3.$key4" => 4},
4121
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4122
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4123
)->all;
4124
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4125

            
4126
$dbi = DBIx::Custom->connect;
4127
eval { $dbi->execute("drop table $table1") };
4128
$dbi->execute($create_table1);
4129
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4130
eval { $dbi->execute("drop table $table2") };
4131
$dbi->execute($create_table2);
4132
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4133
$rows = $dbi->select(
4134
    table => $table1,
4135
    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",
4136
    where   => {"$table1.$key2" => 2},
4137
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4138
)->all;
4139
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4140
          'quote');
4141

            
4142

            
4143
$dbi = DBIx::Custom->connect;
4144
eval { $dbi->execute("drop table $table1") };
4145
$dbi->execute($create_table1);
4146
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4147
$sql = <<"EOS";
4148
left outer join (
4149
  select * from $table1 t1
4150
  where t1.$key2 = (
4151
    select max(t2.$key2) from $table1 t2
4152
    where t1.$key1 = t2.$key1
4153
  )
4154
) $table3 on $table1.$key1 = $table3.$key1
4155
EOS
4156
$join = [$sql];
4157
$rows = $dbi->select(
4158
    table => $table1,
4159
    column => "$table3.$key1 as ${table3}__$key1",
4160
    join  => $join
4161
)->all;
4162
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4163

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

            
4196
$dbi = DBIx::Custom->connect;
4197
eval { $dbi->execute("drop table $table1") };
4198
eval { $dbi->execute("drop table $table2") };
4199
$dbi->execute($create_table1);
4200
$dbi->execute($create_table2);
4201
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4202
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4203
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 5});
4204
$result = $dbi->select(
4205
    table => $table1,
4206
    column => [{$table2 => [$key3]}],
4207
    join => [
4208
        {
4209
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4210
            table => [$table1, $table2]
4211
        }
4212
    ]
4213
);
4214
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4215

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4216
$dbi = DBIx::Custom->connect;
4217
eval { $dbi->execute("drop table $table1") };
4218
eval { $dbi->execute("drop table $table2") };
4219
$dbi->execute($create_table1);
4220
$dbi->execute($create_table2);
4221
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4222
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4223
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4224
$result = $dbi->select(
4225
    table => $table1,
4226
    column => [{$table2 => [$key3]}],
4227
    join => [
4228
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4229
    ]
4230
);
4231
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4232

            
4233
$dbi = DBIx::Custom->connect;
4234
eval { $dbi->execute("drop table $table1") };
4235
eval { $dbi->execute("drop table $table2") };
4236
$dbi->execute($create_table1);
4237
$dbi->execute($create_table2);
4238
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4239
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
4240
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
4241
$result = $dbi->select(
4242
    table => $table1,
4243
    column => [{$table2 => [$key3]}],
4244
    join => [
4245
        "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4246
    ]
4247
);
4248
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4249

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4250
test 'columns';
4251
$dbi = MyDBI1->connect;
4252
$model = $dbi->model($table1);
4253

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4254
test 'count';
4255
$dbi = DBIx::Custom->connect;
4256
eval { $dbi->execute("drop table $table1") };
4257
$dbi->execute($create_table1);
4258
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
4259
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 3});
4260
is($dbi->count(table => $table1), 2);
4261
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4262
$model = $dbi->create_model(table => $table1);
4263
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4264

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