DBIx-Custom / t / common.t /
Newer Older
4560 lines | 152.786kb
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}]);
cleanup
Yuki Kimoto authored on 2011-11-18
251
ok(keys %$reuse);
252
ok((keys %$reuse)[0] !~ /\?/);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
253

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

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

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
272
eval { $dbi->execute("drop table $table1") };
273
$dbi->execute($create_table1);
274
$model = $dbi->create_model(table => $table1);
275
$model->insert({$key1 => 1, $key2 => 2});
276
is_deeply($model->select($key1)->all, [{$key1 => 1}]);
277

            
cleanup test
Yuki Kimoto authored on 2011-08-15
278
test 'DBIx::Custom::Result test';
279
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
280
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
281
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
282
$source = "select $key1, $key2 from $table1";
283
$query = $dbi->create_query($source);
284
$result = $dbi->execute($query);
cleanup
Yuki Kimoto authored on 2011-08-15
285

            
cleanup test
Yuki Kimoto authored on 2011-08-15
286
@rows = ();
287
while (my $row = $result->fetch) {
288
    push @rows, [@$row];
289
}
290
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
cleanup
Yuki Kimoto authored on 2011-08-15
291

            
cleanup test
Yuki Kimoto authored on 2011-08-15
292
$result = $dbi->execute($query);
293
@rows = ();
294
while (my $row = $result->fetch_hash) {
295
    push @rows, {%$row};
296
}
297
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
298

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
307
test 'Insert query return value';
308
$source = "insert into $table1 {insert_param $key1 $key2}";
309
$query = $dbi->execute($source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
310
$ret_val = $dbi->execute($query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
311
ok($ret_val);
test cleanup
Yuki Kimoto authored on 2011-08-10
312

            
cleanup test
Yuki Kimoto authored on 2011-08-15
313
test 'Direct query';
314
$dbi->delete_all(table => $table1);
315
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
test cleanup
Yuki Kimoto authored on 2011-11-01
316
$dbi->execute($insert_source, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
317
$result = $dbi->execute("select * from $table1");
318
$rows = $result->all;
319
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
320

            
321
test 'Filter basic';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
322
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-08
323
$dbi->register_filter(twice       => sub { $_[0] * 2}, 
324
                    three_times => sub { $_[0] * 3});
325

            
cleanup test
Yuki Kimoto authored on 2011-08-15
326
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
327
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
328
$insert_query->filter({$key1 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
329
$dbi->execute($insert_query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
330
$result = $dbi->execute("select * from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
331
$rows = $result->filter({$key2 => 'three_times'})->all;
332
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
333

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
426
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
427
$result = $dbi->execute(
428
    $source,
test cleanup
Yuki Kimoto authored on 2011-11-01
429
    {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
430
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
cleanup test
Yuki Kimoto authored on 2011-08-08
431
);
432
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
433
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
434

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
435
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
436
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
437
$dbi->insert({$key1 => '2011-10-14 12:19:18', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
438
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
439
$result = $dbi->execute(
440
    $source,
test cleanup
Yuki Kimoto authored on 2011-11-01
441
    {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
442
);
443

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
448
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
449
$dbi->insert({$key1 => 'a:b c:d', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
450
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
451
$result = $dbi->execute(
452
    $source,
test cleanup
Yuki Kimoto authored on 2011-11-01
453
    {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
454
);
455
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
456
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
457

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
465
test 'insert';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
466
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
467
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
468
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
469
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
470
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
471
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
472
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
473

            
added tests
Yuki Kimoto authored on 2011-11-01
474
eval { $dbi->execute("drop table $table1") };
475
$dbi->execute($create_table1);
476
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
477
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
478
$result = $dbi->execute("select * from $table1");
479
$rows   = $result->all;
480
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
481

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
503
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
504
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
505
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
test cleanup
Yuki Kimoto authored on 2011-11-01
506
$dbi->insert({select => 1}, table => 'table');
cleanup test
Yuki Kimoto authored on 2011-08-10
507
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
508
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
509
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
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 in progress
Yuki Kimoto authored on 2011-08-15
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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
519
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
520
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
521
$dbi->insert({$key1 => \"'1'", $key2 => 2}, table => $table1);
522
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
523
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
524
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
525
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
526

            
updated pod
Yuki Kimoto authored on 2011-09-02
527
eval { $dbi->execute("drop table $table1") };
528
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
529
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
updated pod
Yuki Kimoto authored on 2011-09-02
530
  wrap => {$key1 => sub { "$_[0] - 1" }});
test cleanup
Yuki Kimoto authored on 2011-11-01
531
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
updated pod
Yuki Kimoto authored on 2011-09-02
532
$result = $dbi->execute("select * from $table1");
533
$rows   = $result->all;
534
is_deeply($rows, [{$key1 => 0, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
535

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
546
eval { $dbi->execute("drop table $table1") };
547
$dbi->execute($create_table1);
548
$dbi->insert_timestamp(
549
    [$key1, $key2] => sub { 5 }
550
);
551
$dbi->insert(table => $table1, timestamp => 1);
552
$result = $dbi->execute("select * from $table1");
553
$rows   = $result->all;
554
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
555

            
556
eval { $dbi->execute("drop table $table1") };
557
$dbi->execute($create_table1);
558
$dbi->insert_timestamp(
559
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
560
);
561
$dbi->insert(table => $table1, timestamp => 1);
562
$result = $dbi->execute("select * from $table1");
563
$rows   = $result->all;
564
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
565

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

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

            
586
eval { $dbi->execute("drop table $table1") };
587
$dbi->execute($create_table1_2);
588
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
589
$dbi->insert($param, table => $table1, created_at => $key2, updated_at => $key3);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
590
$result = $dbi->select(table => $table1);
591
is_deeply($param, {$key1 => 1});
592
$row   = $result->one;
593
is($row->{$key1}, 1);
594
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
595
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
596
is($row->{$key2}, $row->{$key3});
597

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
598
eval { $dbi->execute("drop table $table1") };
599
$dbi->execute($create_table1_2);
600
$model = $dbi->create_model(table => $table1, created_at => $key2);
601
$param = {$key1 => 1};
602
$model->insert($param);
603
$result = $dbi->select(table => $table1);
604
is_deeply($param, {$key1 => 1});
605
$row   = $result->one;
606
is($row->{$key1}, 1);
607
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
608

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

            
620
eval { $dbi->execute("drop table $table1") };
621
$dbi->execute($create_table1_2);
622
$param = {$key1 => 1};
623
$model = $dbi->create_model(table => $table1, created_at => $key2, updated_at => $key3);
624
$model->insert($param);
625
$result = $dbi->select(table => $table1);
626
is_deeply($param, {$key1 => 1});
627
$row   = $result->one;
628
is($row->{$key1}, 1);
629
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
630
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
631
is($row->{$key2}, $row->{$key3});
632

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
633
test 'update_or_insert';
634
eval { $dbi->execute("drop table $table1") };
635
$dbi->execute($create_table1);
636
$dbi->update_or_insert(
637
    {$key2 => 2},
638
    table => $table1,
639
    primary_key => $key1,
640
    id => 1
641
);
642
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
643
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
644

            
645
$dbi->update_or_insert(
646
    {$key2 => 3},
647
    table => $table1,
648
    primary_key => $key1,
649
    id => 1
650
);
651
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
652
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
653

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
654
eval {
655
    $dbi->update_or_insert(
656
        {$key2 => 3},
657
        table => $table1,
658
    );
659
};
660

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
663
eval {
664
    $dbi->insert({$key1 => 1}, table => $table1);
665
    $dbi->update_or_insert(
666
        {$key2 => 3},
667
        table => $table1,
668
        primary_key => $key1,
669
        id => 1
670
    );
671
};
672
like($@, qr/one/);
673

            
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
674
eval { $dbi->execute("drop table $table1") };
675
$dbi->execute($create_table1);
676
$dbi->update_or_insert(
677
    {},
678
    table => $table1,
679
    primary_key => $key1,
680
    id => 1
681
);
682
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
683
is($row->{$key1}, 1);
684

            
685
eval { 
686
    $affected = $dbi->update_or_insert(
687
        {},
688
        table => $table1,
689
        primary_key => $key1,
690
        id => 1
691
    );
692
};
693
is($affected, 0);
694

            
micro optimization
Yuki Kimoto authored on 2011-10-31
695
test 'model update_or_insert';
696
eval { $dbi->execute("drop table $table1") };
697
$dbi->execute($create_table1);
698
$model = $dbi->create_model(
699
    table => $table1,
700
    primary_key => $key1
701
);
702
$model->update_or_insert({$key2 => 2}, id => 1);
703
$row = $model->select(id => 1)->one;
704
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
705

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
706
eval {
707
    $model->insert({$key1 => 1});
708
    $model->update_or_insert(
709
        {$key2 => 3},
710
        id => 1
711
    );
712
};
713
like($@, qr/one/);
714

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
715
test 'default_bind_filter';
716
$dbi->execute("delete from $table1");
717
$dbi->register_filter(
718
    twice       => sub { $_[0] * 2 },
719
    three_times => sub { $_[0] * 3 }
720
);
721
$dbi->default_bind_filter('twice');
cleanup
Yuki Kimoto authored on 2011-11-01
722
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
723
$result = $dbi->execute("select * from $table1");
724
$rows   = $result->all;
725
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
726
$dbi->default_bind_filter(undef);
727

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

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

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

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

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

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

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

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

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
825
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
826
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
827
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
828
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
829
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
830
$dbi->insert({select => 1}, table => 'table');
831
$dbi->update({update => 2}, table => 'table', where => {select => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
832
$result = $dbi->execute("select * from ${q}table$p");
833
$rows   = $result->all;
834
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
835

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

            
839
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
840
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
841
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
842
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
843
$dbi->insert({select => 1}, table => 'table');
844
$dbi->update({update => 2}, table => 'table', where => {'table.select' => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
845
$result = $dbi->execute("select * from ${q}table$p");
846
$rows   = $result->all;
847
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
848

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
849
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
850
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
851
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
852
$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
853
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
854
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
855
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
856
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
857
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
858
                  "basic");
859

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

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

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
894
eval { $dbi->execute("drop table $table1") };
895
$dbi->execute($create_table1);
896
$dbi->update_timestamp(
897
    [$key1, $key2] => sub { '5' }
898
);
test cleanup
Yuki Kimoto authored on 2011-11-01
899
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
900
$dbi->update_all(table => $table1, timestamp => 1);
901
$result = $dbi->execute("select * from $table1");
902
$rows   = $result->all;
903
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
904

            
905
eval { $dbi->execute("drop table $table1") };
906
$dbi->execute($create_table1);
907
$dbi->update_timestamp(
908
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
909
);
test cleanup
Yuki Kimoto authored on 2011-11-01
910
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
911
$dbi->update_all(table => $table1, timestamp => 1);
912
$result = $dbi->execute("select * from $table1");
913
$rows   = $result->all;
914
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
915

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

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

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

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

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

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

            
989

            
990
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
991
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
992
$dbi->execute($create_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 in progress
Yuki Kimoto authored on 2011-08-15
995
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
996
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
997
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
998
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
999

            
cleanup test
Yuki Kimoto authored on 2011-08-15
1000
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
1001
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1002
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1003
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1004
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1005
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1006
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1007
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1008

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1011
$dbi->delete_all(table => $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 in progress
Yuki Kimoto authored on 2011-08-15
1014
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
1015
$rows = $dbi->select(table => $table1)->all;
1016
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1017

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1043
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1044
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1045
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1046
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
1047
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1048
$rows   = $result->all;
1049
is_deeply($rows, [], "basic");
1050

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1060
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
1061
$dbi = DBIx::Custom->connect;
1062
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1063
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1064
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1065
$dbi->insert({select => 1}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1066
$dbi->delete(table => 'table', where => {select => 1});
1067
$result = $dbi->execute("select * from ${q}table$p");
1068
$rows   = $result->all;
1069
is_deeply($rows, [], "reserved word");
1070

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

            
1081

            
1082
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1083
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1084
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1085
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1086
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1087
$rows = $dbi->select(table => $table1)->all;
1088
is_deeply($rows, [{$key1 => 1, $key2 => 2},
1089
                  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
1090

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1105
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1106
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
1107
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1108
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1109
    table => [$table1, $table2],
1110
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
1111
    where   => {"$table1.$key2" => 2},
1112
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1113
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1114
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
1115

            
1116
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1117
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1118
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1119
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1120
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1121
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
1122

            
1123
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
1124
eval { $dbi->execute("drop table ${q}table$p") };
1125
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1126
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1127
$dbi->insert({select => 1, update => 2}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1128
$result = $dbi->select(table => 'table', where => {select => 1});
1129
$rows   = $result->all;
1130
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
1131

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
1132
eval { $dbi->execute("drop table $table1") };
1133
$dbi->execute($create_table1);
1134
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1135
$row = $dbi->select($key1, table => $table1)->one;
1136
is_deeply($row, {$key1 => 1});
1137

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1138
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1139
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1140
$dbi->register_filter(
1141
    twice       => sub { $_[0] * 2 },
1142
    three_times => sub { $_[0] * 3 }
1143
);
1144
$dbi->default_fetch_filter('twice');
1145
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1146
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1147
$result = $dbi->select(table => $table1);
1148
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1149
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1150
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1151

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1152
$dbi->default_fetch_filter('twice');
1153
eval { $dbi->execute("drop table $table1") };
1154
$dbi->execute($create_table1);
1155
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1156
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1157
$result->filter({$key1 => 'three_times'});
1158
$row = $result->fetch_first;
1159
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter");
1160

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1161
test 'filters';
1162
$dbi = DBIx::Custom->new;
1163

            
1164
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
1165
   'あ', "decode_utf8");
1166

            
1167
is($dbi->filters->{encode_utf8}->('あ'),
1168
   encode_utf8('あ'), "encode_utf8");
1169

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1170
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1171
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1172
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1173
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1174
$dbi->begin_work;
1175
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1176
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1177
$dbi->rollback;
1178
$dbi->dbh->{AutoCommit} = 1;
1179

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

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

            
1184
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1185
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1186
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1187
$dbi->begin_work;
1188
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1189
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1190
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1191
$dbi->commit;
1192
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1193
$result = $dbi->select(table => $table1);
1194
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1195
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1196

            
1197
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1198
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1199
$dbi->execute($create_table1);
1200
{
1201
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1202
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1203
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1204
    like($@, qr/\.t /, "fail : not verbose");
1205
}
1206
{
1207
    local $Carp::Verbose = 1;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1208
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1209
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1210
}
1211

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

            
1217
{
1218
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1219
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1220
    like($@, qr/\Q.t /, "caller spec : not vebose");
1221
}
1222
{
1223
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1224
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1225
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1226
}
1227

            
1228

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1229
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1230
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1231
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1232
$dbi->execute($create_table1);
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);
test cleanup
Yuki Kimoto authored on 2011-08-10
1238
    die "Error";
test cleanup
Yuki Kimoto authored on 2011-11-01
1239
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1240
};
1241

            
1242
$dbi->rollback if $@;
1243

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

            
1248
$dbi->begin_work;
1249

            
1250
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1251
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1252
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1253
};
1254

            
1255
$dbi->commit unless $@;
1256

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

            
1261
$dbi->dbh->{AutoCommit} = 0;
1262
eval{ $dbi->begin_work };
1263
ok($@, "exception");
1264
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1265

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1266
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1267
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1268
$dbi->cache(1);
1269
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1270
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1271
$dbi->execute($source, {}, query => 1);
1272
is_deeply($dbi->{_cached}->{$source}, 
micro optimization
Yuki Kimoto authored on 2011-11-18
1273
          {sql => " select * from $table1 where $key1 = ?  and $key2 = ? ", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1274

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1275
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1276
$dbi->execute($create_table1);
1277
$dbi->{_cached} = {};
1278
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1279
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1280
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1281

            
1282
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1283
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1284
$dbi->execute($create_table1);
1285
{
1286
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1287
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1288
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1289
    like($@, qr/\.t /, "fail : not verbose");
1290
}
1291
{
1292
    local $Carp::Verbose = 1;
- removed argument checking ...
Yuki Kimoto authored on 2011-10-21
1293
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1294
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1295
}
1296

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

            
1302
{
1303
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1304
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1305
    like($@, qr/\Q.t /, "caller spec : not vebose");
1306
}
1307
{
1308
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1309
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1310
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1311
}
1312

            
1313
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1314
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1315
    one => sub { 1 }
1316
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1317
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1318
    two => sub { 2 }
1319
);
1320
$dbi->method({
1321
    twice => sub {
1322
        my $self = shift;
1323
        return $_[0] * 2;
1324
    }
1325
});
1326

            
1327
is($dbi->one, 1, "first");
1328
is($dbi->two, 2, "second");
1329
is($dbi->twice(5), 10 , "second");
1330

            
1331
eval {$dbi->XXXXXX};
1332
ok($@, "not exists");
1333

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

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

            
1367
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1368
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1369
$dbi->execute($create_table1);
1370
$dbi->register_filter(twice => sub { $_[0] * 2 });
1371
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1372
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1373
);
cleanup
Yuki Kimoto authored on 2011-11-01
1374
$dbi->insert({$key1 => 1, $key2 => 2},table => $table1, filter => {$key1 => undef});
1375
$dbi->update({$key1 => 2}, table => $table1, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1376
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1377
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1378
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
test cleanup
Yuki Kimoto authored on 2011-08-10
1379

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

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

            
1420
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1421
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1422
$dbi->execute($create_table1);
1423
$dbi->register_filter(twice => sub { $_[0] * 2 });
1424
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1425
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1426
);
cleanup
Yuki Kimoto authored on 2011-11-01
1427
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1428
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
1429
                        {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1430
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1431
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1432

            
1433
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1434
eval { $dbi->execute("drop table $table1") };
1435
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1436
$dbi->execute($create_table1);
1437
$dbi->execute($create_table2);
1438
$dbi->register_filter(twice => sub { $_[0] * 2 });
1439
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1440
$dbi->apply_filter(
cleanup test
Yuki Kimoto authored on 2011-08-15
1441
    $table1, $key2 => {out => 'twice', in => 'twice'}
1442
);
1443
$dbi->apply_filter(
1444
    $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1445
);
cleanup
Yuki Kimoto authored on 2011-11-01
1446
$dbi->insert({$key1 => 5, $key2 => 2}, table => $table1, filter => {$key2 => undef});
1447
$dbi->insert({$key1 => 5, $key3 => 6}, table => $table2, filter => {$key3 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1448
$result = $dbi->select(
1449
     table => [$table1, $table2],
1450
     column => [$key2, $key3],
1451
     where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1452

            
1453
$result->filter({$key2 => 'twice'});
1454
$rows   = $result->all;
1455
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1456

            
1457
$result = $dbi->select(
1458
     table => [$table1, $table2],
1459
     column => [$key2, $key3],
1460
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1461

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1473
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1474
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1475
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1476
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1477
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1478
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1479

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

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1497
$dbi = DBIx::Custom->connect;
1498
eval { $dbi->execute("drop table $table1") };
1499
$dbi->execute($create_table1);
1500
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1501
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1502
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1503
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
1504
$row = $result->fetch_first;
1505
is_deeply($row, [6, 6, 40]);
1506

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

            
1517
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1518
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1519
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1520
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1521
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1522
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1523
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1524
$row = $result->fetch_first;
1525
is_deeply($row, [6, 12]);
1526

            
1527
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1528
$result = $dbi->select(table => $table1);
1529
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1530
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1531
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1532
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1533

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

            
1544
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1545
$dbi->apply_filter($table1,
1546
    $key1 => {end => sub { $_[0] * 3 } },
1547
    $key2 => {end => 'five_times'}
1548
);
1549
$result = $dbi->select(table => $table1);
1550
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1551
$result->filter($key1 => undef);
1552
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1553
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1554
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1555

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1556
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1557
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1558
$result->filter($key1 => undef);
1559
$result->end_filter($key1 => undef);
1560
$row = $result->fetch;
1561
is_deeply($row, [1, 1, 40], 'apply_filter overwrite');
1562

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1563
test 'remove_end_filter and remove_filter';
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);
test cleanup
Yuki Kimoto authored on 2011-08-10
1569
$row = $result
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1570
       ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1571
       ->remove_filter
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1572
       ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1573
       ->remove_end_filter
1574
       ->fetch_first;
1575
is_deeply($row, [1, 2]);
1576

            
1577
test 'empty where select';
1578
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1579
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1580
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1581
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1582
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1583
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1584
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1585

            
1586
test 'select query option';
1587
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1588
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1589
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1590
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1591
ok(ref $query);
cleanup
Yuki Kimoto authored on 2011-11-01
1592
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1593
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1594
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1595
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1596
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1597
ok(ref $query);
test cleanup
Yuki Kimoto authored on 2011-08-10
1598

            
1599
test 'where';
1600
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1601
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1602
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1603
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1604
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1605
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1606
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1607

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

            
1612
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1613
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1614
    where => $where
1615
);
1616
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1617
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1618

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

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

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

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

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

            
1667
eval {
1668
$where = $dbi->where
1669
             ->clause(['uuu']);
1670
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1671
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1672
    where => $where
1673
);
1674
};
1675
ok($@);
1676

            
1677
$where = $dbi->where;
1678
is("$where", '');
1679

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

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

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

            
1710
$where = $dbi->where
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1711
             ->clause("$key1 = :$key1")
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1712
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1713
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1714
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1715
    where => $where,
1716
);
1717
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1718
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1719

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

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

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

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

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

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

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

            
1790
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1791
             ->clause(['or', ("$key1 = :$key1") x 3])
1792
             ->param({$key1 => []});
test cleanup
Yuki Kimoto authored on 2011-08-10
1793
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1794
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1795
    where => $where,
1796
);
1797
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1798
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1799

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

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

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

            
1830
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1831
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1832
             ->param({$key1 => [0, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1833
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1834
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1835
    where => $where,
1836
);
1837
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1838
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1839

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

            
1849
eval {$dbi->where(ppp => 1) };
1850
like($@, qr/invalid/);
1851

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

            
1863

            
1864
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1865
    clause => ['and', ['or'], ['or', ":$key1", ":$key2"]],
test cleanup
Yuki Kimoto authored on 2011-08-10
1866
    param => {}
1867
);
1868
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1869
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1870
    where => $where,
1871
);
1872
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1873
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1874

            
1875
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1876
$where->clause(['and', ":${key1}{=}"]);
1877
$where->param({$key1 => undef});
1878
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1879
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1880
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1881

            
1882
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1883
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1884
$where->param({$key1 => [undef, undef]});
1885
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1886
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1887
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1888
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1889
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1890
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1891

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

            
1893
$dbi = DBIx::Custom->connect;
1894
eval { $dbi->execute("drop table $table1") };
1895
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1896
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
1897
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1898
$where = $dbi->where
1899
             ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
1900
             ->param({$key1 => 1});
1901

            
1902
$result = $dbi->select(
1903
    table => $table1,
1904
    where => $where
1905
);
1906
$row = $result->all;
1907
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
1908

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1909
test 'register_tag_processor';
1910
$dbi = DBIx::Custom->connect;
1911
$dbi->register_tag_processor(
1912
    a => sub { 1 }
1913
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1914
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1915

            
1916
test 'register_tag';
1917
$dbi = DBIx::Custom->connect;
1918
$dbi->register_tag(
1919
    b => sub { 2 }
1920
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1921
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1922

            
1923
test 'table not specify exception';
1924
$dbi = DBIx::Custom->connect;
1925
eval {$dbi->select};
1926
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1927

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1928
test 'more tests';
1929
$dbi = DBIx::Custom->connect;
1930
eval{$dbi->apply_filter('table', 'column', [])};
1931
like($@, qr/apply_filter/);
1932

            
1933
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1934
like($@, qr/apply_filter/);
1935

            
1936
$dbi->apply_filter(
1937

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

            
1949
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1950
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1951
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1952
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1953
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1954
$dbi->apply_filter($table1, $key2, {});
1955
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1956
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1957

            
1958
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1959
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1960
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1961
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1962
like($@, qr/not registered/);
1963
$dbi->method({one => sub { 1 }});
1964
is($dbi->one, 1);
1965

            
1966
eval{DBIx::Custom->connect(dsn => undef)};
1967
like($@, qr/_connect/);
1968

            
1969
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1970
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1971
$dbi->execute($create_table1);
1972
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
1973
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1974
             filter => {$key1 => 'twice'});
1975
$row = $dbi->select(table => $table1)->one;
1976
is_deeply($row, {$key1 => 2, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
1977
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1978
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
1979
like($@, qr//);
1980

            
1981
$dbi->register_filter(one => sub { });
1982
$dbi->default_fetch_filter('one');
1983
ok($dbi->default_fetch_filter);
1984
$dbi->default_bind_filter('one');
1985
ok($dbi->default_bind_filter);
1986
eval{$dbi->default_fetch_filter('no')};
1987
like($@, qr/not registered/);
1988
eval{$dbi->default_bind_filter('no')};
1989
like($@, qr/not registered/);
1990
$dbi->default_bind_filter(undef);
1991
ok(!defined $dbi->default_bind_filter);
1992
$dbi->default_fetch_filter(undef);
1993
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1994
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1995
like($@, qr/Tag not finished/);
1996

            
1997
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1998
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1999
$dbi->execute($create_table1);
2000
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2001
$result = $dbi->select(table => $table1);
2002
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2003
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2004
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2005
like($@, qr/not registered/);
2006
$result->default_filter(undef);
2007
ok(!defined $result->default_filter);
2008
$result->default_filter('one');
2009
is($result->default_filter->(), 1);
2010

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2011
test 'option';
2012
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
2013
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
2014
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2015
ok($dbi->dbh->{PrintError});
2016
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2017
ok($dbi->dbh->{PrintError});
2018

            
2019
test 'DBIx::Custom::Result stash()';
2020
$result = DBIx::Custom::Result->new;
2021
is_deeply($result->stash, {}, 'default');
2022
$result->stash->{foo} = 1;
2023
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2024

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2025
test 'delete_at';
2026
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2027
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2028
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2029
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2030
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2031
    table => $table1,
2032
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2033
    where => [1, 2],
2034
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2035
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2036

            
cleanup
Yuki Kimoto authored on 2011-11-01
2037
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2038
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2039
    table => $table1,
2040
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2041
    where => 1,
2042
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2043
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2044

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2059
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2060
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2061
$dbi->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2062
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2063
    primary_key => $key1, 
2064
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2065
    where => 1,
2066
);
2067

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

            
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);
2075
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2076
    {$key3 => 3},
2077
    primary_key => [$key1, $key2], 
2078
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2079
    where => [1, 2],
2080
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2081
is($dbi->select(table => $table1)->one->{$key1}, 1);
2082
is($dbi->select(table => $table1)->one->{$key2}, 2);
2083
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2084

            
2085
test 'update_at';
2086
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2087
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2088
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2089
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2090
$dbi->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2091
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2092
    table => $table1,
2093
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2094
    where => [1, 2],
2095
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2096
is($dbi->select(table => $table1)->one->{$key1}, 1);
2097
is($dbi->select(table => $table1)->one->{$key2}, 2);
2098
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2099

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2100
$dbi->delete_all(table => $table1);
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
Yuki Kimoto authored on 2011-11-01
2103
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2104
    table => $table1,
2105
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2106
    where => 1,
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
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2113
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2114
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2115
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2116
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2117
    {$key3 => 4},
2118
    table => $table1,
2119
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2120
    where => [1, 2]
2121
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2122
is($dbi->select(table => $table1)->one->{$key1}, 1);
2123
is($dbi->select(table => $table1)->one->{$key2}, 2);
2124
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2125

            
2126
test 'select_at';
2127
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2128
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2129
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2130
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2131
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2132
    table => $table1,
2133
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2134
    where => [1, 2]
2135
);
2136
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2137
is($row->{$key1}, 1);
2138
is($row->{$key2}, 2);
2139
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2140

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2153
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2154
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2155
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2156
    table => $table1,
2157
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2158
    where => [1, 2]
2159
);
2160
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2161
is($row->{$key1}, 1);
2162
is($row->{$key2}, 2);
2163
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2164

            
2165
test 'model delete_at';
2166
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2167
eval { $dbi->execute("drop table $table1") };
2168
eval { $dbi->execute("drop table $table2") };
2169
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2170
$dbi->execute($create_table1_2);
2171
$dbi->execute($create_table2_2);
2172
$dbi->execute($create_table3);
test cleanup
Yuki Kimoto authored on 2011-11-01
2173
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2174
$dbi->model($table1)->delete_at(where => [1, 2]);
2175
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2176
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2177
$dbi->model($table1)->delete_at(where => [1, 2]);
2178
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2179
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2180
$dbi->model($table3)->delete_at(where => [1, 2]);
2181
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2182

            
2183
test 'model insert_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 in progress
Yuki Kimoto authored on 2011-08-15
2187
$dbi->model($table1)->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2188
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2189
    where => [1, 2],
2190
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2191
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2192
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2193
is($row->{$key1}, 1);
2194
is($row->{$key2}, 2);
2195
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2196

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

            
2212
test 'model select_at';
2213
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2214
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2215
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2216
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2217
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2218
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2219
is($row->{$key1}, 1);
2220
is($row->{$key2}, 2);
2221
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2222

            
2223

            
2224
test 'mycolumn and column';
2225
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2226
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2227
eval { $dbi->execute("drop table $table1") };
2228
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2229
$dbi->execute($create_table1);
2230
$dbi->execute($create_table2);
2231
$dbi->separator('__');
2232
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2233
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2234
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2235
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2236
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2237
    column => [$model->mycolumn, $model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2238
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2239
);
2240
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2241
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2242

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

            
2256
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2257
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2258
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2259
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2260
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2261
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2262
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2263
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2264
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2265
is($dbi->select(table => $table1)->one->{$key1}, 1);
2266
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2267

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2268
test 'mycolumn';
2269
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2270
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2271
eval { $dbi->execute("drop table $table1") };
2272
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2273
$dbi->execute($create_table1);
2274
$dbi->execute($create_table2);
2275
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2276
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2277
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2278
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2279
$result = $model->select_at(
2280
    column => [
2281
        $model->mycolumn,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2282
        $model->column($table2)
cleanup test
Yuki Kimoto authored on 2011-08-10
2283
    ]
2284
);
2285
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2286
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2287

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

            
2305
$result = $model->select_at(
2306
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2307
        $model->mycolumn([$key1]),
2308
        ["$table2.$key1", as => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2309
    ]
2310
);
2311
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2312
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2313

            
2314
$result = $model->select_at(
2315
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2316
        $model->mycolumn([$key1]),
2317
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2318
    ]
2319
);
2320
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2321
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2322

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2323
test 'merge_param';
2324
$dbi = DBIx::Custom->new;
2325
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2326
    {$key1 => 1, $key2 => 2, $key3 => 3},
2327
    {$key1 => 1, $key2 => 2},
2328
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2329
];
2330
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2331
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2332

            
2333
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2334
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2335
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2336
];
2337
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2338
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
2339

            
2340
test 'select() param option';
2341
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2342
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2343
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2344
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2345
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2346
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2347
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2348
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
2349
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
2350
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2351
    table => $table1,
2352
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2353
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2354
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
test cleanup
Yuki Kimoto authored on 2011-08-15
2355
              " $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2356
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2357
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2358
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2359

            
cleanup
Yuki Kimoto authored on 2011-10-21
2360
$rows = $dbi->select(
2361
    table => $table1,
2362
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2363
    where   => {"$table1.$key2" => 3},
2364
    join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2365
             " $table2 on $table1.$key1 = $table2.$key1",
2366
    param => {"$table2.$key3" => 5}
2367
)->all;
2368
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2369

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2370
test 'select() string where';
2371
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2372
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2373
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2374
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2375
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2376
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2377
    table => $table1,
2378
    where => "$key1 = :$key1 and $key2 = :$key2",
2379
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
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

            
2383
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2384
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
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 test
Yuki Kimoto authored on 2011-08-10
2388
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2389
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2390
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2391
        "$key1 = :$key1 and $key2 = :$key2",
2392
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2393
    ]
2394
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2395
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2396

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

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

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

            
2440

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

            
2455
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2456
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2457
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2458
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2459
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2460
    {$key1 => 5},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2461
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2462
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2463
        "$key1 = :$key1 and $key2 = :$key2",
2464
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2465
    ]
2466
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2467
$rows = $dbi->select(table => $table1)->all;
2468
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2469

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2484
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2485
$dbi->insert(
cleanup
Yuki Kimoto authored on 2011-11-01
2486
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2487
    primary_key => $key1, 
2488
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2489
    id => 0,
2490
);
2491

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2496
$dbi = DBIx::Custom->connect;
2497
eval { $dbi->execute("drop table $table1") };
2498
$dbi->execute($create_table1_2);
2499
$dbi->insert(
2500
    {$key3 => 3},
2501
    primary_key => [$key1, $key2], 
2502
    table => $table1,
2503
    id => 1,
2504
);
2505
is($dbi->select(table => $table1)->one->{$key1}, 1);
2506
ok(!$dbi->select(table => $table1)->one->{$key2});
2507
is($dbi->select(table => $table1)->one->{$key3}, 3);
2508

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2509
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2510
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2511
$dbi->execute($create_table1_2);
2512
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2513
    {$key3 => 3},
2514
    primary_key => [$key1, $key2], 
2515
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2516
    id => [1, 2],
2517
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2518
is($dbi->select(table => $table1)->one->{$key1}, 1);
2519
is($dbi->select(table => $table1)->one->{$key2}, 2);
2520
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2521

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2522
$dbi = DBIx::Custom->connect;
2523
eval { $dbi->execute("drop table $table1") };
2524
$dbi->execute($create_table1_2);
2525
$param = {$key3 => 3, $key2 => 4};
2526
$dbi->insert(
2527
    $param,
2528
    primary_key => [$key1, $key2], 
2529
    table => $table1,
2530
    id => [1, 2],
2531
);
2532
is($dbi->select(table => $table1)->one->{$key1}, 1);
2533
is($dbi->select(table => $table1)->one->{$key2}, 4);
2534
is($dbi->select(table => $table1)->one->{$key3}, 3);
2535
is_deeply($param, {$key3 => 3, $key2 => 4});
2536

            
added test
Yuki Kimoto authored on 2011-10-25
2537
$dbi = DBIx::Custom->connect;
2538
eval { $dbi->execute("drop table $table1") };
2539
$dbi->execute($create_table1_2);
2540
$param = {$key3 => 3, $key2 => 4};
2541
$query = $dbi->insert(
2542
    $param,
2543
    primary_key => [$key1, $key2], 
2544
    table => $table1,
2545
    id => [1, 2],
2546
    query => 1
2547
);
micro optimization
Yuki Kimoto authored on 2011-11-16
2548
ok(ref $query);
added test
Yuki Kimoto authored on 2011-10-25
2549
is_deeply($param, {$key3 => 3, $key2 => 4});
2550

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

            
2565
$dbi = MyDBI6->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);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2568
$dbi->model($table1)->insert(
2569
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2570
    id => [1, 2]
2571
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2572
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2573
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2574
is($row->{$key1}, 1);
2575
is($row->{$key2}, 2);
2576
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2577

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2593
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2594
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2595
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2596
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2597
    table => $table1,
2598
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2599
    id => 0,
2600
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2601
is($dbi->select(table => $table1)->one->{$key1}, 0);
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
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2606
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2607
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2608
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2609
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2610
    {$key3 => 4},
2611
    table => $table1,
2612
    primary_key => [$key1, $key2],
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
is($dbi->select(table => $table1)->one->{$key1}, 1);
2616
is($dbi->select(table => $table1)->one->{$key2}, 2);
2617
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2618

            
2619

            
2620
test 'model update and id option';
2621
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2622
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2623
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2624
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2625
$dbi->model($table1)->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2626
    {$key3 => 4},
cleanup test
Yuki Kimoto authored on 2011-08-10
2627
    id => [1, 2],
2628
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2629
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2630
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2631
is($row->{$key1}, 1);
2632
is($row->{$key2}, 2);
2633
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2634

            
2635

            
2636
test 'delete and id option';
2637
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2638
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2639
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2640
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2641
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2642
    table => $table1,
2643
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2644
    id => [1, 2],
2645
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2646
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2647

            
cleanup
Yuki Kimoto authored on 2011-11-01
2648
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2649
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2650
    table => $table1,
2651
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2652
    id => 0,
2653
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2654
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2655

            
2656

            
2657
test 'model delete and id option';
2658
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2659
eval { $dbi->execute("drop table $table1") };
2660
eval { $dbi->execute("drop table $table2") };
2661
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2662
$dbi->execute($create_table1_2);
2663
$dbi->execute($create_table2_2);
2664
$dbi->execute($create_table3);
cleanup
Yuki Kimoto authored on 2011-11-01
2665
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2666
$dbi->model($table1)->delete(id => [1, 2]);
2667
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2668
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2669
$dbi->model($table1)->delete(id => [1, 2]);
2670
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2671
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2672
$dbi->model($table3)->delete(id => [1, 2]);
2673
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2674

            
2675

            
2676
test 'select and id option';
2677
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2678
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2679
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2680
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2681
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2682
    table => $table1,
2683
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2684
    id => [1, 2]
2685
);
2686
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2687
is($row->{$key1}, 1);
2688
is($row->{$key2}, 2);
2689
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2690

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2703
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2704
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2705
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2706
    table => $table1,
2707
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2708
    id => [1, 2]
2709
);
2710
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2711
is($row->{$key1}, 1);
2712
is($row->{$key2}, 2);
2713
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2714

            
2715

            
2716
test 'model select_at';
2717
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2718
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2719
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2720
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2721
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2722
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2723
is($row->{$key1}, 1);
2724
is($row->{$key2}, 2);
2725
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2726

            
2727
test 'column separator is default .';
2728
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2729
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2730
eval { $dbi->execute("drop table $table1") };
2731
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2732
$dbi->execute($create_table1);
2733
$dbi->execute($create_table2);
2734
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2735
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2736
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2737
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2738
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2739
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2740
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2741
);
2742
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2743
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2744

            
2745
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2746
    column => [$model->column($table2 => [$key1, $key3])],
2747
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2748
);
2749
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2750
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2751

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2752
test 'separator';
2753
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2754
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2755
eval { $dbi->execute("drop table $table1") };
2756
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2757
$dbi->execute($create_table1);
2758
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2759

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2760
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2761
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2762
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2763
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2764
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2765
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2766
);
2767
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2768
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2769
);
2770
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2771
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2772
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2773
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2774
$result = $model->select(
2775
    column => [
2776
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2777
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2778
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2779
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2780
);
2781
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2782
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2783
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2784

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2798
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2799
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2800
$result = $model->select(
2801
    column => [
2802
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2803
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2804
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2805
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2806
);
2807
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2808
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2809
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2810

            
2811

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2812
test 'filter_off';
2813
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2814
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2815
eval { $dbi->execute("drop table $table1") };
2816
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2817
$dbi->execute($create_table1);
2818
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2819

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2820
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2821
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2822
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2823
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2824
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2825
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2826
);
2827
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2828
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2829
$model = $dbi->model($table1);
2830
$result = $model->select(column => $key1);
2831
$result->filter($key1 => sub { $_[0] * 2 });
2832
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2833

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2834
test 'available_datetype';
2835
$dbi = DBIx::Custom->connect;
2836
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2837

            
2838

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2839
test 'select prefix option';
2840
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2841
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2842
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2843
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2844
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2845
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2846

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

            
added tests
Yuki Kimoto authored on 2011-08-26
2848
test 'mapper';
2849
$dbi = DBIx::Custom->connect;
2850
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2851
    id => {key => "$table1.id"},
2852
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2853
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
2854
);
2855
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2856
  "$table1.price" => 1900});
2857

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2858
$dbi = DBIx::Custom->connect;
2859
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2860
    id => {key => "$table1.id"},
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2861
    author => ["$table1.author" => $dbi->like_value],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2862
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2863
);
2864
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2865
  "$table1.price" => 1900});
2866

            
added tests
Yuki Kimoto authored on 2011-08-26
2867
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2868
    id => {key => "$table1.id"},
2869
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2870
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
2871
);
2872
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2873

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

            
2881
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2882
    id => {key => "$table1.id"},
2883
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2884
);
2885
is_deeply($param, {"$table1.price" => undef});
2886

            
2887
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2888
    id => {key => "$table1.id", condition => 'exists'},
2889
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
2890
);
2891
is_deeply($param, {"$table1.price" => '%a'});
2892

            
2893
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2894
    id => {key => "$table1.id"},
added tests
Yuki Kimoto authored on 2011-08-26
2895
    price => ["$table1.price", sub { '%' . $_[0] }]
2896
);
2897
is_deeply($param, {"$table1.price" => '%a'});
2898

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2899
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2900
    price => sub { '%' . $_[0] },
2901
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2902
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2903
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2904

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

            
2910
$where = $dbi->where;
2911
$where->clause(['and', ":${key1}{=}"]);
2912
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
2913
$where->param($param);
2914
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2915
$row = $result->all;
2916
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2917

            
2918
$where = $dbi->where;
2919
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2920
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
2921
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2922
$row = $result->all;
2923
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2924
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2925
$row = $result->all;
2926
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2927

            
2928
$where = $dbi->where;
2929
$where->clause(['and', ":${key1}{=}"]);
2930
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
2931
$where->param($param);
2932
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2933
$row = $result->all;
2934
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2935
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2936
$row = $result->all;
2937
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2938

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2940
$where = $dbi->where;
2941
$where->clause(['and', ":${key1}{=}"]);
2942
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
2943
  ->pass([$key1, $key2])->map;
2944
$where->param($param);
2945
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2946
$row = $result->all;
2947
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2948

            
2949
$where = $dbi->where;
2950
$where->clause(['and', ":${key1}{=}"]);
2951
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
2952
$where->param($param);
2953
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2954
$row = $result->all;
2955
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2956

            
2957
$where = $dbi->where;
2958
$where->clause(['and', ":${key1}{=}"]);
2959
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
2960
  ->pass([$key1, $key2])->map;
2961
$where->param($param);
2962
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2963
$row = $result->all;
2964
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2965

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2967
$where = $dbi->where;
2968
$where->clause(['and', ":${key1}{=}"]);
2969
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
2970
$where->param($param);
2971
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2972
$row = $result->all;
2973
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2974

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

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

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

            
3003
$where = $dbi->where;
3004
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3005
    id => {key => "$table1.id"},
3006
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3007
);
3008
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
3009

            
3010
$where = $dbi->where;
3011
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3012
    id => {key => "$table1.id", condition => 'exists'},
3013
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3014
);
3015
is_deeply($param, {"$table1.price" => '%a'});
3016

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

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

            
3035
$where = $dbi->where;
3036
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3037
    id => {key => "$table1.id", condition => 'length'},
3038
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
3039
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3040
);
3041
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
3042
  "$table1.price" => 1900});
3043

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3049
test 'order';
3050
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3051
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3052
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3053
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3054
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3055
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3056
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3057
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3058
$order->prepend($key1, "$key2 desc");
3059
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3060
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
3061
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3062
$order->prepend("$key1 desc");
3063
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3064
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
3065
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3066

            
3067
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3068
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3069
$result = $dbi->select(table => $table1,
3070
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3071
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3072
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
3073
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
3074
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
3075
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3076

            
3077
test 'tag_parse';
3078
$dbi = DBIx::Custom->connect;
3079
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3080
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3081
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3082
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3083
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3084
ok($@);
3085

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3086
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3087
{
3088
    $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3089
    $dbi = DBIx::Custom->connect;
3090
    eval { $dbi->execute("drop table $table1") };
3091
    $dbi->execute($create_table1);
3092
    $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3093
    eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3094
    ok($@);
cleanup
Yuki Kimoto authored on 2011-11-16
3095
    eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) };
3096
    ok($@);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3097
    delete$ENV{DBIX_CUSTOM_TAG_PARSE};
3098
}
3099

            
3100
{
3101
    $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3102
    $dbi = DBIx::Custom->connect;
3103
    eval { $dbi->execute("drop table $table1") };
3104
    $dbi->execute($create_table1);
3105
    $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-16
3106
    is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3107
    delete$ENV{DBIX_CUSTOM_TAG_PARSE};
3108
}
3109

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3110
test 'last_sql';
3111
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3112
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3113
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3114
$dbi->execute("select * from $table1");
micro optimization
Yuki Kimoto authored on 2011-11-18
3115
is($dbi->last_sql, " select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3116

            
3117
eval{$dbi->execute("aaa")};
micro optimization
Yuki Kimoto authored on 2011-11-18
3118
is($dbi->last_sql, ' aaa');
test cleanup
Yuki Kimoto authored on 2011-08-10
3119

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3138
$source = "select * from $table1 where :${key1}{ = } and :${key2}{=}";
cleanup
Yuki Kimoto authored on 2011-11-01
3139
$result = $dbi->execute($source, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3148
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3149
$result = $dbi->execute(
3150
    $source,
cleanup
Yuki Kimoto authored on 2011-11-01
3151
    {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3152
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3153
);
3154
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3155
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3156

            
3157
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3158
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3159
$dbi->execute($create_table1_highperformance);
3160
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3161
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3162
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3163
];
3164
{
3165
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3166
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3167
      $query ||= $dbi->insert($row, table => $table1, query => 1);
3168
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
3169
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3170
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3171
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3172
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3173
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3174
      ]
3175
    );
3176
}
3177

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3178
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3179
$dbi->execute($create_table1_highperformance);
3180
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3181
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3182
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3183
];
3184
{
3185
    my $query;
3186
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
3187
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3188
      $query ||= $dbi->insert($row, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
3189
      $sth ||= $query->{sth};
test cleanup
Yuki Kimoto authored on 2011-08-10
3190
      $sth->execute(map { $row->{$_} } sort keys %$row);
3191
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3192
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3193
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3194
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3195
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3196
      ]
3197
    );
3198
}
3199

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3200
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3201
$dbi->execute($create_table1_highperformance);
3202
$rows = [
3203
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
3204
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
3205
];
3206
{
3207
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3208
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3209
    for my $row (@$rows) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3210
      $query ||= $model->insert($row, query => 1);
3211
      $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3212
    }
3213
    is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3214
      [
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3215
          {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3216
          {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3217
      ]
3218
    );
3219
}
3220

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3221
eval { $dbi->execute("drop table $table1") };
3222
$dbi->execute($create_table1);
3223
{
3224
    $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3225
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3226
    eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3227
    like($@, qr/primary_key/);
3228
    delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
3229
}
3230

            
3231
{
3232
    $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3233
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3234
    $model->insert({$key1 => 1});
3235
    $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3236
      table => $table1, primary_key => $key1);
3237
    is($result->one->{$key1}, 1);
3238
    delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
3239
}
3240

            
3241
eval { $dbi->execute("drop table $table1") };
3242
$dbi->execute($create_table1);
3243
{
3244
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3245
    $model->insert({$key1 => 1});
3246
    eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3247
    is($result->one->{$key1}, 1);
3248
}
3249

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3250
test 'id option more';
3251
eval { $dbi->execute("drop table $table1") };
3252
$dbi->execute($create_table1_highperformance);
3253
$row = {
3254
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3255
};
3256
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3257
$model->insert($row);
3258
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3259
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3260
is_deeply($dbi->select(table => $table1)->one,
3261
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3262
);
3263

            
3264
eval { $dbi->execute("drop table $table1") };
3265
eval { $dbi->execute("drop table $table2") };
3266
$dbi->execute($create_table1);
3267
$dbi->execute($create_table2);
3268
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3269
$model->insert({$key1 => 1, $key2 => 2});
3270
$model = $dbi->create_model(table => $table2, primary_key => $key1,
3271
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
3272
$model->insert({$key1 => 1, $key3 => 3});
3273
$result = $model->select(
3274
    column => {$table1 => ["$key2"]},
3275
    id => 1
3276
);
3277
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3278

            
3279
eval { $dbi->execute("drop table $table1") };
3280
$dbi->execute($create_table1_highperformance);
3281
$row = {
3282
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3283
};
3284
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3285
$model->insert($row);
3286
$query = $model->delete(id => 1, query => 1);
3287
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3288
is_deeply($dbi->select(table => $table1)->all, []);
3289

            
3290
eval { $dbi->execute("drop table $table1") };
3291
eval { $dbi->execute($create_table1_highperformance) };
3292
$row = {
3293
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3294
};
3295
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3296
$model->insert($row);
3297
$query = $model->select(id => 1, query => 1);
3298
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3299
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3300
is_deeply($dbi->select(table => $table1)->one,
3301
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3302
);
3303

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3304
test 'result';
3305
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3306
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3307
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3308
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3309
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3310

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3311
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3312
@rows = ();
3313
while (my $row = $result->fetch) {
3314
    push @rows, [@$row];
3315
}
3316
is_deeply(\@rows, [[1, 2], [3, 4]]);
3317

            
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 = ();
3320
while (my $row = $result->fetch_hash) {
3321
    push @rows, {%$row};
3322
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3323
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3324

            
3325
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3326
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3327
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3328
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3329
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3330

            
3331
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3332
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3333
$rows = $result->fetch_all;
3334
is_deeply($rows, [[1, 2], [3, 4]]);
3335

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

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

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

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3358
test 'DBIx::Custom::Result fetch_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_multi(2);
3366
is_deeply($rows, [[1, 2], [3, 4]]);
3367
$rows = $result->fetch_multi(2);
3368
is_deeply($rows, [[5, 6]]);
3369
$rows = $result->fetch_multi(2);
3370
ok(!$rows);
3371

            
3372
test 'DBIx::Custom::Result fetch_hash_multi';
3373
eval { $dbi->execute("drop table $table1") };
3374
$dbi->execute($create_table1);
3375
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3376
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3377
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3378
$result = $dbi->select(table => $table1);
3379
$rows = $result->fetch_hash_multi(2);
3380
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3381
$rows = $result->fetch_hash_multi(2);
3382
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3383
$rows = $result->fetch_hash_multi(2);
3384
ok(!$rows);
3385

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3386
test "query_builder";
3387
$datas = [
3388
    # Basic tests
3389
    {   name            => 'placeholder basic',
3390
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3391
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3392
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3393
    },
3394
    {
3395
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3396
        source            => "{in k1 3}",
3397
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3398
        columns_expected   => [qw/k1 k1 k1/]
3399
    },
3400
    
3401
    # Table name
3402
    {
3403
        name            => 'placeholder with table name',
3404
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3405
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3406
        columns_expected  => [qw/a.k1 a.k2/]
3407
    },
3408
    {   
3409
        name            => 'placeholder in with table name',
3410
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3411
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3412
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3413
    },
3414
    {
3415
        name            => 'not contain tag',
3416
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3417
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3418
        columns_expected  => [],
3419
    }
3420
];
3421

            
3422
for (my $i = 0; $i < @$datas; $i++) {
3423
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3424
    my $dbi = DBIx::Custom->new;
3425
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3426
    my $query = $builder->build_query($data->{source});
3427
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
micro optimization
Yuki Kimoto authored on 2011-11-16
3428
    is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3429
}
3430

            
cleanup
Yuki Kimoto authored on 2011-08-13
3431
$dbi = DBIx::Custom->new;
3432
$builder = $dbi->query_builder;
3433
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3434
    p => sub {
3435
        my @args = @_;
3436
        
3437
        my $expand    = "? $args[0] $args[1]";
3438
        my $columns = [2];
3439
        return [$expand, $columns];
3440
    }
3441
);
3442

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3453
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3454
    q => 'string'
3455
});
3456

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3460
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3461
   r => sub {} 
3462
});
3463

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3467
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3468
   s => sub { return ["a", ""]} 
3469
});
3470

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3474
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3475
    t => sub {return ["a", []]}
3476
);
3477

            
3478

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

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

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

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

            
3494
test 'variouse source';
3495
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3496
$query = $builder->build_query($source);
3497
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3498

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

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

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

            
3511
$source = "a {= b} }";
3512
eval{$builder->build_query($source)};
3513
like($@, qr/unexpected "}"/, "error : 1");
3514

            
3515
$source = "a {= {}";
3516
eval{$builder->build_query($source)};
3517
like($@, qr/unexpected "{"/, "error : 2");
3518

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3537
test 'select() after_build_sql option';
3538
$dbi = DBIx::Custom->connect;
3539
$dbi->user_table_info($user_table_info);
3540
eval { $dbi->execute("drop table $table1") };
3541
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3542
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3543
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3544
$rows = $dbi->select(
3545
    table => $table1,
3546
    column => $key1,
3547
    after_build_sql => sub {
3548
        my $sql = shift;
3549
        $sql = "select * from ( $sql ) t where $key1 = 1";
3550
        return $sql;
3551
    }
3552
)->all;
3553
is_deeply($rows, [{$key1 => 1}]);
3554

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3555
test 'dbi method from model';
3556
$dbi = MyDBI9->connect;
3557
eval { $dbi->execute("drop table $table1") };
3558
$dbi->execute($create_table1);
3559
$dbi->setup_model;
3560
$model = $dbi->model($table1);
3561
eval{$model->execute("select * from $table1")};
3562
ok(!$@);
3563

            
3564
test 'column table option';
3565
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3566
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3567
eval { $dbi->execute("drop table $table1") };
3568
$dbi->execute($create_table1);
3569
eval { $dbi->execute("drop table $table2") };
3570
$dbi->execute($create_table2);
3571
$dbi->setup_model;
3572
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3573
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3574
$model = $dbi->model($table1);
3575
$result = $model->select(
3576
    column => [
3577
        $model->column($table2, {alias => $table2_alias})
3578
    ],
3579
    where => {"$table2_alias.$key3" => 4}
3580
);
3581
is_deeply($result->one, 
3582
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3583

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

            
3594
$dbi->separator('-');
3595
$result = $model->select(
3596
    column => [
3597
        $model->column($table2, {alias => $table2_alias})
3598
    ],
3599
    where => {"$table2_alias.$key3" => 4}
3600
);
3601
is_deeply($result->one, 
3602
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3603

            
3604
test 'create_model';
3605
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3606
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3607
eval { $dbi->execute("drop table $table1") };
3608
eval { $dbi->execute("drop table $table2") };
3609
$dbi->execute($create_table1);
3610
$dbi->execute($create_table2);
3611

            
3612
$dbi->create_model(
3613
    table => $table1,
3614
    join => [
3615
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3616
    ],
3617
    primary_key => [$key1]
3618
);
3619
$model2 = $dbi->create_model(
3620
    table => $table2
3621
);
3622
$dbi->create_model(
3623
    table => $table3,
3624
    filter => [
3625
        $key1 => {in => sub { uc $_[0] }}
3626
    ]
3627
);
3628
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3629
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
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->model($table1);
3632
$result = $model->select(
3633
    column => [$model->mycolumn, $model->column($table2)],
3634
    where => {"$table1.$key1" => 1}
3635
);
3636
is_deeply($result->one,
3637
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3638
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3639

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

            
3651
test 'model helper';
3652
$dbi = DBIx::Custom->connect;
3653
eval { $dbi->execute("drop table $table2") };
3654
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3655
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3656
$model = $dbi->create_model(
3657
    table => $table2
3658
);
3659
$model->helper(foo => sub { shift->select(@_) });
3660
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3661

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

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

            
3682

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

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

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

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

            
3721
            
3722
$dbi = DBIx::Custom->connect;
3723
eval { $dbi->execute("drop table $table1") };
3724
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
3725
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
3726
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3727

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

            
3741
$param = {$key2 => 11};
3742
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3743
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3744
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3745
where $key1 = 1
3746
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3747
$dbi->execute($sql, $param, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3748
$result = $dbi->execute("select * from $table1 order by $key1");
3749
$rows   = $result->all;
3750
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3751
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3752
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3753

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3754
test 'Model class';
3755
$dbi = MyDBI1->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
is($dbi->models->{$table1}, $dbi->model($table1));
3767
is($dbi->models->{$table2}, $dbi->model($table2));
3768

            
3769
$dbi = MyDBI4->connect;
3770
eval { $dbi->execute("drop table $table1") };
3771
$dbi->execute($create_table1);
3772
$model = $dbi->model($table1);
3773
$model->insert({$key1 => 'a', $key2 => 'b'});
3774
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3775
eval { $dbi->execute("drop table $table2") };
3776
$dbi->execute($create_table2);
3777
$model = $dbi->model($table2);
3778
$model->insert({$key1 => 'a'});
3779
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3780

            
3781
$dbi = MyDBI5->connect;
3782
eval { $dbi->execute("drop table $table1") };
3783
eval { $dbi->execute("drop table $table2") };
3784
$dbi->execute($create_table1);
3785
$dbi->execute($create_table2);
3786
$model = $dbi->model($table2);
3787
$model->insert({$key1 => 'a'});
3788
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
3789
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3790
$model = $dbi->model($table1);
3791
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3792

            
3793
test 'primary_key';
3794
$dbi = MyDBI1->connect;
3795
$model = $dbi->model($table1);
3796
$model->primary_key([$key1, $key2]);
3797
is_deeply($model->primary_key, [$key1, $key2]);
3798

            
3799
test 'columns';
3800
$dbi = MyDBI1->connect;
3801
$model = $dbi->model($table1);
3802
$model->columns([$key1, $key2]);
3803
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3804

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3805
test 'setup_model';
3806
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3807
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3808
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3809
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3810

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3811
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3812
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3813
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3814
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3815
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3816

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3817
test 'each_column';
3818
$dbi = DBIx::Custom->connect;
3819
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3820
eval { $dbi->execute("drop table $table1") };
3821
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3822
eval { $dbi->execute("drop table $table3") };
3823
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3824
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3825

            
3826
$infos = [];
3827
$dbi->each_column(sub {
3828
    my ($self, $table, $column, $cinfo) = @_;
3829
    
3830
    if ($table =~ /^table\d/i) {
3831
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3832
         push @$infos, $info;
3833
    }
3834
});
3835
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3836
is_deeply($infos, 
3837
    [
3838
        [$table1, $key1, $key1],
3839
        [$table1, $key2, $key2],
3840
        [$table2, $key1, $key1],
3841
        [$table2, $key3, $key3]
3842
    ]
3843
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3844
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3845

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3846
test 'each_table';
3847
$dbi = DBIx::Custom->connect;
3848
eval { $dbi->execute("drop table $table1") };
3849
eval { $dbi->execute("drop table $table2") };
3850
$dbi->execute($create_table2);
3851
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3852

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3853
$infos = [];
3854
$dbi->each_table(sub {
3855
    my ($self, $table, $table_info) = @_;
3856
    
3857
    if ($table =~ /^table\d/i) {
3858
         my $info = [$table, $table_info->{TABLE_NAME}];
3859
         push @$infos, $info;
3860
    }
3861
});
3862
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3863
is_deeply($infos, 
3864
    [
3865
        [$table1, $table1],
3866
        [$table2, $table2],
3867
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3868
);
3869

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3870
$dbi = DBIx::Custom->connect;
3871
eval { $dbi->execute("drop table $table1") };
3872
eval { $dbi->execute("drop table $table2") };
3873
$dbi->execute($create_table2);
3874
$dbi->execute($create_table1_type);
3875

            
3876
$infos = [];
3877
$dbi->user_table_info($user_table_info);
3878
$dbi->each_table(sub {
3879
    my ($self, $table, $table_info) = @_;
3880
    
3881
    if ($table =~ /^table\d/i) {
3882
         my $info = [$table, $table_info->{TABLE_NAME}];
3883
         push @$infos, $info;
3884
    }
3885
});
3886
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3887
is_deeply($infos, 
3888
    [
3889
        [$table1, $table1],
3890
        [$table2, $table2],
3891
        [$table3, $table3],
3892
    ]
3893
);
3894

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3895
test 'type_rule into';
3896
eval { $dbi->execute("drop table $table1") };
3897
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3898
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3899

            
3900

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3901
$dbi = DBIx::Custom->connect;
3902
eval { $dbi->execute("drop table $table1") };
3903
$dbi->execute($create_table1_type);
3904

            
cleanup
Yuki Kimoto authored on 2011-08-16
3905
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3906
$dbi->type_rule(
3907
    into1 => {
3908
        $date_typename => sub { '2010-' . $_[0] }
3909
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3910
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3911
$dbi->insert({$key1 => '01-01'}, table => $table1);
3912
$result = $dbi->select(table => $table1);
3913
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3914

            
3915
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3916
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3917
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3918
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3919
$dbi->type_rule(
3920
    into1 => [
3921
         [$date_typename, $datetime_typename] => sub {
3922
            my $value = shift;
3923
            $value =~ s/02/03/g;
3924
            return $value;
3925
         }
3926
    ]
3927
);
3928
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3929
$result = $dbi->select(table => $table1);
3930
$row = $result->one;
3931
like($row->{$key1}, qr/^2010-01-03/);
3932
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3933

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

            
3956
$dbi = DBIx::Custom->connect;
3957
eval { $dbi->execute("drop table $table1") };
3958
$dbi->execute($create_table1_type);
3959
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3960
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3961
$dbi->type_rule(
3962
    into1 => [
3963
        [$date_typename, $datetime_typename] => sub {
3964
            my $value = shift;
3965
            $value =~ s/02/03/g;
3966
            return $value;
3967
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3968
    ]
3969
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3970
$result = $dbi->execute(
3971
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
3972
    {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
cleanup test
Yuki Kimoto authored on 2011-08-15
3973
    table => $table1
3974
);
3975
$row = $result->one;
3976
like($row->{$key1}, qr/^2010-01-03/);
3977
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3978

            
3979
$dbi = DBIx::Custom->connect;
3980
eval { $dbi->execute("drop table $table1") };
3981
$dbi->execute($create_table1_type);
3982
$dbi->register_filter(convert => sub {
3983
    my $value = shift || '';
3984
    $value =~ s/02/03/;
3985
    return $value;
3986
});
cleanup
Yuki Kimoto authored on 2011-08-16
3987
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3988
$dbi->type_rule(
3989
    from1 => {
3990
        $date_datatype => 'convert',
3991
    },
3992
    into1 => {
3993
        $date_typename => 'convert',
3994
    }
3995
);
3996
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3997
$result = $dbi->select(table => $table1);
3998
like($result->fetch->[0], qr/^2010-03-03/);
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3999
$result = $dbi->select(column => [$key1, $key1], table => $table1);
4000
$row = $result->fetch;
4001
like($row->[0], qr/^2010-03-03/);
4002
like($row->[1], qr/^2010-03-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4003

            
4004
test 'type_rule and filter order';
4005
$dbi = DBIx::Custom->connect;
4006
eval { $dbi->execute("drop table $table1") };
4007
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4008
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4009
$dbi->type_rule(
4010
    into1 => {
4011
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4012
    },
4013
    into2 => {
4014
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4015
    },
4016
    from1 => {
4017
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4018
    },
4019
    from2 => {
4020
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
4021
    }
4022
);
4023
$dbi->insert({$key1 => '2010-01-03'}, 
4024
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
4025
$result = $dbi->select(table => $table1);
4026
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
4027
like($result->fetch_first->[0], qr/^2010-01-09/);
4028

            
4029

            
4030
$dbi = DBIx::Custom->connect;
4031
eval { $dbi->execute("drop table $table1") };
4032
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4033
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4034
$dbi->type_rule(
4035
    from1 => {
4036
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4037
    },
4038
    from2 => {
4039
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4040
    },
4041
);
4042
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4043
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4044
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4045
$result->type_rule(
4046
    from1 => {
4047
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4048
    },
4049
    from2 => {
4050
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
4051
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4052
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4053
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
4054
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4055

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

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

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

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

            
4121
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4122
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4123
$dbi->execute($create_table1_type);
4124
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
4125
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4126
$dbi->type_rule(
4127
    into1 => {
4128
        $date_typename => 'ppp'
4129
    }
4130
);
4131
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4132
$result = $dbi->select(table => $table1);
4133
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4134

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4135
eval{$dbi->type_rule(
4136
    into1 => {
4137
        $date_typename => 'pp'
4138
    }
4139
)};
4140
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4141

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4142
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4143
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4144
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4145
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
4146
    $dbi->type_rule(
4147
        from1 => {
4148
            Date => sub { $_[0] * 2 },
4149
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
4150
    );
4151
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4152
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4153

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4154
eval {
4155
    $dbi->type_rule(
4156
        into1 => {
4157
            Date => sub { $_[0] * 2 },
4158
        }
4159
    );
4160
};
4161
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4162

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

            
4180
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4181
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4182
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4183
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4184
$dbi->type_rule(
4185
    from1 => {
4186
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4187
        $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4188
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
4189
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4190
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
4191
$result = $dbi->select(table => $table1);
4192
$result->type_rule(
4193
    from1 => {
4194
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4195
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4196
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4197
$row = $result->one;
4198
like($row->{$key1}, qr/^2010-01-05/);
4199
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4200

            
4201
$result = $dbi->select(table => $table1);
4202
$result->type_rule(
4203
    from1 => {
4204
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4205
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4206
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4207
$row = $result->one;
4208
like($row->{$key1}, qr/2010-01-05/);
4209
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4210

            
4211
$result = $dbi->select(table => $table1);
4212
$result->type_rule(
4213
    from1 => {
4214
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4215
    }
4216
);
4217
$row = $result->one;
4218
like($row->{$key1}, qr/2010-01-05/);
4219
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4220

            
4221
$result = $dbi->select(table => $table1);
4222
$result->type_rule(
4223
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
4224
);
4225
$row = $result->one;
4226
like($row->{$key1}, qr/2010-01-05/);
4227
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4228

            
4229
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4230
$result = $dbi->select(table => $table1);
4231
$result->type_rule(
4232
    from1 => [$date_datatype => 'five']
4233
);
4234
$row = $result->one;
4235
like($row->{$key1}, qr/^2010-01-05/);
4236
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4237

            
4238
$result = $dbi->select(table => $table1);
4239
$result->type_rule(
4240
    from1 => [$date_datatype => undef]
4241
);
4242
$row = $result->one;
4243
like($row->{$key1}, qr/^2010-01-03/);
4244
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4245

            
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
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
4254
);
cleanup test
Yuki Kimoto authored on 2011-08-15
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->one->{$key1}, qr/^2010-01-05/);
cleanup test
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
    from1 => {
4266
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4267
    },
4268
);
4269
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4270
$result = $dbi->select(table => $table1);
4271
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4272
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4273

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4274
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4275
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4276
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4277
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4278
$dbi->type_rule(
4279
    into1 => {
4280
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4281
    },
4282
    into2 => {
4283
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4284
    },
4285
    from1 => {
4286
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4287
    },
4288
    from2 => {
4289
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4290
    }
4291
);
4292
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4293
$result = $dbi->select(table => $table1);
4294
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/);
4295
$result = $dbi->select(table => $table1);
4296
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4297

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4298
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4299
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4300
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4301
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4302
$dbi->type_rule(
4303
    into1 => {
4304
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4305
    },
4306
    into2 => {
4307
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4308
    },
4309
    from1 => {
4310
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
4311
    },
4312
    from2 => {
4313
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4314
    }
4315
);
4316
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4317
$result = $dbi->select(table => $table1);
4318
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/);
4319
$result = $dbi->select(table => $table1);
4320
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4321

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4322
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4323
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4324
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4325
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4326
$dbi->type_rule(
4327
    into1 => {
4328
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4329
    },
4330
    into2 => {
4331
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4332
    },
4333
    from1 => {
4334
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4335
    },
4336
    from2 => {
4337
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4338
    }
4339
);
4340
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4341
$result = $dbi->select(table => $table1);
4342
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
4343
$result = $dbi->select(table => $table1);
4344
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4345

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

            
4366
$dbi = DBIx::Custom->connect;
4367
eval { $dbi->execute("drop table $table1") };
4368
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4369
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4370
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4371
eval { $dbi->execute("drop table $table2") };
4372
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4373
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4374
eval { $dbi->execute("drop table $table3") };
4375
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4376
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4377
$rows = $dbi->select(
4378
    table => $table1,
4379
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4380
    where   => {"$table1.$key2" => 2},
4381
    join  => {
4382
        clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4383
        table => [$table1, $table2]
4384
    }
4385
)->all;
4386
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
4387

            
4388
$rows = $dbi->select(
4389
    table => $table1,
4390
    where   => {$key1 => 1},
4391
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4392
)->all;
4393
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4394

            
4395
$rows = $dbi->select(
4396
    table => $table1,
4397
    where   => {$key1 => 1},
4398
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4399
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4400
)->all;
4401
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4402

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

            
4412
$rows = $dbi->select(
4413
    column => "$table1.$key1 as ${table1}__$key1",
4414
    table => $table1,
4415
    where   => {"$table3.$key4" => 4},
4416
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4417
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4418
)->all;
4419
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4420

            
4421
$dbi = DBIx::Custom->connect;
4422
eval { $dbi->execute("drop table $table1") };
4423
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4424
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4425
eval { $dbi->execute("drop table $table2") };
4426
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4427
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4428
$rows = $dbi->select(
4429
    table => $table1,
4430
    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",
4431
    where   => {"$table1.$key2" => 2},
4432
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4433
)->all;
4434
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4435
          'quote');
4436

            
4437

            
4438
$dbi = DBIx::Custom->connect;
4439
eval { $dbi->execute("drop table $table1") };
4440
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4441
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4442
$sql = <<"EOS";
4443
left outer join (
4444
  select * from $table1 t1
4445
  where t1.$key2 = (
4446
    select max(t2.$key2) from $table1 t2
4447
    where t1.$key1 = t2.$key1
4448
  )
4449
) $table3 on $table1.$key1 = $table3.$key1
4450
EOS
4451
$join = [$sql];
4452
$rows = $dbi->select(
4453
    table => $table1,
4454
    column => "$table3.$key1 as ${table3}__$key1",
4455
    join  => $join
4456
)->all;
4457
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4458

            
4459
$dbi = DBIx::Custom->connect;
4460
eval { $dbi->execute("drop table $table1") };
4461
eval { $dbi->execute("drop table $table2") };
4462
$dbi->execute($create_table1);
4463
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4464
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4465
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4466
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4467
$result = $dbi->select(
4468
    table => $table1,
4469
    join => [
4470
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4471
    ]
4472
);
4473
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4474
$result = $dbi->select(
4475
    table => $table1,
4476
    column => [{$table2 => [$key3]}],
4477
    join => [
4478
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4479
    ]
4480
);
4481
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4482
$result = $dbi->select(
4483
    table => $table1,
4484
    column => [{$table2 => [$key3]}],
4485
    join => [
4486
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4487
    ]
4488
);
4489
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4490

            
4491
$dbi = DBIx::Custom->connect;
4492
eval { $dbi->execute("drop table $table1") };
4493
eval { $dbi->execute("drop table $table2") };
4494
$dbi->execute($create_table1);
4495
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4496
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4497
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4498
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4499
$result = $dbi->select(
4500
    table => $table1,
4501
    column => [{$table2 => [$key3]}],
4502
    join => [
4503
        {
4504
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4505
            table => [$table1, $table2]
4506
        }
4507
    ]
4508
);
4509
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4510

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

            
4528
$dbi = DBIx::Custom->connect;
4529
eval { $dbi->execute("drop table $table1") };
4530
eval { $dbi->execute("drop table $table2") };
4531
$dbi->execute($create_table1);
4532
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4533
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4534
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4535
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4536
$result = $dbi->select(
4537
    table => $table1,
4538
    column => [{$table2 => [$key3]}],
4539
    join => [
4540
        "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4541
    ]
4542
);
4543
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4544

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4545
test 'columns';
4546
$dbi = MyDBI1->connect;
4547
$model = $dbi->model($table1);
4548

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4549
test 'count';
4550
$dbi = DBIx::Custom->connect;
4551
eval { $dbi->execute("drop table $table1") };
4552
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4553
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4554
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4555
is($dbi->count(table => $table1), 2);
4556
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4557
$model = $dbi->create_model(table => $table1);
4558
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4559

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