DBIx-Custom / t / common.t /
Newer Older
4546 lines | 152.292kb
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;
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
84
my $affected;
cleanup test
Yuki Kimoto authored on 2011-08-15
85

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

            
90
    use strict;
91
    use warnings;
92

            
93
    use base 'DBIx::Custom';
94

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

            
106
    package MyModel2::Base1;
107

            
108
    use strict;
109
    use warnings;
110

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

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

            
115
    use strict;
116
    use warnings;
117

            
118
    use base 'MyModel2::Base1';
119

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

            
126
    sub list { shift->select; }
127

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

            
130
    use strict;
131
    use warnings;
132

            
133
    use base 'MyModel2::Base1';
134

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

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

            
143
    package MyModel2::TABLE1;
144

            
145
    use strict;
146
    use warnings;
147

            
148
    use base 'MyModel2::Base1';
149

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

            
156
    sub list { shift->select; }
157

            
158
    package MyModel2::TABLE2;
159

            
160
    use strict;
161
    use warnings;
162

            
163
    use base 'MyModel2::Base1';
164

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

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

            
176
    use strict;
177
    use warnings;
178

            
179
    use base 'DBIx::Custom';
180

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
495
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
496
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
497
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
test cleanup
Yuki Kimoto authored on 2011-11-01
498
$dbi->insert({select => 1}, table => 'table');
cleanup test
Yuki Kimoto authored on 2011-08-10
499
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
500
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
501
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
cleanup test
Yuki Kimoto authored on 2011-08-10
502

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
655
eval {
656
    $dbi->insert({$key1 => 1}, table => $table1);
657
    $dbi->update_or_insert(
658
        {$key2 => 3},
659
        table => $table1,
660
        primary_key => $key1,
661
        id => 1
662
    );
663
};
664
like($@, qr/one/);
665

            
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
666
eval { $dbi->execute("drop table $table1") };
667
$dbi->execute($create_table1);
668
$dbi->update_or_insert(
669
    {},
670
    table => $table1,
671
    primary_key => $key1,
672
    id => 1
673
);
674
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
675
is($row->{$key1}, 1);
676

            
677
eval { 
678
    $affected = $dbi->update_or_insert(
679
        {},
680
        table => $table1,
681
        primary_key => $key1,
682
        id => 1
683
    );
684
};
685
is($affected, 0);
686

            
micro optimization
Yuki Kimoto authored on 2011-10-31
687
test 'model update_or_insert';
688
eval { $dbi->execute("drop table $table1") };
689
$dbi->execute($create_table1);
690
$model = $dbi->create_model(
691
    table => $table1,
692
    primary_key => $key1
693
);
694
$model->update_or_insert({$key2 => 2}, id => 1);
695
$row = $model->select(id => 1)->one;
696
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
697

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
698
eval {
699
    $model->insert({$key1 => 1});
700
    $model->update_or_insert(
701
        {$key2 => 3},
702
        id => 1
703
    );
704
};
705
like($@, qr/one/);
706

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
707
test 'default_bind_filter';
708
$dbi->execute("delete from $table1");
709
$dbi->register_filter(
710
    twice       => sub { $_[0] * 2 },
711
    three_times => sub { $_[0] * 3 }
712
);
713
$dbi->default_bind_filter('twice');
cleanup
Yuki Kimoto authored on 2011-11-01
714
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
715
$result = $dbi->execute("select * from $table1");
716
$rows   = $result->all;
717
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
718
$dbi->default_bind_filter(undef);
719

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

            
732
eval { $dbi->execute("drop table $table1") };
733
$dbi->execute($create_table1_2);
734
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
735
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
736
$dbi->update(param => {$key2 => 11}, table => $table1, where => {$key1 => 1});
737
$result = $dbi->execute("select * from $table1 order by $key1");
738
$rows   = $result->all;
739
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
740
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
741
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
742
                  
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
743
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
744
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
745
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
746
$dbi->update({$key2 => 12}, table => $table1, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
747
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
748
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
749
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
750
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
751
                  "update key same as search key");
752

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
760
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
761
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
762
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
763
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
764
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
765
              filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
766
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
767
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
768
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
769
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
770
                  "filter");
771

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
777
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
778
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
779
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
780
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
781
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
782
$where->param({$key1 => 1, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
783
$dbi->update({$key1 => 3}, table => $table1, where => $where);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
784
$result = $dbi->select(table => $table1);
785
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
786

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
787
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
788
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
789
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
790
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
791
    {$key1 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
792
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
793
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
794
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
795
        {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
796
    ]
797
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
798
$result = $dbi->select(table => $table1);
799
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
800

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
801
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
802
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
803
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
804
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
805
$where->clause(['and', "$key2 = :$key2"]);
806
$where->param({$key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
807
$dbi->update({$key1 => 3}, table => $table1, where => $where);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
808
$result = $dbi->select(table => $table1);
809
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
810

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
817
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
818
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
819
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
820
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
821
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
822
$dbi->insert({select => 1}, table => 'table');
823
$dbi->update({update => 2}, table => 'table', where => {select => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
824
$result = $dbi->execute("select * from ${q}table$p");
825
$rows   = $result->all;
826
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
827

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

            
831
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
832
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
833
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
834
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
835
$dbi->insert({select => 1}, table => 'table');
836
$dbi->update({update => 2}, table => 'table', where => {'table.select' => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
837
$result = $dbi->execute("select * from ${q}table$p");
838
$rows   = $result->all;
839
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
840

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
841
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
842
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
843
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
844
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
845
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
846
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
847
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
848
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
849
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
850
                  "basic");
851

            
updated pod
Yuki Kimoto authored on 2011-09-02
852
eval { $dbi->execute("drop table $table1") };
853
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
854
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
855
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
856
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
updated pod
Yuki Kimoto authored on 2011-09-02
857
wrap => {$key2 => sub { "$_[0] - 1" }});
858
$result = $dbi->execute("select * from $table1 order by $key1");
859
$rows   = $result->all;
860
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5},
861
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
862
                  "basic");
863

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
864
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
865
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
866
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
867
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
868
$dbi->update({$key2 => \"'11'"}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
869
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
870
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
871
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
872
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
873
                  "basic");
874

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
875
eval { $dbi->execute("drop table $table1") };
876
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
877
$dbi->update_timestamp(
878
    $key1 => '5'
879
);
test cleanup
Yuki Kimoto authored on 2011-11-01
880
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
881
$dbi->update(table => $table1, timestamp => 1, where => {$key2 => 2});
882
$result = $dbi->execute("select * from $table1");
883
$rows   = $result->all;
884
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
885

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
886
eval { $dbi->execute("drop table $table1") };
887
$dbi->execute($create_table1);
888
$dbi->update_timestamp(
889
    [$key1, $key2] => sub { '5' }
890
);
test cleanup
Yuki Kimoto authored on 2011-11-01
891
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
892
$dbi->update_all(table => $table1, timestamp => 1);
893
$result = $dbi->execute("select * from $table1");
894
$rows   = $result->all;
895
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
896

            
897
eval { $dbi->execute("drop table $table1") };
898
$dbi->execute($create_table1);
899
$dbi->update_timestamp(
900
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
901
);
test cleanup
Yuki Kimoto authored on 2011-11-01
902
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
903
$dbi->update_all(table => $table1, timestamp => 1);
904
$result = $dbi->execute("select * from $table1");
905
$rows   = $result->all;
906
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
907

            
micro optimization and
Yuki Kimoto authored on 2011-10-25
908
eval { $dbi->execute("drop table $table1") };
909
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
910
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
911
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
912
$param = {$key2 => 11};
913
$dbi->update($param, table => $table1, where => {$key1 => 1});
914
is_deeply($param, {$key2 => 11});
915
$result = $dbi->execute("select * from $table1 order by $key1");
916
$rows   = $result->all;
917
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
918
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
919
                  "basic");
920

            
921
eval { $dbi->execute("drop table $table1") };
922
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
923
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
924
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
925
$param = {$key2 => 11};
926
$dbi->update($param, table => $table1, where => {$key2 => 2});
927
is_deeply($param, {$key2 => 11});
928
$result = $dbi->execute("select * from $table1 order by $key1");
929
$rows   = $result->all;
930
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
931
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
932
                  "basic");
933

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
934
eval { $dbi->execute("drop table $table1") };
935
$dbi->execute($create_table1_2);
936
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
937
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
938
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key1 => 1});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
939
$result = $dbi->select(table => $table1);
940
is_deeply($param, {$key3 => 4});
941
$row   = $result->one;
942
is($row->{$key3}, 4);
943
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
944

            
945
eval { $dbi->execute("drop table $table1") };
946
$dbi->execute($create_table1_2);
947
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
948
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
949
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key3 => 3});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
950
$result = $dbi->select(table => $table1);
951
is_deeply($param, {$key3 => 4});
952
$row   = $result->one;
953
is($row->{$key3}, 4);
954
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
955

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
956
eval { $dbi->execute("drop table $table1") };
957
$dbi->execute($create_table1_2);
958
$model = $dbi->create_model(table => $table1, updated_at => $key2);
959
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
960
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
961
$model->update($param, where => {$key1 => 1});
962
$result = $dbi->select(table => $table1);
963
is_deeply($param, {$key3 => 4});
964
$row   = $result->one;
965
is($row->{$key3}, 4);
966
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
967

            
test cleanup
Yuki Kimoto authored on 2011-08-10
968
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
969
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
970
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
971
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
972
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
973
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
974
$dbi->update_all({$key2 => 10}, table => $table1, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
975
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
976
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
977
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
978
                  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
979
                  "filter");
980

            
981

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
992
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
993
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
994
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
995
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
996
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
997
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
998
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
999
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1000

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1003
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1004
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1005
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1006
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
1007
$rows = $dbi->select(table => $table1)->all;
1008
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1009

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1035
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1036
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1037
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1038
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
1039
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1040
$rows   = $result->all;
1041
is_deeply($rows, [], "basic");
1042

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

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

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

            
1063
test 'delete_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1064
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1065
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1066
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1067
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1068
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1069
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1070
$rows   = $result->all;
1071
is_deeply($rows, [], "basic");
1072

            
1073

            
1074
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1075
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1076
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1077
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1078
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1079
$rows = $dbi->select(table => $table1)->all;
1080
is_deeply($rows, [{$key1 => 1, $key2 => 2},
1081
                  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
1082

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1097
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1098
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
1099
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1100
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1101
    table => [$table1, $table2],
1102
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
1103
    where   => {"$table1.$key2" => 2},
1104
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1105
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1106
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
1107

            
1108
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1109
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1110
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1111
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1112
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1113
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
1114

            
1115
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
1116
eval { $dbi->execute("drop table ${q}table$p") };
1117
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1118
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1119
$dbi->insert({select => 1, update => 2}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1120
$result = $dbi->select(table => 'table', where => {select => 1});
1121
$rows   = $result->all;
1122
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
1123

            
1124
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1125
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1126
$dbi->register_filter(
1127
    twice       => sub { $_[0] * 2 },
1128
    three_times => sub { $_[0] * 3 }
1129
);
1130
$dbi->default_fetch_filter('twice');
1131
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1132
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1133
$result = $dbi->select(table => $table1);
1134
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1135
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1136
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1137

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1138
$dbi->default_fetch_filter('twice');
1139
eval { $dbi->execute("drop table $table1") };
1140
$dbi->execute($create_table1);
1141
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1142
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1143
$result->filter({$key1 => 'three_times'});
1144
$row = $result->fetch_first;
1145
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter");
1146

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1147
test 'filters';
1148
$dbi = DBIx::Custom->new;
1149

            
1150
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
1151
   'あ', "decode_utf8");
1152

            
1153
is($dbi->filters->{encode_utf8}->('あ'),
1154
   encode_utf8('あ'), "encode_utf8");
1155

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1156
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1157
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1158
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1159
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1160
$dbi->begin_work;
1161
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1162
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1163
$dbi->rollback;
1164
$dbi->dbh->{AutoCommit} = 1;
1165

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

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

            
1170
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1171
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1172
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1173
$dbi->begin_work;
1174
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1175
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1176
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1177
$dbi->commit;
1178
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1179
$result = $dbi->select(table => $table1);
1180
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1181
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1182

            
1183
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1184
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1185
$dbi->execute($create_table1);
1186
{
1187
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1188
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1189
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1190
    like($@, qr/\.t /, "fail : not verbose");
1191
}
1192
{
1193
    local $Carp::Verbose = 1;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1194
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1195
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1196
}
1197

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

            
1203
{
1204
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1205
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1206
    like($@, qr/\Q.t /, "caller spec : not vebose");
1207
}
1208
{
1209
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1210
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1211
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1212
}
1213

            
1214

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1215
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1216
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1217
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1218
$dbi->execute($create_table1);
1219

            
1220
$dbi->begin_work;
1221

            
1222
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1223
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1224
    die "Error";
test cleanup
Yuki Kimoto authored on 2011-11-01
1225
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1226
};
1227

            
1228
$dbi->rollback if $@;
1229

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

            
1234
$dbi->begin_work;
1235

            
1236
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1237
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1238
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1239
};
1240

            
1241
$dbi->commit unless $@;
1242

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

            
1247
$dbi->dbh->{AutoCommit} = 0;
1248
eval{ $dbi->begin_work };
1249
ok($@, "exception");
1250
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1251

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1252
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1253
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1254
$dbi->cache(1);
1255
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1256
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1257
$dbi->execute($source, {}, query => 1);
1258
is_deeply($dbi->{_cached}->{$source}, 
cleanup test
Yuki Kimoto authored on 2011-08-15
1259
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1260

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1261
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1262
$dbi->execute($create_table1);
1263
$dbi->{_cached} = {};
1264
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1265
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1266
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1267

            
1268
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1269
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1270
$dbi->execute($create_table1);
1271
{
1272
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1273
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1274
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1275
    like($@, qr/\.t /, "fail : not verbose");
1276
}
1277
{
1278
    local $Carp::Verbose = 1;
- removed argument checking ...
Yuki Kimoto authored on 2011-10-21
1279
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1280
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1281
}
1282

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

            
1288
{
1289
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1290
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1291
    like($@, qr/\Q.t /, "caller spec : not vebose");
1292
}
1293
{
1294
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1295
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1296
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1297
}
1298

            
1299
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1300
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1301
    one => sub { 1 }
1302
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1303
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1304
    two => sub { 2 }
1305
);
1306
$dbi->method({
1307
    twice => sub {
1308
        my $self = shift;
1309
        return $_[0] * 2;
1310
    }
1311
});
1312

            
1313
is($dbi->one, 1, "first");
1314
is($dbi->two, 2, "second");
1315
is($dbi->twice(5), 10 , "second");
1316

            
1317
eval {$dbi->XXXXXX};
1318
ok($@, "not exists");
1319

            
1320
test 'out filter';
1321
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1322
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1323
$dbi->execute($create_table1);
1324
$dbi->register_filter(twice => sub { $_[0] * 2 });
1325
$dbi->register_filter(three_times => sub { $_[0] * 3});
1326
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1327
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1328
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
1329
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1330
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1331
$row   = $result->fetch_hash_first;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1332
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1333
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1334
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1335
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1336

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

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

            
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);
1369
$dbi->register_filter(twice => sub { $_[0] * 2 });
1370
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1371
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1372
);
cleanup
Yuki Kimoto authored on 2011-11-01
1373
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1=> undef});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1374
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1375
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1376
$rows   = $result->all;
1377
is_deeply($rows, [], "delete");
1378

            
1379
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1380
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1381
$dbi->execute($create_table1);
1382
$dbi->register_filter(twice => sub { $_[0] * 2 });
1383
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1384
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1385
);
cleanup
Yuki Kimoto authored on 2011-11-01
1386
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1387
$result = $dbi->select(table => $table1, where => {$key1 => 1});
1388
$result->filter({$key2 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1389
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1390
is_deeply($rows, [{$key1 => 4, $key2 => 4}], "select");
test cleanup
Yuki Kimoto authored on 2011-08-10
1391

            
1392
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1393
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1394
$dbi->execute($create_table1);
1395
$dbi->register_filter(twice => sub { $_[0] * 2 });
1396
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1397
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1398
);
cleanup
Yuki Kimoto authored on 2011-11-01
1399
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1400
$result = $dbi->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
1401
                        {$key1 => 1, $key2 => 2},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1402
                        table => [$table1]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1403
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1404
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute");
test cleanup
Yuki Kimoto authored on 2011-08-10
1405

            
1406
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1407
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1408
$dbi->execute($create_table1);
1409
$dbi->register_filter(twice => sub { $_[0] * 2 });
1410
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1411
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1412
);
cleanup
Yuki Kimoto authored on 2011-11-01
1413
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1414
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
1415
                        {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1416
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1417
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1418

            
1419
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1420
eval { $dbi->execute("drop table $table1") };
1421
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1422
$dbi->execute($create_table1);
1423
$dbi->execute($create_table2);
1424
$dbi->register_filter(twice => sub { $_[0] * 2 });
1425
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1426
$dbi->apply_filter(
cleanup test
Yuki Kimoto authored on 2011-08-15
1427
    $table1, $key2 => {out => 'twice', in => 'twice'}
1428
);
1429
$dbi->apply_filter(
1430
    $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1431
);
cleanup
Yuki Kimoto authored on 2011-11-01
1432
$dbi->insert({$key1 => 5, $key2 => 2}, table => $table1, filter => {$key2 => undef});
1433
$dbi->insert({$key1 => 5, $key3 => 6}, table => $table2, filter => {$key3 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1434
$result = $dbi->select(
1435
     table => [$table1, $table2],
1436
     column => [$key2, $key3],
1437
     where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1438

            
1439
$result->filter({$key2 => 'twice'});
1440
$rows   = $result->all;
1441
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1442

            
1443
$result = $dbi->select(
1444
     table => [$table1, $table2],
1445
     column => [$key2, $key3],
1446
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1447

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

            
1452
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1453
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1454
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1455
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1456
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1457
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1458

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1459
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1460
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1461
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1462
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1463
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1464
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1465

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

            
1472
test 'end_filter';
1473
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1474
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1475
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1476
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1477
$result = $dbi->select(table => $table1);
1478
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1479
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1480
$row = $result->fetch_first;
1481
is_deeply($row, [6, 40]);
1482

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1483
$dbi = DBIx::Custom->connect;
1484
eval { $dbi->execute("drop table $table1") };
1485
$dbi->execute($create_table1);
1486
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1487
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1488
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1489
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
1490
$row = $result->fetch_first;
1491
is_deeply($row, [6, 6, 40]);
1492

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1493
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1494
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1495
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1496
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1497
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1498
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1499
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1500
$row = $result->fetch_first;
1501
is_deeply($row, [6, 12]);
1502

            
1503
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1504
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1505
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1506
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1507
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1508
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1509
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1510
$row = $result->fetch_first;
1511
is_deeply($row, [6, 12]);
1512

            
1513
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1514
$result = $dbi->select(table => $table1);
1515
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1516
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1517
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1518
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1519

            
1520
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1521
$dbi->apply_filter($table1,
1522
    $key1 => {end => sub { $_[0] * 3 } },
1523
    $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1524
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1525
$result = $dbi->select(table => $table1);
1526
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1527
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1528
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1529

            
1530
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1531
$dbi->apply_filter($table1,
1532
    $key1 => {end => sub { $_[0] * 3 } },
1533
    $key2 => {end => 'five_times'}
1534
);
1535
$result = $dbi->select(table => $table1);
1536
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1537
$result->filter($key1 => undef);
1538
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1539
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1540
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1541

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1542
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1543
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1544
$result->filter($key1 => undef);
1545
$result->end_filter($key1 => undef);
1546
$row = $result->fetch;
1547
is_deeply($row, [1, 1, 40], 'apply_filter overwrite');
1548

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1549
test 'remove_end_filter and remove_filter';
1550
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1551
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1552
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1553
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1554
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1555
$row = $result
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1556
       ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1557
       ->remove_filter
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1558
       ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1559
       ->remove_end_filter
1560
       ->fetch_first;
1561
is_deeply($row, [1, 2]);
1562

            
1563
test 'empty where select';
1564
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1565
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1566
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1567
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1568
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1569
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1570
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1571

            
1572
test 'select query option';
1573
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1574
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1575
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1576
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1577
ok(ref $query);
cleanup
Yuki Kimoto authored on 2011-11-01
1578
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1579
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1580
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1581
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1582
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1583
ok(ref $query);
test cleanup
Yuki Kimoto authored on 2011-08-10
1584

            
1585
test 'where';
1586
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1587
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1588
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1589
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1590
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1591
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1592
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
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", "$key2 = :$key2"])
1596
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1597

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

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

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

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

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

            
1645
$where = $dbi->where;
1646
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1647
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1648
    where => $where
1649
);
1650
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1651
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1652

            
1653
eval {
1654
$where = $dbi->where
1655
             ->clause(['uuu']);
1656
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1657
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1658
    where => $where
1659
);
1660
};
1661
ok($@);
1662

            
1663
$where = $dbi->where;
1664
is("$where", '');
1665

            
1666
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1667
             ->clause(['or', ("$key1 = :$key1") x 2])
1668
             ->param({$key1 => [1, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1669
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1670
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1671
    where => $where,
1672
);
1673
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1674
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
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
             ->clause(['or', ("$key1 = :$key1") x 2])
1678
             ->param({$key1 => [1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1679
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1680
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1681
    where => $where,
1682
);
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
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1687
             ->clause(['or', ("$key1 = :$key1") x 2])
1688
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1689
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1690
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1691
    where => $where,
1692
);
1693
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1694
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1695

            
1696
$where = $dbi->where
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1697
             ->clause("$key1 = :$key1")
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1698
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1699
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1700
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1701
    where => $where,
1702
);
1703
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1704
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1705

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

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

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

            
1736
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1737
             ->clause(['or', ("$key1 = :$key1") x 3])
1738
             ->param({$key1 => [1, $dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1739
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1740
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1741
    where => $where,
1742
);
1743
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1744
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1745

            
1746
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1747
             ->clause(['or', ("$key1 = :$key1") x 3])
1748
             ->param({$key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1749
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1750
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1751
    where => $where,
1752
);
1753
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1754
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1755

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

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

            
1776
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1777
             ->clause(['or', ("$key1 = :$key1") x 3])
1778
             ->param({$key1 => []});
test cleanup
Yuki Kimoto authored on 2011-08-10
1779
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1780
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1781
    where => $where,
1782
);
1783
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1784
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1785

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

            
1796
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1797
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1798
             ->param({$key1 => [$dbi->not_exists, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1799
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1800
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1801
    where => $where,
1802
);
1803
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1804
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1805

            
1806
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1807
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1808
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1809
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1810
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1811
    where => $where,
1812
);
1813
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1814
is_deeply($row, [{$key1 => 1, $key2 => 2},{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1815

            
1816
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1817
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1818
             ->param({$key1 => [0, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1819
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1820
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1821
    where => $where,
1822
);
1823
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1824
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1825

            
1826
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1827
             ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1828
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1829
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1830
    where => $where,
1831
);
1832
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1833
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1834

            
1835
eval {$dbi->where(ppp => 1) };
1836
like($@, qr/invalid/);
1837

            
1838
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1839
    clause => ['and', ['or'], ['and', "$key1 = :$key1", "$key2 = :$key2"]],
1840
    param => {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
1841
);
1842
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1843
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1844
    where => $where,
1845
);
1846
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1847
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1848

            
1849

            
1850
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1851
    clause => ['and', ['or'], ['or', ":$key1", ":$key2"]],
test cleanup
Yuki Kimoto authored on 2011-08-10
1852
    param => {}
1853
);
1854
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1855
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1856
    where => $where,
1857
);
1858
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1859
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1860

            
1861
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1862
$where->clause(['and', ":${key1}{=}"]);
1863
$where->param({$key1 => undef});
1864
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1865
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1866
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1867

            
1868
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1869
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1870
$where->param({$key1 => [undef, undef]});
1871
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1872
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1873
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1874
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1875
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1876
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1877

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

            
1879
$dbi = DBIx::Custom->connect;
1880
eval { $dbi->execute("drop table $table1") };
1881
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1882
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
1883
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1884
$where = $dbi->where
1885
             ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
1886
             ->param({$key1 => 1});
1887

            
1888
$result = $dbi->select(
1889
    table => $table1,
1890
    where => $where
1891
);
1892
$row = $result->all;
1893
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
1894

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1895
test 'register_tag_processor';
1896
$dbi = DBIx::Custom->connect;
1897
$dbi->register_tag_processor(
1898
    a => sub { 1 }
1899
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1900
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1901

            
1902
test 'register_tag';
1903
$dbi = DBIx::Custom->connect;
1904
$dbi->register_tag(
1905
    b => sub { 2 }
1906
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1907
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1908

            
1909
test 'table not specify exception';
1910
$dbi = DBIx::Custom->connect;
1911
eval {$dbi->select};
1912
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1913

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1914
test 'more tests';
1915
$dbi = DBIx::Custom->connect;
1916
eval{$dbi->apply_filter('table', 'column', [])};
1917
like($@, qr/apply_filter/);
1918

            
1919
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1920
like($@, qr/apply_filter/);
1921

            
1922
$dbi->apply_filter(
1923

            
1924
);
1925
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1926
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1927
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1928
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1929
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1930
$dbi->apply_filter($table1, $key2, 
test cleanup
Yuki Kimoto authored on 2011-08-10
1931
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1932
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
1933
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1934

            
1935
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1936
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1937
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1938
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1939
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1940
$dbi->apply_filter($table1, $key2, {});
1941
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1942
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1943

            
1944
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1945
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1946
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1947
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1948
like($@, qr/not registered/);
1949
$dbi->method({one => sub { 1 }});
1950
is($dbi->one, 1);
1951

            
1952
eval{DBIx::Custom->connect(dsn => undef)};
1953
like($@, qr/_connect/);
1954

            
1955
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1956
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1957
$dbi->execute($create_table1);
1958
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
1959
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1960
             filter => {$key1 => 'twice'});
1961
$row = $dbi->select(table => $table1)->one;
1962
is_deeply($row, {$key1 => 2, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
1963
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1964
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
1965
like($@, qr//);
1966

            
1967
$dbi->register_filter(one => sub { });
1968
$dbi->default_fetch_filter('one');
1969
ok($dbi->default_fetch_filter);
1970
$dbi->default_bind_filter('one');
1971
ok($dbi->default_bind_filter);
1972
eval{$dbi->default_fetch_filter('no')};
1973
like($@, qr/not registered/);
1974
eval{$dbi->default_bind_filter('no')};
1975
like($@, qr/not registered/);
1976
$dbi->default_bind_filter(undef);
1977
ok(!defined $dbi->default_bind_filter);
1978
$dbi->default_fetch_filter(undef);
1979
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1980
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1981
like($@, qr/Tag not finished/);
1982

            
1983
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1984
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1985
$dbi->execute($create_table1);
1986
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1987
$result = $dbi->select(table => $table1);
1988
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1989
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1990
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1991
like($@, qr/not registered/);
1992
$result->default_filter(undef);
1993
ok(!defined $result->default_filter);
1994
$result->default_filter('one');
1995
is($result->default_filter->(), 1);
1996

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1997
test 'option';
1998
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
1999
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
2000
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2001
ok($dbi->dbh->{PrintError});
2002
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2003
ok($dbi->dbh->{PrintError});
2004

            
2005
test 'DBIx::Custom::Result stash()';
2006
$result = DBIx::Custom::Result->new;
2007
is_deeply($result->stash, {}, 'default');
2008
$result->stash->{foo} = 1;
2009
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2010

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

            
cleanup
Yuki Kimoto authored on 2011-11-01
2023
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2024
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2025
    table => $table1,
2026
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2027
    where => 1,
2028
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2029
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2030

            
2031
test 'insert_at';
2032
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2033
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2034
$dbi->execute($create_table1_2);
2035
$dbi->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2036
    {$key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2037
    primary_key => [$key1, $key2], 
2038
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2039
    where => [1, 2],
2040
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2041
is($dbi->select(table => $table1)->one->{$key1}, 1);
2042
is($dbi->select(table => $table1)->one->{$key2}, 2);
2043
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2044

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2045
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2046
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2047
$dbi->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2048
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2049
    primary_key => $key1, 
2050
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2051
    where => 1,
2052
);
2053

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

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

            
2071
test 'update_at';
2072
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2073
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2074
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2075
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2076
$dbi->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2077
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2078
    table => $table1,
2079
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2080
    where => [1, 2],
2081
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2082
is($dbi->select(table => $table1)->one->{$key1}, 1);
2083
is($dbi->select(table => $table1)->one->{$key2}, 2);
2084
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2085

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2086
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2087
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2088
$dbi->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2089
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2090
    table => $table1,
2091
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2092
    where => 1,
2093
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2094
is($dbi->select(table => $table1)->one->{$key1}, 1);
2095
is($dbi->select(table => $table1)->one->{$key2}, 2);
2096
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2097

            
2098
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2099
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2100
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2101
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2102
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2103
    {$key3 => 4},
2104
    table => $table1,
2105
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2106
    where => [1, 2]
2107
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2108
is($dbi->select(table => $table1)->one->{$key1}, 1);
2109
is($dbi->select(table => $table1)->one->{$key2}, 2);
2110
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2111

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2127
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2128
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2129
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2130
    table => $table1,
2131
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2132
    where => 1,
2133
);
2134
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2135
is($row->{$key1}, 1);
2136
is($row->{$key2}, 2);
2137
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2138

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2139
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2140
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2141
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2142
    table => $table1,
2143
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2144
    where => [1, 2]
2145
);
2146
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2147
is($row->{$key1}, 1);
2148
is($row->{$key2}, 2);
2149
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2150

            
2151
test 'model delete_at';
2152
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2153
eval { $dbi->execute("drop table $table1") };
2154
eval { $dbi->execute("drop table $table2") };
2155
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2156
$dbi->execute($create_table1_2);
2157
$dbi->execute($create_table2_2);
2158
$dbi->execute($create_table3);
test cleanup
Yuki Kimoto authored on 2011-11-01
2159
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2160
$dbi->model($table1)->delete_at(where => [1, 2]);
2161
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2162
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2163
$dbi->model($table1)->delete_at(where => [1, 2]);
2164
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2165
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2166
$dbi->model($table3)->delete_at(where => [1, 2]);
2167
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2168

            
2169
test 'model insert_at';
2170
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2171
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2172
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2173
$dbi->model($table1)->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2174
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2175
    where => [1, 2],
2176
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2177
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2178
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2179
is($row->{$key1}, 1);
2180
is($row->{$key2}, 2);
2181
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2182

            
2183
test 'model update_at';
2184
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2185
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2186
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2187
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2188
$dbi->model($table1)->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2189
    {$key3 => 4},
cleanup test
Yuki Kimoto authored on 2011-08-10
2190
    where => [1, 2],
2191
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2192
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2193
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2194
is($row->{$key1}, 1);
2195
is($row->{$key2}, 2);
2196
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2197

            
2198
test 'model select_at';
2199
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2200
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2201
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2202
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2203
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2204
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2205
is($row->{$key1}, 1);
2206
is($row->{$key2}, 2);
2207
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2208

            
2209

            
2210
test 'mycolumn and column';
2211
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2212
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2213
eval { $dbi->execute("drop table $table1") };
2214
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2215
$dbi->execute($create_table1);
2216
$dbi->execute($create_table2);
2217
$dbi->separator('__');
2218
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2219
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2220
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2221
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2222
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2223
    column => [$model->mycolumn, $model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2224
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2225
);
2226
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2227
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2228

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2229
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2230
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2231
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2232
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2233
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2234
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2235
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2236
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2237
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2238
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2239
is($dbi->select(table => $table1)->one->{$key1}, 1);
2240
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2241

            
2242
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2243
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2244
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2245
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2246
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2247
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2248
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2249
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2250
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2251
is($dbi->select(table => $table1)->one->{$key1}, 1);
2252
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2253

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2254
test 'mycolumn';
2255
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2256
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2257
eval { $dbi->execute("drop table $table1") };
2258
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2259
$dbi->execute($create_table1);
2260
$dbi->execute($create_table2);
2261
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2262
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2263
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2264
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2265
$result = $model->select_at(
2266
    column => [
2267
        $model->mycolumn,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2268
        $model->column($table2)
cleanup test
Yuki Kimoto authored on 2011-08-10
2269
    ]
2270
);
2271
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2272
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2273

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

            
2291
$result = $model->select_at(
2292
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2293
        $model->mycolumn([$key1]),
2294
        ["$table2.$key1", as => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2295
    ]
2296
);
2297
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2298
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2299

            
2300
$result = $model->select_at(
2301
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2302
        $model->mycolumn([$key1]),
2303
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2304
    ]
2305
);
2306
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2307
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2308

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2309
test 'merge_param';
2310
$dbi = DBIx::Custom->new;
2311
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2312
    {$key1 => 1, $key2 => 2, $key3 => 3},
2313
    {$key1 => 1, $key2 => 2},
2314
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2315
];
2316
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2317
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2318

            
2319
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2320
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2321
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2322
];
2323
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2324
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
2325

            
2326
test 'select() param option';
2327
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2328
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2329
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2330
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2331
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2332
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2333
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2334
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
2335
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
2336
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2337
    table => $table1,
2338
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2339
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2340
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
test cleanup
Yuki Kimoto authored on 2011-08-15
2341
              " $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2342
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2343
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2344
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2345

            
cleanup
Yuki Kimoto authored on 2011-10-21
2346
$rows = $dbi->select(
2347
    table => $table1,
2348
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2349
    where   => {"$table1.$key2" => 3},
2350
    join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2351
             " $table2 on $table1.$key1 = $table2.$key1",
2352
    param => {"$table2.$key3" => 5}
2353
)->all;
2354
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2355

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

            
2369
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2370
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2371
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2372
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2373
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2374
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2375
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2376
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2377
        "$key1 = :$key1 and $key2 = :$key2",
2378
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2379
    ]
2380
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2381
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2382

            
cleanup
Yuki Kimoto authored on 2011-10-21
2383
$dbi = DBIx::Custom->connect;
2384
eval { $dbi->execute("drop table $table1") };
2385
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2386
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2387
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
2388
$rows = $dbi->select(
2389
    table => $table1,
2390
    where => [
2391
        "$key1 = :$key1 and $key2 = :$key2",
2392
        {$key1 => 1, $key2 => 2}
2393
    ]
2394
)->all;
2395
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2396

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

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

            
2426

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

            
2441
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2442
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2443
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2444
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2445
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2446
    {$key1 => 5},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2447
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2448
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2449
        "$key1 = :$key1 and $key2 = :$key2",
2450
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2451
    ]
2452
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2453
$rows = $dbi->select(table => $table1)->all;
2454
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2455

            
2456
test 'insert id and primary_key option';
2457
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2458
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2459
$dbi->execute($create_table1_2);
2460
$dbi->insert(
cleanup
Yuki Kimoto authored on 2011-11-01
2461
    {$key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2462
    primary_key => [$key1, $key2], 
2463
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2464
    id => [1, 2],
2465
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2466
is($dbi->select(table => $table1)->one->{$key1}, 1);
2467
is($dbi->select(table => $table1)->one->{$key2}, 2);
2468
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2469

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2470
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2471
$dbi->insert(
cleanup
Yuki Kimoto authored on 2011-11-01
2472
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2473
    primary_key => $key1, 
2474
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2475
    id => 0,
2476
);
2477

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2482
$dbi = DBIx::Custom->connect;
2483
eval { $dbi->execute("drop table $table1") };
2484
$dbi->execute($create_table1_2);
2485
$dbi->insert(
2486
    {$key3 => 3},
2487
    primary_key => [$key1, $key2], 
2488
    table => $table1,
2489
    id => 1,
2490
);
2491
is($dbi->select(table => $table1)->one->{$key1}, 1);
2492
ok(!$dbi->select(table => $table1)->one->{$key2});
2493
is($dbi->select(table => $table1)->one->{$key3}, 3);
2494

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

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2508
$dbi = DBIx::Custom->connect;
2509
eval { $dbi->execute("drop table $table1") };
2510
$dbi->execute($create_table1_2);
2511
$param = {$key3 => 3, $key2 => 4};
2512
$dbi->insert(
2513
    $param,
2514
    primary_key => [$key1, $key2], 
2515
    table => $table1,
2516
    id => [1, 2],
2517
);
2518
is($dbi->select(table => $table1)->one->{$key1}, 1);
2519
is($dbi->select(table => $table1)->one->{$key2}, 4);
2520
is($dbi->select(table => $table1)->one->{$key3}, 3);
2521
is_deeply($param, {$key3 => 3, $key2 => 4});
2522

            
added test
Yuki Kimoto authored on 2011-10-25
2523
$dbi = DBIx::Custom->connect;
2524
eval { $dbi->execute("drop table $table1") };
2525
$dbi->execute($create_table1_2);
2526
$param = {$key3 => 3, $key2 => 4};
2527
$query = $dbi->insert(
2528
    $param,
2529
    primary_key => [$key1, $key2], 
2530
    table => $table1,
2531
    id => [1, 2],
2532
    query => 1
2533
);
micro optimization
Yuki Kimoto authored on 2011-11-16
2534
ok(ref $query);
added test
Yuki Kimoto authored on 2011-10-25
2535
is_deeply($param, {$key3 => 3, $key2 => 4});
2536

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

            
2551
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2552
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2553
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2554
$dbi->model($table1)->insert(
2555
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2556
    id => [1, 2]
2557
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2558
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2559
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2560
is($row->{$key1}, 1);
2561
is($row->{$key2}, 2);
2562
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2563

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2579
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2580
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2581
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2582
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2583
    table => $table1,
2584
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2585
    id => 0,
2586
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2587
is($dbi->select(table => $table1)->one->{$key1}, 0);
2588
is($dbi->select(table => $table1)->one->{$key2}, 2);
2589
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2590

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

            
2605

            
2606
test 'model update and id option';
2607
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2608
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2609
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2610
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2611
$dbi->model($table1)->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2612
    {$key3 => 4},
cleanup test
Yuki Kimoto authored on 2011-08-10
2613
    id => [1, 2],
2614
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2615
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2616
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2617
is($row->{$key1}, 1);
2618
is($row->{$key2}, 2);
2619
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2620

            
2621

            
2622
test 'delete and id option';
2623
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2624
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2625
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2626
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2627
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2628
    table => $table1,
2629
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2630
    id => [1, 2],
2631
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2632
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2633

            
cleanup
Yuki Kimoto authored on 2011-11-01
2634
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2635
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2636
    table => $table1,
2637
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2638
    id => 0,
2639
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2640
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2641

            
2642

            
2643
test 'model delete and id option';
2644
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2645
eval { $dbi->execute("drop table $table1") };
2646
eval { $dbi->execute("drop table $table2") };
2647
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2648
$dbi->execute($create_table1_2);
2649
$dbi->execute($create_table2_2);
2650
$dbi->execute($create_table3);
cleanup
Yuki Kimoto authored on 2011-11-01
2651
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2652
$dbi->model($table1)->delete(id => [1, 2]);
2653
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2654
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2655
$dbi->model($table1)->delete(id => [1, 2]);
2656
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2657
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2658
$dbi->model($table3)->delete(id => [1, 2]);
2659
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2660

            
2661

            
2662
test 'select and id option';
2663
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2664
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2665
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2666
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2667
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2668
    table => $table1,
2669
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2670
    id => [1, 2]
2671
);
2672
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2673
is($row->{$key1}, 1);
2674
is($row->{$key2}, 2);
2675
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2676

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2677
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2678
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2679
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2680
    table => $table1,
2681
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2682
    id => 0,
2683
);
2684
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2685
is($row->{$key1}, 0);
2686
is($row->{$key2}, 2);
2687
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2688

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2689
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2690
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2691
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2692
    table => $table1,
2693
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2694
    id => [1, 2]
2695
);
2696
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2697
is($row->{$key1}, 1);
2698
is($row->{$key2}, 2);
2699
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2700

            
2701

            
2702
test 'model select_at';
2703
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2704
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2705
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2706
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2707
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2708
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2709
is($row->{$key1}, 1);
2710
is($row->{$key2}, 2);
2711
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2712

            
2713
test 'column separator is default .';
2714
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2715
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2716
eval { $dbi->execute("drop table $table1") };
2717
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2718
$dbi->execute($create_table1);
2719
$dbi->execute($create_table2);
2720
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2721
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2722
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2723
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2724
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2725
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2726
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2727
);
2728
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2729
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2730

            
2731
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2732
    column => [$model->column($table2 => [$key1, $key3])],
2733
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2734
);
2735
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2736
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2737

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2738
test 'separator';
2739
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2740
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2741
eval { $dbi->execute("drop table $table1") };
2742
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2743
$dbi->execute($create_table1);
2744
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2745

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2746
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2747
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2748
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2749
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2750
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2751
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2752
);
2753
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2754
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2755
);
2756
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2757
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2758
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2759
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2760
$result = $model->select(
2761
    column => [
2762
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2763
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2764
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2765
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2766
);
2767
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2768
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2769
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2770

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2771
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2772
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2773
$result = $model->select(
2774
    column => [
2775
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2776
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2777
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2778
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2779
);
2780
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2781
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
2782
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2783

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2784
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2785
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2786
$result = $model->select(
2787
    column => [
2788
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2789
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2790
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2791
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2792
);
2793
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2794
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2795
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2796

            
2797

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2798
test 'filter_off';
2799
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2800
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2801
eval { $dbi->execute("drop table $table1") };
2802
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2803
$dbi->execute($create_table1);
2804
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2805

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2806
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2807
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2808
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2809
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2810
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2811
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2812
);
2813
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2814
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2815
$model = $dbi->model($table1);
2816
$result = $model->select(column => $key1);
2817
$result->filter($key1 => sub { $_[0] * 2 });
2818
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2819

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2820
test 'available_datetype';
2821
$dbi = DBIx::Custom->connect;
2822
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2823

            
2824

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2825
test 'select prefix option';
2826
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2827
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2828
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2829
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2830
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2831
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2832

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

            
added tests
Yuki Kimoto authored on 2011-08-26
2834
test 'mapper';
2835
$dbi = DBIx::Custom->connect;
2836
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2837
    id => {key => "$table1.id"},
2838
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2839
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
2840
);
2841
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2842
  "$table1.price" => 1900});
2843

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2844
$dbi = DBIx::Custom->connect;
2845
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2846
    id => {key => "$table1.id"},
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2847
    author => ["$table1.author" => $dbi->like_value],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2848
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2849
);
2850
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2851
  "$table1.price" => 1900});
2852

            
added tests
Yuki Kimoto authored on 2011-08-26
2853
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2854
    id => {key => "$table1.id"},
2855
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2856
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
2857
);
2858
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2859

            
2860
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2861
    id => {key => "$table1.id"},
2862
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2863
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
added tests
Yuki Kimoto authored on 2011-08-26
2864
);
2865
is_deeply($param, {});
2866

            
2867
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2868
    id => {key => "$table1.id"},
2869
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2870
);
2871
is_deeply($param, {"$table1.price" => undef});
2872

            
2873
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2874
    id => {key => "$table1.id", condition => 'exists'},
2875
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
2876
);
2877
is_deeply($param, {"$table1.price" => '%a'});
2878

            
2879
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2880
    id => {key => "$table1.id"},
added tests
Yuki Kimoto authored on 2011-08-26
2881
    price => ["$table1.price", sub { '%' . $_[0] }]
2882
);
2883
is_deeply($param, {"$table1.price" => '%a'});
2884

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2885
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2886
    price => sub { '%' . $_[0] },
2887
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2888
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2889
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2890

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

            
2896
$where = $dbi->where;
2897
$where->clause(['and', ":${key1}{=}"]);
2898
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
2899
$where->param($param);
2900
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2901
$row = $result->all;
2902
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2903

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

            
2914
$where = $dbi->where;
2915
$where->clause(['and', ":${key1}{=}"]);
2916
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
2917
$where->param($param);
2918
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2919
$row = $result->all;
2920
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2921
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2922
$row = $result->all;
2923
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2924

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2926
$where = $dbi->where;
2927
$where->clause(['and', ":${key1}{=}"]);
2928
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
2929
  ->pass([$key1, $key2])->map;
2930
$where->param($param);
2931
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2932
$row = $result->all;
2933
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2934

            
2935
$where = $dbi->where;
2936
$where->clause(['and', ":${key1}{=}"]);
2937
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
2938
$where->param($param);
2939
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2940
$row = $result->all;
2941
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2942

            
2943
$where = $dbi->where;
2944
$where->clause(['and', ":${key1}{=}"]);
2945
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
2946
  ->pass([$key1, $key2])->map;
2947
$where->param($param);
2948
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2949
$row = $result->all;
2950
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2951

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2953
$where = $dbi->where;
2954
$where->clause(['and', ":${key1}{=}"]);
2955
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
2956
$where->param($param);
2957
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2958
$row = $result->all;
2959
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2960

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

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

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

            
2989
$where = $dbi->where;
2990
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2991
    id => {key => "$table1.id"},
2992
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2993
);
2994
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
2995

            
2996
$where = $dbi->where;
2997
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2998
    id => {key => "$table1.id", condition => 'exists'},
2999
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3000
);
3001
is_deeply($param, {"$table1.price" => '%a'});
3002

            
3003
$where = $dbi->where;
3004
$param = $dbi->mapper(param => {id => [1, 2], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3005
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3006
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3007
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3008
);
3009
is_deeply($param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
3010
  "$table1.price" => 1900});
3011

            
3012
$where = $dbi->where;
3013
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900}, condition => 'length')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3014
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3015
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3016
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3017
);
3018
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
3019
  "$table1.price" => 1900});
3020

            
3021
$where = $dbi->where;
3022
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3023
    id => {key => "$table1.id", condition => 'length'},
3024
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
3025
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3026
);
3027
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
3028
  "$table1.price" => 1900});
3029

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3035
test 'order';
3036
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3037
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3038
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3039
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3040
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3041
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3042
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3043
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3044
$order->prepend($key1, "$key2 desc");
3045
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3046
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
3047
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3048
$order->prepend("$key1 desc");
3049
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3050
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
3051
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3052

            
3053
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3054
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3055
$result = $dbi->select(table => $table1,
3056
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3057
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3058
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
3059
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
3060
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
3061
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3062

            
3063
test 'tag_parse';
3064
$dbi = DBIx::Custom->connect;
3065
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3066
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3067
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3068
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3069
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3070
ok($@);
3071

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3072
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3073
{
3074
    $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3075
    $dbi = DBIx::Custom->connect;
3076
    eval { $dbi->execute("drop table $table1") };
3077
    $dbi->execute($create_table1);
3078
    $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3079
    eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3080
    ok($@);
cleanup
Yuki Kimoto authored on 2011-11-16
3081
    eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) };
3082
    ok($@);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3083
    delete$ENV{DBIX_CUSTOM_TAG_PARSE};
3084
}
3085

            
3086
{
3087
    $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3088
    $dbi = DBIx::Custom->connect;
3089
    eval { $dbi->execute("drop table $table1") };
3090
    $dbi->execute($create_table1);
3091
    $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-16
3092
    is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3093
    delete$ENV{DBIX_CUSTOM_TAG_PARSE};
3094
}
3095

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3096
test 'last_sql';
3097
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3098
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3099
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3100
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
3101
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3102

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3134
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3135
$result = $dbi->execute(
3136
    $source,
cleanup
Yuki Kimoto authored on 2011-11-01
3137
    {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3138
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3139
);
3140
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3141
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3142

            
3143
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3144
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3145
$dbi->execute($create_table1_highperformance);
3146
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3147
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3148
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3149
];
3150
{
3151
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3152
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3153
      $query ||= $dbi->insert($row, table => $table1, query => 1);
3154
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
3155
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3156
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3157
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3158
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3159
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3160
      ]
3161
    );
3162
}
3163

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3164
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3165
$dbi->execute($create_table1_highperformance);
3166
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3167
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3168
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3169
];
3170
{
3171
    my $query;
3172
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
3173
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3174
      $query ||= $dbi->insert($row, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
3175
      $sth ||= $query->{sth};
test cleanup
Yuki Kimoto authored on 2011-08-10
3176
      $sth->execute(map { $row->{$_} } sort keys %$row);
3177
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3178
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3179
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3180
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3181
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3182
      ]
3183
    );
3184
}
3185

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3186
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3187
$dbi->execute($create_table1_highperformance);
3188
$rows = [
3189
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
3190
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
3191
];
3192
{
3193
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3194
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3195
    for my $row (@$rows) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3196
      $query ||= $model->insert($row, query => 1);
3197
      $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3198
    }
3199
    is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3200
      [
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3201
          {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3202
          {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3203
      ]
3204
    );
3205
}
3206

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3207
eval { $dbi->execute("drop table $table1") };
3208
$dbi->execute($create_table1);
3209
{
3210
    $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3211
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3212
    eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3213
    like($@, qr/primary_key/);
3214
    delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
3215
}
3216

            
3217
{
3218
    $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3219
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3220
    $model->insert({$key1 => 1});
3221
    $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3222
      table => $table1, primary_key => $key1);
3223
    is($result->one->{$key1}, 1);
3224
    delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
3225
}
3226

            
3227
eval { $dbi->execute("drop table $table1") };
3228
$dbi->execute($create_table1);
3229
{
3230
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3231
    $model->insert({$key1 => 1});
3232
    eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3233
    is($result->one->{$key1}, 1);
3234
}
3235

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3236
test 'id option more';
3237
eval { $dbi->execute("drop table $table1") };
3238
$dbi->execute($create_table1_highperformance);
3239
$row = {
3240
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3241
};
3242
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3243
$model->insert($row);
3244
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3245
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3246
is_deeply($dbi->select(table => $table1)->one,
3247
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3248
);
3249

            
3250
eval { $dbi->execute("drop table $table1") };
3251
eval { $dbi->execute("drop table $table2") };
3252
$dbi->execute($create_table1);
3253
$dbi->execute($create_table2);
3254
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3255
$model->insert({$key1 => 1, $key2 => 2});
3256
$model = $dbi->create_model(table => $table2, primary_key => $key1,
3257
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
3258
$model->insert({$key1 => 1, $key3 => 3});
3259
$result = $model->select(
3260
    column => {$table1 => ["$key2"]},
3261
    id => 1
3262
);
3263
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3264

            
3265
eval { $dbi->execute("drop table $table1") };
3266
$dbi->execute($create_table1_highperformance);
3267
$row = {
3268
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3269
};
3270
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3271
$model->insert($row);
3272
$query = $model->delete(id => 1, query => 1);
3273
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3274
is_deeply($dbi->select(table => $table1)->all, []);
3275

            
3276
eval { $dbi->execute("drop table $table1") };
3277
eval { $dbi->execute($create_table1_highperformance) };
3278
$row = {
3279
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3280
};
3281
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3282
$model->insert($row);
3283
$query = $model->select(id => 1, query => 1);
3284
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3285
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3286
is_deeply($dbi->select(table => $table1)->one,
3287
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3288
);
3289

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3290
test 'result';
3291
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3292
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3293
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3294
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3295
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3296

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3297
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3298
@rows = ();
3299
while (my $row = $result->fetch) {
3300
    push @rows, [@$row];
3301
}
3302
is_deeply(\@rows, [[1, 2], [3, 4]]);
3303

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3304
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3305
@rows = ();
3306
while (my $row = $result->fetch_hash) {
3307
    push @rows, {%$row};
3308
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3309
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3310

            
3311
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3312
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3313
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3314
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3315
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3316

            
3317
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3318
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3319
$rows = $result->fetch_all;
3320
is_deeply($rows, [[1, 2], [3, 4]]);
3321

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3326
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3327
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3328
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3329
$rows = $result->fetch_all;
3330
is_deeply($rows, [[3, 2], [9, 4]], "array");
3331

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3332
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
3333
$result->dbi->filters({three_times => sub { $_[0] * 3}});
3334
$result->filter({$key1 => 'three_times'});
3335
$rows = $result->fetch_all;
3336
is_deeply($rows, [[3, 3, 2], [9, 9, 4]], "array");
3337

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3344
test 'DBIx::Custom::Result fetch_multi';
3345
eval { $dbi->execute("drop table $table1") };
3346
$dbi->execute($create_table1);
3347
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3348
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3349
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3350
$result = $dbi->select(table => $table1);
3351
$rows = $result->fetch_multi(2);
3352
is_deeply($rows, [[1, 2], [3, 4]]);
3353
$rows = $result->fetch_multi(2);
3354
is_deeply($rows, [[5, 6]]);
3355
$rows = $result->fetch_multi(2);
3356
ok(!$rows);
3357

            
3358
test 'DBIx::Custom::Result fetch_hash_multi';
3359
eval { $dbi->execute("drop table $table1") };
3360
$dbi->execute($create_table1);
3361
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3362
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3363
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3364
$result = $dbi->select(table => $table1);
3365
$rows = $result->fetch_hash_multi(2);
3366
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3367
$rows = $result->fetch_hash_multi(2);
3368
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3369
$rows = $result->fetch_hash_multi(2);
3370
ok(!$rows);
3371

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3372
test "query_builder";
3373
$datas = [
3374
    # Basic tests
3375
    {   name            => 'placeholder basic',
3376
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3377
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3378
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3379
    },
3380
    {
3381
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3382
        source            => "{in k1 3}",
3383
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3384
        columns_expected   => [qw/k1 k1 k1/]
3385
    },
3386
    
3387
    # Table name
3388
    {
3389
        name            => 'placeholder with table name',
3390
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3391
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3392
        columns_expected  => [qw/a.k1 a.k2/]
3393
    },
3394
    {   
3395
        name            => 'placeholder in with table name',
3396
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3397
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3398
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3399
    },
3400
    {
3401
        name            => 'not contain tag',
3402
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3403
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3404
        columns_expected  => [],
3405
    }
3406
];
3407

            
3408
for (my $i = 0; $i < @$datas; $i++) {
3409
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3410
    my $dbi = DBIx::Custom->new;
3411
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3412
    my $query = $builder->build_query($data->{source});
3413
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
micro optimization
Yuki Kimoto authored on 2011-11-16
3414
    is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3415
}
3416

            
cleanup
Yuki Kimoto authored on 2011-08-13
3417
$dbi = DBIx::Custom->new;
3418
$builder = $dbi->query_builder;
3419
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3420
    p => sub {
3421
        my @args = @_;
3422
        
3423
        my $expand    = "? $args[0] $args[1]";
3424
        my $columns = [2];
3425
        return [$expand, $columns];
3426
    }
3427
);
3428

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3439
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3440
    q => 'string'
3441
});
3442

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3446
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3447
   r => sub {} 
3448
});
3449

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3453
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3454
   s => sub { return ["a", ""]} 
3455
});
3456

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3460
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3461
    t => sub {return ["a", []]}
3462
);
3463

            
3464

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

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

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

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

            
3480
test 'variouse source';
3481
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3482
$query = $builder->build_query($source);
3483
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3484

            
3485
$source = "abc";
3486
$query = $builder->build_query($source);
micro optimization
Yuki Kimoto authored on 2011-11-16
3487
is($query->{sql}, 'abc', "basic : 2");
cleanup test
Yuki Kimoto authored on 2011-08-15
3488

            
3489
$source = "{= a}";
3490
$query = $builder->build_query($source);
micro optimization
Yuki Kimoto authored on 2011-11-16
3491
is($query->{sql}, 'a = ?', "only tag");
cleanup test
Yuki Kimoto authored on 2011-08-15
3492

            
3493
$source = "000";
3494
$query = $builder->build_query($source);
micro optimization
Yuki Kimoto authored on 2011-11-16
3495
is($query->{sql}, '000', "contain 0 value");
cleanup test
Yuki Kimoto authored on 2011-08-15
3496

            
3497
$source = "a {= b} }";
3498
eval{$builder->build_query($source)};
3499
like($@, qr/unexpected "}"/, "error : 1");
3500

            
3501
$source = "a {= {}";
3502
eval{$builder->build_query($source)};
3503
like($@, qr/unexpected "{"/, "error : 2");
3504

            
3505
test 'select() sqlfilter option';
3506
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3507
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3508
eval { $dbi->execute("drop table $table1") };
3509
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3510
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3511
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3512
$rows = $dbi->select(
3513
    table => $table1,
3514
    column => $key1,
3515
    sqlfilter => sub {
3516
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
3517
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
3518
        return $sql;
3519
    }
3520
)->all;
3521
is_deeply($rows, [{$key1 => 1}]);
3522

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3523
test 'select() after_build_sql option';
3524
$dbi = DBIx::Custom->connect;
3525
$dbi->user_table_info($user_table_info);
3526
eval { $dbi->execute("drop table $table1") };
3527
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3528
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3529
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3530
$rows = $dbi->select(
3531
    table => $table1,
3532
    column => $key1,
3533
    after_build_sql => sub {
3534
        my $sql = shift;
3535
        $sql = "select * from ( $sql ) t where $key1 = 1";
3536
        return $sql;
3537
    }
3538
)->all;
3539
is_deeply($rows, [{$key1 => 1}]);
3540

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3541
test 'dbi method from model';
3542
$dbi = MyDBI9->connect;
3543
eval { $dbi->execute("drop table $table1") };
3544
$dbi->execute($create_table1);
3545
$dbi->setup_model;
3546
$model = $dbi->model($table1);
3547
eval{$model->execute("select * from $table1")};
3548
ok(!$@);
3549

            
3550
test 'column table option';
3551
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3552
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3553
eval { $dbi->execute("drop table $table1") };
3554
$dbi->execute($create_table1);
3555
eval { $dbi->execute("drop table $table2") };
3556
$dbi->execute($create_table2);
3557
$dbi->setup_model;
3558
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3559
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3560
$model = $dbi->model($table1);
3561
$result = $model->select(
3562
    column => [
3563
        $model->column($table2, {alias => $table2_alias})
3564
    ],
3565
    where => {"$table2_alias.$key3" => 4}
3566
);
3567
is_deeply($result->one, 
3568
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3569

            
3570
$dbi->separator('__');
3571
$result = $model->select(
3572
    column => [
3573
        $model->column($table2, {alias => $table2_alias})
3574
    ],
3575
    where => {"$table2_alias.$key3" => 4}
3576
);
3577
is_deeply($result->one, 
3578
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3579

            
3580
$dbi->separator('-');
3581
$result = $model->select(
3582
    column => [
3583
        $model->column($table2, {alias => $table2_alias})
3584
    ],
3585
    where => {"$table2_alias.$key3" => 4}
3586
);
3587
is_deeply($result->one, 
3588
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3589

            
3590
test 'create_model';
3591
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3592
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3593
eval { $dbi->execute("drop table $table1") };
3594
eval { $dbi->execute("drop table $table2") };
3595
$dbi->execute($create_table1);
3596
$dbi->execute($create_table2);
3597

            
3598
$dbi->create_model(
3599
    table => $table1,
3600
    join => [
3601
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3602
    ],
3603
    primary_key => [$key1]
3604
);
3605
$model2 = $dbi->create_model(
3606
    table => $table2
3607
);
3608
$dbi->create_model(
3609
    table => $table3,
3610
    filter => [
3611
        $key1 => {in => sub { uc $_[0] }}
3612
    ]
3613
);
3614
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3615
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3616
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3617
$model = $dbi->model($table1);
3618
$result = $model->select(
3619
    column => [$model->mycolumn, $model->column($table2)],
3620
    where => {"$table1.$key1" => 1}
3621
);
3622
is_deeply($result->one,
3623
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3624
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3625

            
3626
test 'model method';
3627
$dbi = DBIx::Custom->connect;
3628
eval { $dbi->execute("drop table $table2") };
3629
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3630
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3631
$model = $dbi->create_model(
3632
    table => $table2
3633
);
3634
$model->method(foo => sub { shift->select(@_) });
3635
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3636

            
3637
test 'model helper';
3638
$dbi = DBIx::Custom->connect;
3639
eval { $dbi->execute("drop table $table2") };
3640
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3641
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3642
$model = $dbi->create_model(
3643
    table => $table2
3644
);
3645
$model->helper(foo => sub { shift->select(@_) });
3646
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3647

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

            
3655
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3656
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3657
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3658
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3659
where $key1 = 1
3660
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3661
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3662
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3663
$rows   = $result->all;
3664
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3665
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3666
                  "basic");
3667

            
3668

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

            
3675
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3676
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3677
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3678
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3679
where $key1 = 1
3680
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3681
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3682
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3683
$rows   = $result->all;
3684
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3685
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3686
                  "basic");
3687

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

            
3694
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3695
$assign_clause = $dbi->update_param($param, {no_set => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
3696
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3697
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3698
where $key1 = 1
3699
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3700
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3701
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3702
$rows   = $result->all;
3703
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3704
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3705
                  "update param no_set");
3706

            
3707
            
3708
$dbi = DBIx::Custom->connect;
3709
eval { $dbi->execute("drop table $table1") };
3710
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
3711
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
3712
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3713

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3714
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3715
$assign_clause = $dbi->assign_param($param);
3716
$sql = <<"EOS";
3717
update $table1 set $assign_clause
3718
where $key1 = 1
3719
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3720
$dbi->execute($sql, $param, table => $table1);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3721
$result = $dbi->execute("select * from $table1 order by $key1");
3722
$rows   = $result->all;
3723
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3724
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3725
                  "basic");
3726

            
3727
$param = {$key2 => 11};
3728
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3729
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3730
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3731
where $key1 = 1
3732
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3733
$dbi->execute($sql, $param, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3734
$result = $dbi->execute("select * from $table1 order by $key1");
3735
$rows   = $result->all;
3736
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3737
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3738
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3739

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3740
test 'Model class';
3741
$dbi = MyDBI1->connect;
3742
eval { $dbi->execute("drop table $table1") };
3743
$dbi->execute($create_table1);
3744
$model = $dbi->model($table1);
3745
$model->insert({$key1 => 'a', $key2 => 'b'});
3746
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3747
eval { $dbi->execute("drop table $table2") };
3748
$dbi->execute($create_table2);
3749
$model = $dbi->model($table2);
3750
$model->insert({$key1 => 'a'});
3751
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3752
is($dbi->models->{$table1}, $dbi->model($table1));
3753
is($dbi->models->{$table2}, $dbi->model($table2));
3754

            
3755
$dbi = MyDBI4->connect;
3756
eval { $dbi->execute("drop table $table1") };
3757
$dbi->execute($create_table1);
3758
$model = $dbi->model($table1);
3759
$model->insert({$key1 => 'a', $key2 => 'b'});
3760
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3761
eval { $dbi->execute("drop table $table2") };
3762
$dbi->execute($create_table2);
3763
$model = $dbi->model($table2);
3764
$model->insert({$key1 => 'a'});
3765
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3766

            
3767
$dbi = MyDBI5->connect;
3768
eval { $dbi->execute("drop table $table1") };
3769
eval { $dbi->execute("drop table $table2") };
3770
$dbi->execute($create_table1);
3771
$dbi->execute($create_table2);
3772
$model = $dbi->model($table2);
3773
$model->insert({$key1 => 'a'});
3774
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
3775
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3776
$model = $dbi->model($table1);
3777
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3778

            
3779
test 'primary_key';
3780
$dbi = MyDBI1->connect;
3781
$model = $dbi->model($table1);
3782
$model->primary_key([$key1, $key2]);
3783
is_deeply($model->primary_key, [$key1, $key2]);
3784

            
3785
test 'columns';
3786
$dbi = MyDBI1->connect;
3787
$model = $dbi->model($table1);
3788
$model->columns([$key1, $key2]);
3789
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3790

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3791
test 'setup_model';
3792
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3793
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3794
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3795
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3796

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3797
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3798
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3799
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3800
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3801
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3802

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3803
test 'each_column';
3804
$dbi = DBIx::Custom->connect;
3805
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3806
eval { $dbi->execute("drop table $table1") };
3807
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3808
eval { $dbi->execute("drop table $table3") };
3809
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3810
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3811

            
3812
$infos = [];
3813
$dbi->each_column(sub {
3814
    my ($self, $table, $column, $cinfo) = @_;
3815
    
3816
    if ($table =~ /^table\d/i) {
3817
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3818
         push @$infos, $info;
3819
    }
3820
});
3821
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3822
is_deeply($infos, 
3823
    [
3824
        [$table1, $key1, $key1],
3825
        [$table1, $key2, $key2],
3826
        [$table2, $key1, $key1],
3827
        [$table2, $key3, $key3]
3828
    ]
3829
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3830
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3831

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3832
test 'each_table';
3833
$dbi = DBIx::Custom->connect;
3834
eval { $dbi->execute("drop table $table1") };
3835
eval { $dbi->execute("drop table $table2") };
3836
$dbi->execute($create_table2);
3837
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3838

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3839
$infos = [];
3840
$dbi->each_table(sub {
3841
    my ($self, $table, $table_info) = @_;
3842
    
3843
    if ($table =~ /^table\d/i) {
3844
         my $info = [$table, $table_info->{TABLE_NAME}];
3845
         push @$infos, $info;
3846
    }
3847
});
3848
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3849
is_deeply($infos, 
3850
    [
3851
        [$table1, $table1],
3852
        [$table2, $table2],
3853
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3854
);
3855

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3856
$dbi = DBIx::Custom->connect;
3857
eval { $dbi->execute("drop table $table1") };
3858
eval { $dbi->execute("drop table $table2") };
3859
$dbi->execute($create_table2);
3860
$dbi->execute($create_table1_type);
3861

            
3862
$infos = [];
3863
$dbi->user_table_info($user_table_info);
3864
$dbi->each_table(sub {
3865
    my ($self, $table, $table_info) = @_;
3866
    
3867
    if ($table =~ /^table\d/i) {
3868
         my $info = [$table, $table_info->{TABLE_NAME}];
3869
         push @$infos, $info;
3870
    }
3871
});
3872
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3873
is_deeply($infos, 
3874
    [
3875
        [$table1, $table1],
3876
        [$table2, $table2],
3877
        [$table3, $table3],
3878
    ]
3879
);
3880

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3881
test 'type_rule into';
3882
eval { $dbi->execute("drop table $table1") };
3883
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3884
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3885

            
3886

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3887
$dbi = DBIx::Custom->connect;
3888
eval { $dbi->execute("drop table $table1") };
3889
$dbi->execute($create_table1_type);
3890

            
cleanup
Yuki Kimoto authored on 2011-08-16
3891
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3892
$dbi->type_rule(
3893
    into1 => {
3894
        $date_typename => sub { '2010-' . $_[0] }
3895
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3896
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3897
$dbi->insert({$key1 => '01-01'}, table => $table1);
3898
$result = $dbi->select(table => $table1);
3899
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3900

            
3901
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3902
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3903
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3904
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3905
$dbi->type_rule(
3906
    into1 => [
3907
         [$date_typename, $datetime_typename] => sub {
3908
            my $value = shift;
3909
            $value =~ s/02/03/g;
3910
            return $value;
3911
         }
3912
    ]
3913
);
3914
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3915
$result = $dbi->select(table => $table1);
3916
$row = $result->one;
3917
like($row->{$key1}, qr/^2010-01-03/);
3918
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3919

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3920
$dbi = DBIx::Custom->connect;
3921
eval { $dbi->execute("drop table $table1") };
3922
$dbi->execute($create_table1_type);
3923
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3924
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3925
$dbi->type_rule(
3926
    into1 => [
3927
        [$date_typename, $datetime_typename] => sub {
3928
            my $value = shift;
3929
            $value =~ s/02/03/g;
3930
            return $value;
3931
        }
3932
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3933
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3934
$result = $dbi->execute(
3935
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
3936
    {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
3937
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3938
$row = $result->one;
3939
like($row->{$key1}, qr/^2010-01-03/);
3940
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3941

            
3942
$dbi = DBIx::Custom->connect;
3943
eval { $dbi->execute("drop table $table1") };
3944
$dbi->execute($create_table1_type);
3945
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3946
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3947
$dbi->type_rule(
3948
    into1 => [
3949
        [$date_typename, $datetime_typename] => sub {
3950
            my $value = shift;
3951
            $value =~ s/02/03/g;
3952
            return $value;
3953
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3954
    ]
3955
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3956
$result = $dbi->execute(
3957
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
3958
    {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
cleanup test
Yuki Kimoto authored on 2011-08-15
3959
    table => $table1
3960
);
3961
$row = $result->one;
3962
like($row->{$key1}, qr/^2010-01-03/);
3963
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3964

            
3965
$dbi = DBIx::Custom->connect;
3966
eval { $dbi->execute("drop table $table1") };
3967
$dbi->execute($create_table1_type);
3968
$dbi->register_filter(convert => sub {
3969
    my $value = shift || '';
3970
    $value =~ s/02/03/;
3971
    return $value;
3972
});
cleanup
Yuki Kimoto authored on 2011-08-16
3973
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3974
$dbi->type_rule(
3975
    from1 => {
3976
        $date_datatype => 'convert',
3977
    },
3978
    into1 => {
3979
        $date_typename => 'convert',
3980
    }
3981
);
3982
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3983
$result = $dbi->select(table => $table1);
3984
like($result->fetch->[0], qr/^2010-03-03/);
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3985
$result = $dbi->select(column => [$key1, $key1], table => $table1);
3986
$row = $result->fetch;
3987
like($row->[0], qr/^2010-03-03/);
3988
like($row->[1], qr/^2010-03-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
3989

            
3990
test 'type_rule and filter order';
3991
$dbi = DBIx::Custom->connect;
3992
eval { $dbi->execute("drop table $table1") };
3993
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3994
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3995
$dbi->type_rule(
3996
    into1 => {
3997
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3998
    },
3999
    into2 => {
4000
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4001
    },
4002
    from1 => {
4003
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4004
    },
4005
    from2 => {
4006
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
4007
    }
4008
);
4009
$dbi->insert({$key1 => '2010-01-03'}, 
4010
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
4011
$result = $dbi->select(table => $table1);
4012
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
4013
like($result->fetch_first->[0], qr/^2010-01-09/);
4014

            
4015

            
4016
$dbi = DBIx::Custom->connect;
4017
eval { $dbi->execute("drop table $table1") };
4018
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4019
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4020
$dbi->type_rule(
4021
    from1 => {
4022
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4023
    },
4024
    from2 => {
4025
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4026
    },
4027
);
4028
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4029
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4030
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4031
$result->type_rule(
4032
    from1 => {
4033
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4034
    },
4035
    from2 => {
4036
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
4037
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4038
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4039
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
4040
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4041

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4042
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
4043
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
4044
eval { $dbi->execute("drop table $table1") };
4045
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4046
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4047
$dbi->type_rule(
4048
    from1 => {
4049
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4050
    },
4051
    into1 => {
4052
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4053
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4054
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4055
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4056
$result = $dbi->select(table => $table1, type_rule_off => 1);
4057
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4058

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4059
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4060
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4061
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4062
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4063
$dbi->type_rule(
4064
    from1 => {
4065
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4066
    },
4067
    into1 => {
4068
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4069
    }
4070
);
4071
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4072
$result = $dbi->select(table => $table1, type_rule_off => 1);
4073
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4074

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

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

            
4107
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4108
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4109
$dbi->execute($create_table1_type);
4110
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
4111
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4112
$dbi->type_rule(
4113
    into1 => {
4114
        $date_typename => 'ppp'
4115
    }
4116
);
4117
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4118
$result = $dbi->select(table => $table1);
4119
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4120

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4121
eval{$dbi->type_rule(
4122
    into1 => {
4123
        $date_typename => 'pp'
4124
    }
4125
)};
4126
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4127

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4128
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4129
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4130
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4131
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
4132
    $dbi->type_rule(
4133
        from1 => {
4134
            Date => sub { $_[0] * 2 },
4135
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
4136
    );
4137
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4138
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4139

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4140
eval {
4141
    $dbi->type_rule(
4142
        into1 => {
4143
            Date => sub { $_[0] * 2 },
4144
        }
4145
    );
4146
};
4147
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4148

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

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

            
4187
$result = $dbi->select(table => $table1);
4188
$result->type_rule(
4189
    from1 => {
4190
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4191
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4192
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4193
$row = $result->one;
4194
like($row->{$key1}, qr/2010-01-05/);
4195
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4196

            
4197
$result = $dbi->select(table => $table1);
4198
$result->type_rule(
4199
    from1 => {
4200
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4201
    }
4202
);
4203
$row = $result->one;
4204
like($row->{$key1}, qr/2010-01-05/);
4205
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4206

            
4207
$result = $dbi->select(table => $table1);
4208
$result->type_rule(
4209
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
4210
);
4211
$row = $result->one;
4212
like($row->{$key1}, qr/2010-01-05/);
4213
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4214

            
4215
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4216
$result = $dbi->select(table => $table1);
4217
$result->type_rule(
4218
    from1 => [$date_datatype => 'five']
4219
);
4220
$row = $result->one;
4221
like($row->{$key1}, qr/^2010-01-05/);
4222
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4223

            
4224
$result = $dbi->select(table => $table1);
4225
$result->type_rule(
4226
    from1 => [$date_datatype => undef]
4227
);
4228
$row = $result->one;
4229
like($row->{$key1}, qr/^2010-01-03/);
4230
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4231

            
4232
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4233
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4234
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4235
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4236
$dbi->type_rule(
4237
    from1 => {
4238
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4239
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
4240
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4241
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4242
$result = $dbi->select(table => $table1);
4243
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4244
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4245

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4246
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4247
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4248
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4249
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4250
$dbi->type_rule(
4251
    from1 => {
4252
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4253
    },
4254
);
4255
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4256
$result = $dbi->select(table => $table1);
4257
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4258
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4259

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4260
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4261
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4262
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4263
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4264
$dbi->type_rule(
4265
    into1 => {
4266
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4267
    },
4268
    into2 => {
4269
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4270
    },
4271
    from1 => {
4272
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4273
    },
4274
    from2 => {
4275
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4276
    }
4277
);
4278
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4279
$result = $dbi->select(table => $table1);
4280
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/);
4281
$result = $dbi->select(table => $table1);
4282
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4283

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4284
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4285
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4286
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4287
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4288
$dbi->type_rule(
4289
    into1 => {
4290
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4291
    },
4292
    into2 => {
4293
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4294
    },
4295
    from1 => {
4296
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
4297
    },
4298
    from2 => {
4299
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4300
    }
4301
);
4302
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4303
$result = $dbi->select(table => $table1);
4304
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/);
4305
$result = $dbi->select(table => $table1);
4306
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4307

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4308
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4309
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4310
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4311
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4312
$dbi->type_rule(
4313
    into1 => {
4314
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4315
    },
4316
    into2 => {
4317
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4318
    },
4319
    from1 => {
4320
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4321
    },
4322
    from2 => {
4323
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4324
    }
4325
);
4326
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4327
$result = $dbi->select(table => $table1);
4328
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
4329
$result = $dbi->select(table => $table1);
4330
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4331

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4332
test 'join';
4333
$dbi = DBIx::Custom->connect;
4334
eval { $dbi->execute("drop table $table1") };
4335
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4336
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4337
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4338
eval { $dbi->execute("drop table $table2") };
4339
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4340
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4341
eval { $dbi->execute("drop table $table3") };
4342
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4343
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4344
$rows = $dbi->select(
4345
    table => $table1,
4346
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4347
    where   => {"$table1.$key2" => 2},
4348
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4349
)->all;
4350
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4351

            
4352
$dbi = DBIx::Custom->connect;
4353
eval { $dbi->execute("drop table $table1") };
4354
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4355
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4356
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4357
eval { $dbi->execute("drop table $table2") };
4358
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4359
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4360
eval { $dbi->execute("drop table $table3") };
4361
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4362
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4363
$rows = $dbi->select(
4364
    table => $table1,
4365
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4366
    where   => {"$table1.$key2" => 2},
4367
    join  => {
4368
        clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4369
        table => [$table1, $table2]
4370
    }
4371
)->all;
4372
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4373

            
4374
$rows = $dbi->select(
4375
    table => $table1,
4376
    where   => {$key1 => 1},
4377
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4378
)->all;
4379
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4380

            
4381
$rows = $dbi->select(
4382
    table => $table1,
4383
    where   => {$key1 => 1},
4384
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4385
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4386
)->all;
4387
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4388

            
4389
$rows = $dbi->select(
4390
    column => "$table3.$key4 as ${table3}__$key4",
4391
    table => $table1,
4392
    where   => {"$table1.$key1" => 1},
4393
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4394
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4395
)->all;
4396
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4397

            
4398
$rows = $dbi->select(
4399
    column => "$table1.$key1 as ${table1}__$key1",
4400
    table => $table1,
4401
    where   => {"$table3.$key4" => 4},
4402
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4403
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4404
)->all;
4405
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4406

            
4407
$dbi = DBIx::Custom->connect;
4408
eval { $dbi->execute("drop table $table1") };
4409
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4410
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4411
eval { $dbi->execute("drop table $table2") };
4412
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4413
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4414
$rows = $dbi->select(
4415
    table => $table1,
4416
    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",
4417
    where   => {"$table1.$key2" => 2},
4418
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4419
)->all;
4420
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4421
          'quote');
4422

            
4423

            
4424
$dbi = DBIx::Custom->connect;
4425
eval { $dbi->execute("drop table $table1") };
4426
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4427
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4428
$sql = <<"EOS";
4429
left outer join (
4430
  select * from $table1 t1
4431
  where t1.$key2 = (
4432
    select max(t2.$key2) from $table1 t2
4433
    where t1.$key1 = t2.$key1
4434
  )
4435
) $table3 on $table1.$key1 = $table3.$key1
4436
EOS
4437
$join = [$sql];
4438
$rows = $dbi->select(
4439
    table => $table1,
4440
    column => "$table3.$key1 as ${table3}__$key1",
4441
    join  => $join
4442
)->all;
4443
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4444

            
4445
$dbi = DBIx::Custom->connect;
4446
eval { $dbi->execute("drop table $table1") };
4447
eval { $dbi->execute("drop table $table2") };
4448
$dbi->execute($create_table1);
4449
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4450
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4451
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4452
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4453
$result = $dbi->select(
4454
    table => $table1,
4455
    join => [
4456
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4457
    ]
4458
);
4459
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4460
$result = $dbi->select(
4461
    table => $table1,
4462
    column => [{$table2 => [$key3]}],
4463
    join => [
4464
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4465
    ]
4466
);
4467
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4468
$result = $dbi->select(
4469
    table => $table1,
4470
    column => [{$table2 => [$key3]}],
4471
    join => [
4472
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4473
    ]
4474
);
4475
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4476

            
4477
$dbi = DBIx::Custom->connect;
4478
eval { $dbi->execute("drop table $table1") };
4479
eval { $dbi->execute("drop table $table2") };
4480
$dbi->execute($create_table1);
4481
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4482
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4483
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4484
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4485
$result = $dbi->select(
4486
    table => $table1,
4487
    column => [{$table2 => [$key3]}],
4488
    join => [
4489
        {
4490
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4491
            table => [$table1, $table2]
4492
        }
4493
    ]
4494
);
4495
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4496

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4497
$dbi = DBIx::Custom->connect;
4498
eval { $dbi->execute("drop table $table1") };
4499
eval { $dbi->execute("drop table $table2") };
4500
$dbi->execute($create_table1);
4501
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4502
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4503
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4504
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4505
$result = $dbi->select(
4506
    table => $table1,
4507
    column => [{$table2 => [$key3]}],
4508
    join => [
4509
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4510
    ]
4511
);
4512
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4513

            
4514
$dbi = DBIx::Custom->connect;
4515
eval { $dbi->execute("drop table $table1") };
4516
eval { $dbi->execute("drop table $table2") };
4517
$dbi->execute($create_table1);
4518
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4519
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4520
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4521
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4522
$result = $dbi->select(
4523
    table => $table1,
4524
    column => [{$table2 => [$key3]}],
4525
    join => [
4526
        "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4527
    ]
4528
);
4529
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4530

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4531
test 'columns';
4532
$dbi = MyDBI1->connect;
4533
$model = $dbi->model($table1);
4534

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4535
test 'count';
4536
$dbi = DBIx::Custom->connect;
4537
eval { $dbi->execute("drop table $table1") };
4538
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4539
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4540
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4541
is($dbi->count(table => $table1), 2);
4542
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4543
$model = $dbi->create_model(table => $table1);
4544
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4545

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