DBIx-Custom / t / common.t /
Newer Older
4614 lines | 154.904kb
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;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
301
is_deeply($rows, [[1, 2], [3, 4]]);
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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
307
is_deeply($dbi->select($key1, table => $table1)->column, [1, 3]);
308

            
309
is($dbi->select('count(*)', table => $table1)->value, 2);
310
ok(!defined $dbi->select($key1, table => $table1, where => {$key1 => 10})->value);
311

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

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

            
326
test 'Filter basic';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
327
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-08
328
$dbi->register_filter(twice       => sub { $_[0] * 2}, 
329
                    three_times => sub { $_[0] * 3});
330

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-08
410
test 'Named placeholder';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
411
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
412
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
413
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
414
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
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 = :$key1 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 = \n:$key1\n and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-11-01
422
$result = $dbi->execute($source, {$key1 => 1, $key2 => 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 = :$key1 or $key1 = :$key1";
test cleanup
Yuki Kimoto authored on 2011-11-01
427
$result = $dbi->execute($source, {$key1 => [1, 2]});
cleanup test
Yuki Kimoto authored on 2011-08-08
428
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
429
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
430

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

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

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

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

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

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
487
$dbi->execute("delete from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
488
$dbi->register_filter(
489
    twice       => sub { $_[0] * 2 },
490
    three_times => sub { $_[0] * 3 }
491
);
492
$dbi->default_bind_filter('twice');
test cleanup
Yuki Kimoto authored on 2011-11-01
493
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
cleanup test
Yuki Kimoto authored on 2011-08-15
494
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
495
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
496
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
497
$dbi->delete_all(table => $table1);
498
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
499
$result = $dbi->execute("select * from $table1");
500
$rows   = $result->all;
501
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-10
502
$dbi->default_bind_filter(undef);
503

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
504

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
514
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
515
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
516
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
test cleanup
Yuki Kimoto authored on 2011-11-01
517
$dbi->insert({select => 1}, table => 'table');
cleanup test
Yuki Kimoto authored on 2011-08-10
518
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
519
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
520
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
cleanup test
Yuki Kimoto authored on 2011-08-10
521

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
530
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
531
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
532
$dbi->insert({$key1 => \"'1'", $key2 => 2}, table => $table1);
533
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
534
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
535
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
536
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
537

            
updated pod
Yuki Kimoto authored on 2011-09-02
538
eval { $dbi->execute("drop table $table1") };
539
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
540
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
updated pod
Yuki Kimoto authored on 2011-09-02
541
  wrap => {$key1 => sub { "$_[0] - 1" }});
test cleanup
Yuki Kimoto authored on 2011-11-01
542
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
updated pod
Yuki Kimoto authored on 2011-09-02
543
$result = $dbi->execute("select * from $table1");
544
$rows   = $result->all;
545
is_deeply($rows, [{$key1 => 0, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
546

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
557
eval { $dbi->execute("drop table $table1") };
558
$dbi->execute($create_table1);
559
$dbi->insert_timestamp(
560
    [$key1, $key2] => sub { 5 }
561
);
562
$dbi->insert(table => $table1, timestamp => 1);
563
$result = $dbi->execute("select * from $table1");
564
$rows   = $result->all;
565
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
566

            
567
eval { $dbi->execute("drop table $table1") };
568
$dbi->execute($create_table1);
569
$dbi->insert_timestamp(
570
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
571
);
572
$dbi->insert(table => $table1, timestamp => 1);
573
$result = $dbi->execute("select * from $table1");
574
$rows   = $result->all;
575
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
576

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

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
609
eval { $dbi->execute("drop table $table1") };
610
$dbi->execute($create_table1_2);
611
$model = $dbi->create_model(table => $table1, created_at => $key2);
612
$param = {$key1 => 1};
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->{$key2}, 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, 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->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
630

            
631
eval { $dbi->execute("drop table $table1") };
632
$dbi->execute($create_table1_2);
633
$param = {$key1 => 1};
634
$model = $dbi->create_model(table => $table1, created_at => $key2, updated_at => $key3);
635
$model->insert($param);
636
$result = $dbi->select(table => $table1);
637
is_deeply($param, {$key1 => 1});
638
$row   = $result->one;
639
is($row->{$key1}, 1);
640
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
641
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
642
is($row->{$key2}, $row->{$key3});
643

            
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
644
eval { $dbi->execute("drop table $table1") };
645
$dbi->execute($create_table1);
646
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] , table => $table1);
647
$result = $dbi->execute("select * from $table1");
648
$rows   = $result->all;
649
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
650

            
651
eval { $dbi->execute("drop table $table1") };
652
$dbi->execute($create_table1_2);
653
$dbi->insert([{$key1 => 1}, {$key1 => 3}] ,
654
  table => $table1,
655
  updated_at => $key2,
656
  created_at => $key3
657
);
658
$result = $dbi->execute("select * from $table1");
659
$rows   = $result->all;
660
is($rows->[0]->{$key1}, 1);
661
is($rows->[1]->{$key1}, 3);
662
like($rows->[0]->{$key2}, qr/\d{2}:/);
663
like($rows->[1]->{$key2}, qr/\d{2}:/);
664
like($rows->[0]->{$key3}, qr/\d{2}:/);
665
like($rows->[1]->{$key3}, qr/\d{2}:/);
666

            
667
eval { $dbi->execute("drop table $table1") };
668
$dbi->execute($create_table1);
669
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] ,
670
  table => $table1, filter => {$key1 => sub { $_[0] * 2 }});
671
$result = $dbi->execute("select * from $table1");
672
$rows   = $result->all;
673
is_deeply($rows, [{$key1 => 2, $key2 => 2}, {$key1 => 6, $key2 => 4}], "basic");
674

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
675
test 'update_or_insert';
676
eval { $dbi->execute("drop table $table1") };
677
$dbi->execute($create_table1);
678
$dbi->update_or_insert(
679
    {$key2 => 2},
680
    table => $table1,
681
    primary_key => $key1,
682
    id => 1
683
);
684
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
685
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
686

            
687
$dbi->update_or_insert(
688
    {$key2 => 3},
689
    table => $table1,
690
    primary_key => $key1,
691
    id => 1
692
);
693
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
694
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
695

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
696
eval {
697
    $dbi->update_or_insert(
698
        {$key2 => 3},
699
        table => $table1,
700
    );
701
};
702

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

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

            
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
716
eval { $dbi->execute("drop table $table1") };
717
$dbi->execute($create_table1);
718
$dbi->update_or_insert(
719
    {},
720
    table => $table1,
721
    primary_key => $key1,
722
    id => 1
723
);
724
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
725
is($row->{$key1}, 1);
726

            
727
eval { 
728
    $affected = $dbi->update_or_insert(
729
        {},
730
        table => $table1,
731
        primary_key => $key1,
732
        id => 1
733
    );
734
};
735
is($affected, 0);
736

            
micro optimization
Yuki Kimoto authored on 2011-10-31
737
test 'model update_or_insert';
738
eval { $dbi->execute("drop table $table1") };
739
$dbi->execute($create_table1);
740
$model = $dbi->create_model(
741
    table => $table1,
742
    primary_key => $key1
743
);
744
$model->update_or_insert({$key2 => 2}, id => 1);
745
$row = $model->select(id => 1)->one;
746
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
747

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
748
eval {
749
    $model->insert({$key1 => 1});
750
    $model->update_or_insert(
751
        {$key2 => 3},
752
        id => 1
753
    );
754
};
755
like($@, qr/one/);
756

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
757
test 'default_bind_filter';
758
$dbi->execute("delete from $table1");
759
$dbi->register_filter(
760
    twice       => sub { $_[0] * 2 },
761
    three_times => sub { $_[0] * 3 }
762
);
763
$dbi->default_bind_filter('twice');
cleanup
Yuki Kimoto authored on 2011-11-01
764
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
765
$result = $dbi->execute("select * from $table1");
766
$rows   = $result->all;
767
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
768
$dbi->default_bind_filter(undef);
769

            
test cleanup
Yuki Kimoto authored on 2011-08-10
770
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
771
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
772
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
773
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
774
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
775
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
776
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
777
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
778
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
779
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
780
                  "basic");
added tests
Yuki Kimoto authored on 2011-11-01
781

            
782
eval { $dbi->execute("drop table $table1") };
783
$dbi->execute($create_table1_2);
784
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
785
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
786
$dbi->update(param => {$key2 => 11}, table => $table1, where => {$key1 => 1});
787
$result = $dbi->execute("select * from $table1 order by $key1");
788
$rows   = $result->all;
789
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
790
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
791
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
792
                  
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
793
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
794
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
795
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
796
$dbi->update({$key2 => 12}, table => $table1, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
797
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
798
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
799
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
800
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
801
                  "update key same as search key");
802

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
810
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
811
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
812
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
813
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
814
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
815
              filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
816
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
817
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
818
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
819
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
820
                  "filter");
821

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

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

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

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

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
867
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
868
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
869
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
870
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
871
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
872
$dbi->insert({select => 1}, table => 'table');
873
$dbi->update({update => 2}, table => 'table', where => {select => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
874
$result = $dbi->execute("select * from ${q}table$p");
875
$rows   = $result->all;
876
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
877

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
891
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
892
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
893
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
894
$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
895
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
896
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
897
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
898
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
899
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
900
                  "basic");
901

            
updated pod
Yuki Kimoto authored on 2011-09-02
902
eval { $dbi->execute("drop table $table1") };
903
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
904
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
905
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
906
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
updated pod
Yuki Kimoto authored on 2011-09-02
907
wrap => {$key2 => sub { "$_[0] - 1" }});
908
$result = $dbi->execute("select * from $table1 order by $key1");
909
$rows   = $result->all;
910
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5},
911
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
912
                  "basic");
913

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
914
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
915
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
916
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
917
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
918
$dbi->update({$key2 => \"'11'"}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
919
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
920
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
921
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
922
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
923
                  "basic");
924

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
925
eval { $dbi->execute("drop table $table1") };
926
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
927
$dbi->update_timestamp(
928
    $key1 => '5'
929
);
test cleanup
Yuki Kimoto authored on 2011-11-01
930
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
931
$dbi->update(table => $table1, timestamp => 1, where => {$key2 => 2});
932
$result = $dbi->execute("select * from $table1");
933
$rows   = $result->all;
934
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
935

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
936
eval { $dbi->execute("drop table $table1") };
937
$dbi->execute($create_table1);
938
$dbi->update_timestamp(
939
    [$key1, $key2] => sub { '5' }
940
);
test cleanup
Yuki Kimoto authored on 2011-11-01
941
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
942
$dbi->update_all(table => $table1, timestamp => 1);
943
$result = $dbi->execute("select * from $table1");
944
$rows   = $result->all;
945
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
946

            
947
eval { $dbi->execute("drop table $table1") };
948
$dbi->execute($create_table1);
949
$dbi->update_timestamp(
950
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
951
);
test cleanup
Yuki Kimoto authored on 2011-11-01
952
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
953
$dbi->update_all(table => $table1, timestamp => 1);
954
$result = $dbi->execute("select * from $table1");
955
$rows   = $result->all;
956
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
957

            
micro optimization and
Yuki Kimoto authored on 2011-10-25
958
eval { $dbi->execute("drop table $table1") };
959
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
960
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
961
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
962
$param = {$key2 => 11};
963
$dbi->update($param, table => $table1, where => {$key1 => 1});
964
is_deeply($param, {$key2 => 11});
965
$result = $dbi->execute("select * from $table1 order by $key1");
966
$rows   = $result->all;
967
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
968
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
969
                  "basic");
970

            
971
eval { $dbi->execute("drop table $table1") };
972
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
973
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
974
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
975
$param = {$key2 => 11};
976
$dbi->update($param, table => $table1, where => {$key2 => 2});
977
is_deeply($param, {$key2 => 11});
978
$result = $dbi->execute("select * from $table1 order by $key1");
979
$rows   = $result->all;
980
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
981
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
982
                  "basic");
983

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
984
eval { $dbi->execute("drop table $table1") };
985
$dbi->execute($create_table1_2);
986
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
987
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
988
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key1 => 1});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
989
$result = $dbi->select(table => $table1);
990
is_deeply($param, {$key3 => 4});
991
$row   = $result->one;
992
is($row->{$key3}, 4);
993
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
994

            
995
eval { $dbi->execute("drop table $table1") };
996
$dbi->execute($create_table1_2);
997
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
998
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
999
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key3 => 3});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1000
$result = $dbi->select(table => $table1);
1001
is_deeply($param, {$key3 => 4});
1002
$row   = $result->one;
1003
is($row->{$key3}, 4);
1004
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1005

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
1006
eval { $dbi->execute("drop table $table1") };
1007
$dbi->execute($create_table1_2);
1008
$model = $dbi->create_model(table => $table1, updated_at => $key2);
1009
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1010
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
1011
$model->update($param, where => {$key1 => 1});
1012
$result = $dbi->select(table => $table1);
1013
is_deeply($param, {$key3 => 4});
1014
$row   = $result->one;
1015
is($row->{$key3}, 4);
1016
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1017

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1018
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1019
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1020
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1021
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1022
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1023
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
1024
$dbi->update_all({$key2 => 10}, table => $table1, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1025
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1026
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1027
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
1028
                  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
1029
                  "filter");
1030

            
1031

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
1042
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
1043
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1044
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1045
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1046
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
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;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1049
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1050

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1053
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1054
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1055
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1056
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
1057
$rows = $dbi->select(table => $table1)->all;
1058
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1059

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1060
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1061
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1062
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1063
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1064
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1065
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1066
$where->param({ke1 => 1, $key2 => 2});
1067
$dbi->delete(table => $table1, where => $where);
1068
$result = $dbi->select(table => $table1);
1069
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1070

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1085
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1086
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1087
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1088
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
1089
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1090
$rows   = $result->all;
1091
is_deeply($rows, [], "basic");
1092

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1102
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
1103
$dbi = DBIx::Custom->connect;
1104
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1105
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1106
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1107
$dbi->insert({select => 1}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1108
$dbi->delete(table => 'table', where => {select => 1});
1109
$result = $dbi->execute("select * from ${q}table$p");
1110
$rows   = $result->all;
1111
is_deeply($rows, [], "reserved word");
1112

            
1113
test 'delete_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1114
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1115
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1116
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1117
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1118
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1119
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1120
$rows   = $result->all;
1121
is_deeply($rows, [], "basic");
1122

            
1123

            
1124
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1125
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1126
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1127
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1128
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1129
$rows = $dbi->select(table => $table1)->all;
1130
is_deeply($rows, [{$key1 => 1, $key2 => 2},
1131
                  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
1132

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1147
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1148
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
1149
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1150
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1151
    table => [$table1, $table2],
1152
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
1153
    where   => {"$table1.$key2" => 2},
1154
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1155
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1156
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
1157

            
1158
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1159
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1160
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1161
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1162
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1163
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
1164

            
1165
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
1166
eval { $dbi->execute("drop table ${q}table$p") };
1167
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1168
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1169
$dbi->insert({select => 1, update => 2}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1170
$result = $dbi->select(table => 'table', where => {select => 1});
1171
$rows   = $result->all;
1172
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
1173

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
1174
eval { $dbi->execute("drop table $table1") };
1175
$dbi->execute($create_table1);
1176
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1177
$row = $dbi->select($key1, table => $table1)->one;
1178
is_deeply($row, {$key1 => 1});
1179

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1180
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1181
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1182
$dbi->register_filter(
1183
    twice       => sub { $_[0] * 2 },
1184
    three_times => sub { $_[0] * 3 }
1185
);
1186
$dbi->default_fetch_filter('twice');
1187
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1188
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1189
$result = $dbi->select(table => $table1);
1190
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1191
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1192
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1193

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1194
$dbi->default_fetch_filter('twice');
1195
eval { $dbi->execute("drop table $table1") };
1196
$dbi->execute($create_table1);
1197
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1198
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1199
$result->filter({$key1 => 'three_times'});
1200
$row = $result->fetch_first;
1201
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter");
1202

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1203
test 'filters';
1204
$dbi = DBIx::Custom->new;
1205

            
1206
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
1207
   'あ', "decode_utf8");
1208

            
1209
is($dbi->filters->{encode_utf8}->('あ'),
1210
   encode_utf8('あ'), "encode_utf8");
1211

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1212
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1213
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1214
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1215
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1216
$dbi->begin_work;
1217
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1218
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1219
$dbi->rollback;
1220
$dbi->dbh->{AutoCommit} = 1;
1221

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

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

            
1226
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1227
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1228
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1229
$dbi->begin_work;
1230
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1231
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1232
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1233
$dbi->commit;
1234
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1235
$result = $dbi->select(table => $table1);
1236
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1237
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1238

            
1239
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1240
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1241
$dbi->execute($create_table1);
1242
{
1243
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1244
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1245
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1246
    like($@, qr/\.t /, "fail : not verbose");
1247
}
1248
{
1249
    local $Carp::Verbose = 1;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1250
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1251
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1252
}
1253

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

            
1259
{
1260
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1261
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1262
    like($@, qr/\Q.t /, "caller spec : not vebose");
1263
}
1264
{
1265
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1266
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1267
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1268
}
1269

            
1270

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1271
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1272
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1273
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1274
$dbi->execute($create_table1);
1275

            
1276
$dbi->begin_work;
1277

            
1278
eval {
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
    die "Error";
test cleanup
Yuki Kimoto authored on 2011-11-01
1281
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1282
};
1283

            
1284
$dbi->rollback if $@;
1285

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

            
1290
$dbi->begin_work;
1291

            
1292
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1293
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1294
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1295
};
1296

            
1297
$dbi->commit unless $@;
1298

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

            
1303
$dbi->dbh->{AutoCommit} = 0;
1304
eval{ $dbi->begin_work };
1305
ok($@, "exception");
1306
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1307

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1308
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1309
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1310
$dbi->cache(1);
1311
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1312
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1313
$dbi->execute($source, {}, query => 1);
1314
is_deeply($dbi->{_cached}->{$source}, 
micro optimization
Yuki Kimoto authored on 2011-11-18
1315
          {sql => " select * from $table1 where $key1 = ?  and $key2 = ? ", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1316

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1317
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1318
$dbi->execute($create_table1);
1319
$dbi->{_cached} = {};
1320
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1321
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1322
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1323

            
1324
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1325
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1326
$dbi->execute($create_table1);
1327
{
1328
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1329
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1330
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1331
    like($@, qr/\.t /, "fail : not verbose");
1332
}
1333
{
1334
    local $Carp::Verbose = 1;
- removed argument checking ...
Yuki Kimoto authored on 2011-10-21
1335
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1336
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1337
}
1338

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

            
1344
{
1345
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1346
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1347
    like($@, qr/\Q.t /, "caller spec : not vebose");
1348
}
1349
{
1350
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1351
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1352
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1353
}
1354

            
1355
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1356
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1357
    one => sub { 1 }
1358
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1359
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1360
    two => sub { 2 }
1361
);
1362
$dbi->method({
1363
    twice => sub {
1364
        my $self = shift;
1365
        return $_[0] * 2;
1366
    }
1367
});
1368

            
1369
is($dbi->one, 1, "first");
1370
is($dbi->two, 2, "second");
1371
is($dbi->twice(5), 10 , "second");
1372

            
1373
eval {$dbi->XXXXXX};
1374
ok($@, "not exists");
1375

            
1376
test 'out filter';
1377
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1378
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1379
$dbi->execute($create_table1);
1380
$dbi->register_filter(twice => sub { $_[0] * 2 });
1381
$dbi->register_filter(three_times => sub { $_[0] * 3});
1382
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1383
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1384
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
1385
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1386
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1387
$row   = $result->fetch_hash_first;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1388
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1389
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1390
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1391
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
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->register_filter(three_times => sub { $_[0] * 3});
1398
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1399
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1400
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1401
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1402
    $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1403
); 
test cleanup
Yuki Kimoto authored on 2011-11-01
1404
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1405
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1406
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1407
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1408

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

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

            
1435
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1436
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1437
$dbi->execute($create_table1);
1438
$dbi->register_filter(twice => sub { $_[0] * 2 });
1439
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1440
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1441
);
cleanup
Yuki Kimoto authored on 2011-11-01
1442
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1443
$result = $dbi->select(table => $table1, where => {$key1 => 1});
1444
$result->filter({$key2 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1445
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1446
is_deeply($rows, [{$key1 => 4, $key2 => 4}], "select");
test cleanup
Yuki Kimoto authored on 2011-08-10
1447

            
1448
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1449
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1450
$dbi->execute($create_table1);
1451
$dbi->register_filter(twice => sub { $_[0] * 2 });
1452
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1453
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1454
);
cleanup
Yuki Kimoto authored on 2011-11-01
1455
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1456
$result = $dbi->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
1457
                        {$key1 => 1, $key2 => 2},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1458
                        table => [$table1]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1459
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1460
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute");
test cleanup
Yuki Kimoto authored on 2011-08-10
1461

            
1462
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1463
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1464
$dbi->execute($create_table1);
1465
$dbi->register_filter(twice => sub { $_[0] * 2 });
1466
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1467
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1468
);
cleanup
Yuki Kimoto authored on 2011-11-01
1469
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1470
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
1471
                        {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1472
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1473
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1474

            
1475
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1476
eval { $dbi->execute("drop table $table1") };
1477
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1478
$dbi->execute($create_table1);
1479
$dbi->execute($create_table2);
1480
$dbi->register_filter(twice => sub { $_[0] * 2 });
1481
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1482
$dbi->apply_filter(
cleanup test
Yuki Kimoto authored on 2011-08-15
1483
    $table1, $key2 => {out => 'twice', in => 'twice'}
1484
);
1485
$dbi->apply_filter(
1486
    $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1487
);
cleanup
Yuki Kimoto authored on 2011-11-01
1488
$dbi->insert({$key1 => 5, $key2 => 2}, table => $table1, filter => {$key2 => undef});
1489
$dbi->insert({$key1 => 5, $key3 => 6}, table => $table2, filter => {$key3 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1490
$result = $dbi->select(
1491
     table => [$table1, $table2],
1492
     column => [$key2, $key3],
1493
     where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1494

            
1495
$result->filter({$key2 => 'twice'});
1496
$rows   = $result->all;
1497
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1498

            
1499
$result = $dbi->select(
1500
     table => [$table1, $table2],
1501
     column => [$key2, $key3],
1502
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1503

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

            
1508
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1509
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1510
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1511
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1512
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1513
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1514

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1515
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1516
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1517
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1518
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1519
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1520
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1521

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

            
1528
test 'end_filter';
1529
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1530
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1531
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1532
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1533
$result = $dbi->select(table => $table1);
1534
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1535
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1536
$row = $result->fetch_first;
1537
is_deeply($row, [6, 40]);
1538

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1539
$dbi = DBIx::Custom->connect;
1540
eval { $dbi->execute("drop table $table1") };
1541
$dbi->execute($create_table1);
1542
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1543
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1544
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1545
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
1546
$row = $result->fetch_first;
1547
is_deeply($row, [6, 6, 40]);
1548

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

            
1559
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1560
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1561
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1562
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1563
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1564
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1565
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1566
$row = $result->fetch_first;
1567
is_deeply($row, [6, 12]);
1568

            
1569
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1570
$result = $dbi->select(table => $table1);
1571
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1572
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1573
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1574
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1575

            
1576
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1577
$dbi->apply_filter($table1,
1578
    $key1 => {end => sub { $_[0] * 3 } },
1579
    $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1580
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1581
$result = $dbi->select(table => $table1);
1582
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
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 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1585

            
1586
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1587
$dbi->apply_filter($table1,
1588
    $key1 => {end => sub { $_[0] * 3 } },
1589
    $key2 => {end => 'five_times'}
1590
);
1591
$result = $dbi->select(table => $table1);
1592
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1593
$result->filter($key1 => undef);
1594
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1595
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1596
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1597

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1598
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1599
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1600
$result->filter($key1 => undef);
1601
$result->end_filter($key1 => undef);
1602
$row = $result->fetch;
1603
is_deeply($row, [1, 1, 40], 'apply_filter overwrite');
1604

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1605
test 'remove_end_filter and remove_filter';
1606
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1607
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1608
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1609
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1610
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1611
$row = $result
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1612
       ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1613
       ->remove_filter
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1614
       ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1615
       ->remove_end_filter
1616
       ->fetch_first;
1617
is_deeply($row, [1, 2]);
1618

            
1619
test 'empty where select';
1620
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1621
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1622
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1623
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1624
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1625
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1626
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1627

            
1628
test 'select query option';
1629
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1630
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1631
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1632
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1633
ok(ref $query);
cleanup
Yuki Kimoto authored on 2011-11-01
1634
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1635
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1636
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1637
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1638
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1639
ok(ref $query);
test cleanup
Yuki Kimoto authored on 2011-08-10
1640

            
1641
test 'where';
1642
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1643
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1644
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1645
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1646
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1647
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1648
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1649

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

            
1654
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1655
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1656
    where => $where
1657
);
1658
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1659
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1660

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

            
1671
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1672
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1673
             ->param({$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1674
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1675
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1676
    where => $where
1677
);
1678
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1679
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1680

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

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

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

            
1709
eval {
1710
$where = $dbi->where
1711
             ->clause(['uuu']);
1712
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1713
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1714
    where => $where
1715
);
1716
};
1717
ok($@);
1718

            
1719
$where = $dbi->where;
1720
is("$where", '');
1721

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

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

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

            
1752
$where = $dbi->where
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1753
             ->clause("$key1 = :$key1")
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1754
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1755
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1756
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1757
    where => $where,
1758
);
1759
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1760
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1761

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

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

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

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

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

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

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

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

            
1842
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1843
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1844
             ->param({$key1 => [2, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1845
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1846
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1847
    where => $where,
1848
);
1849
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1850
is_deeply($row, [{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1851

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

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

            
1872
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1873
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1874
             ->param({$key1 => [0, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1875
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1876
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1877
    where => $where,
1878
);
1879
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1880
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
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
             ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1884
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1885
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1886
    where => $where,
1887
);
1888
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1889
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1890

            
1891
eval {$dbi->where(ppp => 1) };
1892
like($@, qr/invalid/);
1893

            
1894
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1895
    clause => ['and', ['or'], ['and', "$key1 = :$key1", "$key2 = :$key2"]],
1896
    param => {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
1897
);
1898
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1899
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1900
    where => $where,
1901
);
1902
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1903
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1904

            
1905

            
1906
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1907
    clause => ['and', ['or'], ['or', ":$key1", ":$key2"]],
test cleanup
Yuki Kimoto authored on 2011-08-10
1908
    param => {}
1909
);
1910
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1911
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1912
    where => $where,
1913
);
1914
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1915
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1916

            
1917
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1918
$where->clause(['and', ":${key1}{=}"]);
1919
$where->param({$key1 => undef});
1920
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1921
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1922
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1923

            
1924
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1925
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1926
$where->param({$key1 => [undef, undef]});
1927
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1928
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1929
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1930
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1931
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1932
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1933

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

            
1935
$dbi = DBIx::Custom->connect;
1936
eval { $dbi->execute("drop table $table1") };
1937
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1938
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
1939
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1940
$where = $dbi->where
1941
             ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
1942
             ->param({$key1 => 1});
1943

            
1944
$result = $dbi->select(
1945
    table => $table1,
1946
    where => $where
1947
);
1948
$row = $result->all;
1949
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
1950

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1951
test 'register_tag_processor';
1952
$dbi = DBIx::Custom->connect;
1953
$dbi->register_tag_processor(
1954
    a => sub { 1 }
1955
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1956
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1957

            
1958
test 'register_tag';
1959
$dbi = DBIx::Custom->connect;
1960
$dbi->register_tag(
1961
    b => sub { 2 }
1962
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1963
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1964

            
1965
test 'table not specify exception';
1966
$dbi = DBIx::Custom->connect;
1967
eval {$dbi->select};
1968
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1969

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1970
test 'more tests';
1971
$dbi = DBIx::Custom->connect;
1972
eval{$dbi->apply_filter('table', 'column', [])};
1973
like($@, qr/apply_filter/);
1974

            
1975
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1976
like($@, qr/apply_filter/);
1977

            
1978
$dbi->apply_filter(
1979

            
1980
);
1981
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1982
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1983
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1984
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1985
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1986
$dbi->apply_filter($table1, $key2, 
test cleanup
Yuki Kimoto authored on 2011-08-10
1987
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1988
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
1989
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1990

            
1991
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1992
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1993
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1994
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1995
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1996
$dbi->apply_filter($table1, $key2, {});
1997
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1998
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1999

            
2000
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2001
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2002
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2003
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2004
like($@, qr/not registered/);
2005
$dbi->method({one => sub { 1 }});
2006
is($dbi->one, 1);
2007

            
2008
eval{DBIx::Custom->connect(dsn => undef)};
2009
like($@, qr/_connect/);
2010

            
2011
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2012
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2013
$dbi->execute($create_table1);
2014
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
2015
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2016
             filter => {$key1 => 'twice'});
2017
$row = $dbi->select(table => $table1)->one;
2018
is_deeply($row, {$key1 => 2, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
2019
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2020
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
2021
like($@, qr//);
2022

            
2023
$dbi->register_filter(one => sub { });
2024
$dbi->default_fetch_filter('one');
2025
ok($dbi->default_fetch_filter);
2026
$dbi->default_bind_filter('one');
2027
ok($dbi->default_bind_filter);
2028
eval{$dbi->default_fetch_filter('no')};
2029
like($@, qr/not registered/);
2030
eval{$dbi->default_bind_filter('no')};
2031
like($@, qr/not registered/);
2032
$dbi->default_bind_filter(undef);
2033
ok(!defined $dbi->default_bind_filter);
2034
$dbi->default_fetch_filter(undef);
2035
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2036
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2037
like($@, qr/Tag not finished/);
2038

            
2039
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2040
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2041
$dbi->execute($create_table1);
2042
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2043
$result = $dbi->select(table => $table1);
2044
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2045
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2046
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2047
like($@, qr/not registered/);
2048
$result->default_filter(undef);
2049
ok(!defined $result->default_filter);
2050
$result->default_filter('one');
2051
is($result->default_filter->(), 1);
2052

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2053
test 'option';
2054
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
2055
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
2056
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2057
ok($dbi->dbh->{PrintError});
2058
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2059
ok($dbi->dbh->{PrintError});
2060

            
2061
test 'DBIx::Custom::Result stash()';
2062
$result = DBIx::Custom::Result->new;
2063
is_deeply($result->stash, {}, 'default');
2064
$result->stash->{foo} = 1;
2065
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2066

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2067
test 'delete_at';
2068
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2069
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2070
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2071
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2072
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2073
    table => $table1,
2074
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2075
    where => [1, 2],
2076
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2077
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2078

            
cleanup
Yuki Kimoto authored on 2011-11-01
2079
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2080
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2081
    table => $table1,
2082
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2083
    where => 1,
2084
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2085
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2086

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2101
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2102
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2103
$dbi->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2104
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2105
    primary_key => $key1, 
2106
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2107
    where => 1,
2108
);
2109

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

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

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

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

            
2154
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2155
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2156
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2157
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2158
$dbi->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2159
    {$key3 => 4},
2160
    table => $table1,
2161
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2162
    where => [1, 2]
2163
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2164
is($dbi->select(table => $table1)->one->{$key1}, 1);
2165
is($dbi->select(table => $table1)->one->{$key2}, 2);
2166
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2167

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2183
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2184
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2185
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2186
    table => $table1,
2187
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2188
    where => 1,
2189
);
2190
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2191
is($row->{$key1}, 1);
2192
is($row->{$key2}, 2);
2193
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2194

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2195
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2196
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2197
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2198
    table => $table1,
2199
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2200
    where => [1, 2]
2201
);
2202
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2203
is($row->{$key1}, 1);
2204
is($row->{$key2}, 2);
2205
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2206

            
2207
test 'model delete_at';
2208
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2209
eval { $dbi->execute("drop table $table1") };
2210
eval { $dbi->execute("drop table $table2") };
2211
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2212
$dbi->execute($create_table1_2);
2213
$dbi->execute($create_table2_2);
2214
$dbi->execute($create_table3);
test cleanup
Yuki Kimoto authored on 2011-11-01
2215
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2216
$dbi->model($table1)->delete_at(where => [1, 2]);
2217
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2218
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2219
$dbi->model($table1)->delete_at(where => [1, 2]);
2220
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2221
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2222
$dbi->model($table3)->delete_at(where => [1, 2]);
2223
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2224

            
2225
test 'model insert_at';
2226
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2227
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2228
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2229
$dbi->model($table1)->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2230
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2231
    where => [1, 2],
2232
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2233
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2234
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2235
is($row->{$key1}, 1);
2236
is($row->{$key2}, 2);
2237
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2238

            
2239
test 'model update_at';
2240
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2241
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2242
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2243
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2244
$dbi->model($table1)->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2245
    {$key3 => 4},
cleanup test
Yuki Kimoto authored on 2011-08-10
2246
    where => [1, 2],
2247
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2248
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2249
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2250
is($row->{$key1}, 1);
2251
is($row->{$key2}, 2);
2252
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2253

            
2254
test 'model select_at';
2255
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2256
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2257
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2258
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2259
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2260
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2261
is($row->{$key1}, 1);
2262
is($row->{$key2}, 2);
2263
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2264

            
2265

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2285
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2286
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2287
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2288
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2289
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2290
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2291
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2292
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2293
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2294
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2295
is($dbi->select(table => $table1)->one->{$key1}, 1);
2296
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2297

            
2298
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2299
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2300
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2301
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2302
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2303
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2304
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2305
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2306
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2307
is($dbi->select(table => $table1)->one->{$key1}, 1);
2308
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2309

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2310
test 'mycolumn';
2311
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2312
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2313
eval { $dbi->execute("drop table $table1") };
2314
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2315
$dbi->execute($create_table1);
2316
$dbi->execute($create_table2);
2317
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2318
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2319
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2320
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2321
$result = $model->select_at(
2322
    column => [
2323
        $model->mycolumn,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2324
        $model->column($table2)
cleanup test
Yuki Kimoto authored on 2011-08-10
2325
    ]
2326
);
2327
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2328
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2329

            
2330
$result = $model->select_at(
2331
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2332
        $model->mycolumn([$key1]),
2333
        $model->column($table2 => [$key1])
cleanup test
Yuki Kimoto authored on 2011-08-10
2334
    ]
2335
);
2336
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2337
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2338
$result = $model->select_at(
2339
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2340
        $model->mycolumn([$key1]),
2341
        {$table2 => [$key1]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2342
    ]
2343
);
2344
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2345
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2346

            
2347
$result = $model->select_at(
2348
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2349
        $model->mycolumn([$key1]),
2350
        ["$table2.$key1", as => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2351
    ]
2352
);
2353
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2354
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2355

            
2356
$result = $model->select_at(
2357
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2358
        $model->mycolumn([$key1]),
2359
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2360
    ]
2361
);
2362
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2363
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2364

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2365
test 'merge_param';
2366
$dbi = DBIx::Custom->new;
2367
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2368
    {$key1 => 1, $key2 => 2, $key3 => 3},
2369
    {$key1 => 1, $key2 => 2},
2370
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2371
];
2372
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2373
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2374

            
2375
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2376
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2377
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2378
];
2379
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2380
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
2381

            
2382
test 'select() param option';
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);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2388
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2389
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2390
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
2391
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
2392
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2393
    table => $table1,
2394
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2395
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2396
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
test cleanup
Yuki Kimoto authored on 2011-08-15
2397
              " $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2398
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2399
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2400
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2401

            
cleanup
Yuki Kimoto authored on 2011-10-21
2402
$rows = $dbi->select(
2403
    table => $table1,
2404
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2405
    where   => {"$table1.$key2" => 3},
2406
    join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2407
             " $table2 on $table1.$key1 = $table2.$key1",
2408
    param => {"$table2.$key3" => 5}
2409
)->all;
2410
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2411

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
2439
$dbi = DBIx::Custom->connect;
2440
eval { $dbi->execute("drop table $table1") };
2441
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2442
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2443
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
2444
$rows = $dbi->select(
2445
    table => $table1,
2446
    where => [
2447
        "$key1 = :$key1 and $key2 = :$key2",
2448
        {$key1 => 1, $key2 => 2}
2449
    ]
2450
)->all;
2451
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2452

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

            
2467
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2468
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2469
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2470
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2471
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2472
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2473
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2474
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2475
        "$key1 = :$key1 and $key2 = :$key2",
2476
         {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2477
    ]
2478
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2479
$rows = $dbi->select(table => $table1)->all;
2480
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2481

            
2482

            
2483
test 'update() string where';
2484
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2485
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2486
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2487
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2488
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2489
    {$key1 => 5},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2490
    table => $table1,
2491
    where => "$key1 = :$key1 and $key2 = :$key2",
2492
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2493
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2494
$rows = $dbi->select(table => $table1)->all;
2495
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2496

            
2497
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2498
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2499
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2500
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2501
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2502
    {$key1 => 5},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2503
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2504
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2505
        "$key1 = :$key1 and $key2 = :$key2",
2506
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2507
    ]
2508
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2509
$rows = $dbi->select(table => $table1)->all;
2510
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2511

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2526
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2527
$dbi->insert(
cleanup
Yuki Kimoto authored on 2011-11-01
2528
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2529
    primary_key => $key1, 
2530
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2531
    id => 0,
2532
);
2533

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2538
$dbi = DBIx::Custom->connect;
2539
eval { $dbi->execute("drop table $table1") };
2540
$dbi->execute($create_table1_2);
2541
$dbi->insert(
2542
    {$key3 => 3},
2543
    primary_key => [$key1, $key2], 
2544
    table => $table1,
2545
    id => 1,
2546
);
2547
is($dbi->select(table => $table1)->one->{$key1}, 1);
2548
ok(!$dbi->select(table => $table1)->one->{$key2});
2549
is($dbi->select(table => $table1)->one->{$key3}, 3);
2550

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

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2564
$dbi = DBIx::Custom->connect;
2565
eval { $dbi->execute("drop table $table1") };
2566
$dbi->execute($create_table1_2);
2567
$param = {$key3 => 3, $key2 => 4};
2568
$dbi->insert(
2569
    $param,
2570
    primary_key => [$key1, $key2], 
2571
    table => $table1,
2572
    id => [1, 2],
2573
);
2574
is($dbi->select(table => $table1)->one->{$key1}, 1);
2575
is($dbi->select(table => $table1)->one->{$key2}, 4);
2576
is($dbi->select(table => $table1)->one->{$key3}, 3);
2577
is_deeply($param, {$key3 => 3, $key2 => 4});
2578

            
added test
Yuki Kimoto authored on 2011-10-25
2579
$dbi = DBIx::Custom->connect;
2580
eval { $dbi->execute("drop table $table1") };
2581
$dbi->execute($create_table1_2);
2582
$param = {$key3 => 3, $key2 => 4};
2583
$query = $dbi->insert(
2584
    $param,
2585
    primary_key => [$key1, $key2], 
2586
    table => $table1,
2587
    id => [1, 2],
2588
    query => 1
2589
);
micro optimization
Yuki Kimoto authored on 2011-11-16
2590
ok(ref $query);
added test
Yuki Kimoto authored on 2011-10-25
2591
is_deeply($param, {$key3 => 3, $key2 => 4});
2592

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2593
test 'model insert id and primary_key option';
2594
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2595
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2596
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2597
$dbi->model($table1)->insert(
cleanup
Yuki Kimoto authored on 2011-11-01
2598
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2599
    id => [1, 2],
2600
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2601
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2602
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2603
is($row->{$key1}, 1);
2604
is($row->{$key2}, 2);
2605
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2606

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

            
2620
test 'update and id option';
2621
$dbi = DBIx::Custom->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);
cleanup test
Yuki Kimoto authored on 2011-08-10
2625
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2626
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2627
    table => $table1,
2628
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2629
    id => [1, 2],
2630
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2631
is($dbi->select(table => $table1)->one->{$key1}, 1);
2632
is($dbi->select(table => $table1)->one->{$key2}, 2);
2633
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2634

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2635
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2636
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2637
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2638
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2639
    table => $table1,
2640
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2641
    id => 0,
2642
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2643
is($dbi->select(table => $table1)->one->{$key1}, 0);
2644
is($dbi->select(table => $table1)->one->{$key2}, 2);
2645
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2646

            
2647
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2648
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2649
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2650
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2651
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2652
    {$key3 => 4},
2653
    table => $table1,
2654
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2655
    id => [1, 2]
2656
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2657
is($dbi->select(table => $table1)->one->{$key1}, 1);
2658
is($dbi->select(table => $table1)->one->{$key2}, 2);
2659
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2660

            
2661

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

            
2677

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

            
cleanup
Yuki Kimoto authored on 2011-11-01
2690
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2691
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2692
    table => $table1,
2693
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2694
    id => 0,
2695
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2696
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2697

            
2698

            
2699
test 'model delete and id option';
2700
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2701
eval { $dbi->execute("drop table $table1") };
2702
eval { $dbi->execute("drop table $table2") };
2703
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2704
$dbi->execute($create_table1_2);
2705
$dbi->execute($create_table2_2);
2706
$dbi->execute($create_table3);
cleanup
Yuki Kimoto authored on 2011-11-01
2707
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2708
$dbi->model($table1)->delete(id => [1, 2]);
2709
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2710
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2711
$dbi->model($table1)->delete(id => [1, 2]);
2712
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2713
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2714
$dbi->model($table3)->delete(id => [1, 2]);
2715
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2716

            
2717

            
2718
test 'select and id option';
2719
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2720
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2721
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2722
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2723
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2724
    table => $table1,
2725
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2726
    id => [1, 2]
2727
);
2728
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2729
is($row->{$key1}, 1);
2730
is($row->{$key2}, 2);
2731
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2732

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2733
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2734
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2735
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2736
    table => $table1,
2737
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2738
    id => 0,
2739
);
2740
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2741
is($row->{$key1}, 0);
2742
is($row->{$key2}, 2);
2743
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2744

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2745
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2746
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2747
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2748
    table => $table1,
2749
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2750
    id => [1, 2]
2751
);
2752
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2753
is($row->{$key1}, 1);
2754
is($row->{$key2}, 2);
2755
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2756

            
2757

            
2758
test 'model select_at';
2759
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2760
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2761
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2762
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2763
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2764
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2765
is($row->{$key1}, 1);
2766
is($row->{$key2}, 2);
2767
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2768

            
2769
test 'column separator is default .';
2770
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2771
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2772
eval { $dbi->execute("drop table $table1") };
2773
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2774
$dbi->execute($create_table1);
2775
$dbi->execute($create_table2);
2776
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2777
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2778
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2779
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2780
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2781
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2782
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2783
);
2784
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2785
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2786

            
2787
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2788
    column => [$model->column($table2 => [$key1, $key3])],
2789
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2790
);
2791
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2792
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2793

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2802
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2803
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2804
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2805
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2806
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2807
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2808
);
2809
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2810
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2811
);
2812
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2813
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2814
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2815
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2816
$result = $model->select(
2817
    column => [
2818
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2819
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2820
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2821
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2822
);
2823
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2824
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2825
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2826

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2827
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2828
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2829
$result = $model->select(
2830
    column => [
2831
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2832
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2833
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2834
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2835
);
2836
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2837
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
2838
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2839

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2840
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2841
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2842
$result = $model->select(
2843
    column => [
2844
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2845
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2846
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2847
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2848
);
2849
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2850
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2851
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2852

            
2853

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2854
test 'filter_off';
2855
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2856
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2857
eval { $dbi->execute("drop table $table1") };
2858
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2859
$dbi->execute($create_table1);
2860
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2861

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2862
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2863
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2864
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2865
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2866
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2867
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2868
);
2869
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2870
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2871
$model = $dbi->model($table1);
2872
$result = $model->select(column => $key1);
2873
$result->filter($key1 => sub { $_[0] * 2 });
2874
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2875

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2876
test 'available_datetype';
2877
$dbi = DBIx::Custom->connect;
2878
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2879

            
2880

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2881
test 'select prefix option';
2882
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2883
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2884
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2885
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2886
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2887
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2888

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

            
added tests
Yuki Kimoto authored on 2011-08-26
2890
test 'mapper';
2891
$dbi = DBIx::Custom->connect;
2892
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2893
    id => {key => "$table1.id"},
2894
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2895
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
2896
);
2897
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2898
  "$table1.price" => 1900});
2899

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2900
$dbi = DBIx::Custom->connect;
2901
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2902
    id => {key => "$table1.id"},
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2903
    author => ["$table1.author" => $dbi->like_value],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2904
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2905
);
2906
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2907
  "$table1.price" => 1900});
2908

            
added tests
Yuki Kimoto authored on 2011-08-26
2909
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2910
    id => {key => "$table1.id"},
2911
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2912
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
2913
);
2914
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2915

            
2916
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2917
    id => {key => "$table1.id"},
2918
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2919
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
added tests
Yuki Kimoto authored on 2011-08-26
2920
);
2921
is_deeply($param, {});
2922

            
2923
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2924
    id => {key => "$table1.id"},
2925
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2926
);
2927
is_deeply($param, {"$table1.price" => undef});
2928

            
2929
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2930
    id => {key => "$table1.id", condition => 'exists'},
2931
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
2932
);
2933
is_deeply($param, {"$table1.price" => '%a'});
2934

            
2935
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2936
    id => {key => "$table1.id"},
added tests
Yuki Kimoto authored on 2011-08-26
2937
    price => ["$table1.price", sub { '%' . $_[0] }]
2938
);
2939
is_deeply($param, {"$table1.price" => '%a'});
2940

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2941
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2942
    price => sub { '%' . $_[0] },
2943
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2944
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2945
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2946

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

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

            
2960
$where = $dbi->where;
2961
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2962
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
2963
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2964
$row = $result->all;
2965
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2966
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2967
$row = $result->all;
2968
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2969

            
2970
$where = $dbi->where;
2971
$where->clause(['and', ":${key1}{=}"]);
2972
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
2973
$where->param($param);
2974
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2975
$row = $result->all;
2976
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2977
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2978
$row = $result->all;
2979
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2980

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2982
$where = $dbi->where;
2983
$where->clause(['and', ":${key1}{=}"]);
2984
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
2985
  ->pass([$key1, $key2])->map;
2986
$where->param($param);
2987
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2988
$row = $result->all;
2989
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2990

            
2991
$where = $dbi->where;
2992
$where->clause(['and', ":${key1}{=}"]);
2993
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
2994
$where->param($param);
2995
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2996
$row = $result->all;
2997
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2998

            
2999
$where = $dbi->where;
3000
$where->clause(['and', ":${key1}{=}"]);
3001
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
3002
  ->pass([$key1, $key2])->map;
3003
$where->param($param);
3004
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3005
$row = $result->all;
3006
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3007

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3009
$where = $dbi->where;
3010
$where->clause(['and', ":${key1}{=}"]);
3011
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
3012
$where->param($param);
3013
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3014
$row = $result->all;
3015
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3016

            
3017
$where = $dbi->where;
3018
$param = $dbi->mapper(param => {id => 1, 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
$where->param($param);
3024
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
3025
  "$table1.price" => 1900});
3026

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

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

            
3045
$where = $dbi->where;
3046
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3047
    id => {key => "$table1.id"},
3048
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3049
);
3050
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
3051

            
3052
$where = $dbi->where;
3053
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3054
    id => {key => "$table1.id", condition => 'exists'},
3055
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3056
);
3057
is_deeply($param, {"$table1.price" => '%a'});
3058

            
3059
$where = $dbi->where;
3060
$param = $dbi->mapper(param => {id => [1, 2], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3061
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3062
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3063
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3064
);
3065
is_deeply($param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
3066
  "$table1.price" => 1900});
3067

            
3068
$where = $dbi->where;
3069
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900}, condition => 'length')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3070
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3071
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3072
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3073
);
3074
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
3075
  "$table1.price" => 1900});
3076

            
3077
$where = $dbi->where;
3078
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3079
    id => {key => "$table1.id", condition => 'length'},
3080
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
3081
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3082
);
3083
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
3084
  "$table1.price" => 1900});
3085

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3091
test 'order';
3092
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3093
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3094
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3095
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3096
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3097
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3098
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3099
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3100
$order->prepend($key1, "$key2 desc");
3101
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3102
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
3103
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3104
$order->prepend("$key1 desc");
3105
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3106
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
3107
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3108

            
3109
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3110
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3111
$result = $dbi->select(table => $table1,
3112
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3113
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3114
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
3115
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
3116
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
3117
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3118

            
3119
test 'tag_parse';
3120
$dbi = DBIx::Custom->connect;
3121
$dbi->tag_parse(0);
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
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3125
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3126
ok($@);
3127

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3128
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3129
{
3130
    $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3131
    $dbi = DBIx::Custom->connect;
3132
    eval { $dbi->execute("drop table $table1") };
3133
    $dbi->execute($create_table1);
3134
    $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3135
    eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3136
    ok($@);
cleanup
Yuki Kimoto authored on 2011-11-16
3137
    eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) };
3138
    ok($@);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3139
    delete$ENV{DBIX_CUSTOM_TAG_PARSE};
3140
}
3141

            
3142
{
3143
    $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3144
    $dbi = DBIx::Custom->connect;
3145
    eval { $dbi->execute("drop table $table1") };
3146
    $dbi->execute($create_table1);
3147
    $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-16
3148
    is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3149
    delete$ENV{DBIX_CUSTOM_TAG_PARSE};
3150
}
3151

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3152
test 'last_sql';
3153
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3154
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3155
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3156
$dbi->execute("select * from $table1");
micro optimization
Yuki Kimoto authored on 2011-11-18
3157
is($dbi->last_sql, " select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3158

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3190
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3191
$result = $dbi->execute(
3192
    $source,
cleanup
Yuki Kimoto authored on 2011-11-01
3193
    {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3194
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3195
);
3196
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3197
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3198

            
3199
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3200
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3201
$dbi->execute($create_table1_highperformance);
3202
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3203
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3204
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3205
];
3206
{
3207
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3208
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3209
      $query ||= $dbi->insert($row, table => $table1, query => 1);
3210
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
3211
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3212
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3213
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3214
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3215
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3216
      ]
3217
    );
3218
}
3219

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3220
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3221
$dbi->execute($create_table1_highperformance);
3222
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3223
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3224
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3225
];
3226
{
3227
    my $query;
3228
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
3229
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3230
      $query ||= $dbi->insert($row, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
3231
      $sth ||= $query->{sth};
test cleanup
Yuki Kimoto authored on 2011-08-10
3232
      $sth->execute(map { $row->{$_} } sort keys %$row);
3233
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3234
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3235
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3236
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3237
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3238
      ]
3239
    );
3240
}
3241

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3242
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3243
$dbi->execute($create_table1_highperformance);
3244
$rows = [
3245
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
3246
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
3247
];
3248
{
3249
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3250
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3251
    for my $row (@$rows) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3252
      $query ||= $model->insert($row, query => 1);
3253
      $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3254
    }
3255
    is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3256
      [
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3257
          {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3258
          {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3259
      ]
3260
    );
3261
}
3262

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3263
eval { $dbi->execute("drop table $table1") };
3264
$dbi->execute($create_table1);
3265
{
3266
    $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3267
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3268
    eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3269
    like($@, qr/primary_key/);
3270
    delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
3271
}
3272

            
3273
{
3274
    $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3275
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3276
    $model->insert({$key1 => 1});
3277
    $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3278
      table => $table1, primary_key => $key1);
3279
    is($result->one->{$key1}, 1);
3280
    delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
3281
}
3282

            
3283
eval { $dbi->execute("drop table $table1") };
3284
$dbi->execute($create_table1);
3285
{
3286
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3287
    $model->insert({$key1 => 1});
3288
    eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3289
    is($result->one->{$key1}, 1);
3290
}
3291

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

            
3306
eval { $dbi->execute("drop table $table1") };
3307
eval { $dbi->execute("drop table $table2") };
3308
$dbi->execute($create_table1);
3309
$dbi->execute($create_table2);
3310
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3311
$model->insert({$key1 => 1, $key2 => 2});
3312
$model = $dbi->create_model(table => $table2, primary_key => $key1,
3313
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
3314
$model->insert({$key1 => 1, $key3 => 3});
3315
$result = $model->select(
3316
    column => {$table1 => ["$key2"]},
3317
    id => 1
3318
);
3319
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3320

            
3321
eval { $dbi->execute("drop table $table1") };
3322
$dbi->execute($create_table1_highperformance);
3323
$row = {
3324
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3325
};
3326
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3327
$model->insert($row);
3328
$query = $model->delete(id => 1, query => 1);
3329
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3330
is_deeply($dbi->select(table => $table1)->all, []);
3331

            
3332
eval { $dbi->execute("drop table $table1") };
3333
eval { $dbi->execute($create_table1_highperformance) };
3334
$row = {
3335
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3336
};
3337
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3338
$model->insert($row);
3339
$query = $model->select(id => 1, query => 1);
3340
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3341
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3342
is_deeply($dbi->select(table => $table1)->one,
3343
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3344
);
3345

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3346
test 'result';
3347
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3348
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3349
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3350
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3351
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3352

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3353
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3354
@rows = ();
3355
while (my $row = $result->fetch) {
3356
    push @rows, [@$row];
3357
}
3358
is_deeply(\@rows, [[1, 2], [3, 4]]);
3359

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3360
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3361
@rows = ();
3362
while (my $row = $result->fetch_hash) {
3363
    push @rows, {%$row};
3364
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3365
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3366

            
3367
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3368
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3369
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3370
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3371
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3372

            
3373
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3374
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3375
$rows = $result->fetch_all;
3376
is_deeply($rows, [[1, 2], [3, 4]]);
3377

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3382
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3383
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3384
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3385
$rows = $result->fetch_all;
3386
is_deeply($rows, [[3, 2], [9, 4]], "array");
3387

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

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3400
test 'DBIx::Custom::Result fetch_multi';
3401
eval { $dbi->execute("drop table $table1") };
3402
$dbi->execute($create_table1);
3403
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3404
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3405
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3406
$result = $dbi->select(table => $table1);
3407
$rows = $result->fetch_multi(2);
3408
is_deeply($rows, [[1, 2], [3, 4]]);
3409
$rows = $result->fetch_multi(2);
3410
is_deeply($rows, [[5, 6]]);
3411
$rows = $result->fetch_multi(2);
3412
ok(!$rows);
3413

            
3414
test 'DBIx::Custom::Result fetch_hash_multi';
3415
eval { $dbi->execute("drop table $table1") };
3416
$dbi->execute($create_table1);
3417
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3418
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3419
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3420
$result = $dbi->select(table => $table1);
3421
$rows = $result->fetch_hash_multi(2);
3422
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3423
$rows = $result->fetch_hash_multi(2);
3424
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3425
$rows = $result->fetch_hash_multi(2);
3426
ok(!$rows);
3427

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3428
test "query_builder";
3429
$datas = [
3430
    # Basic tests
3431
    {   name            => 'placeholder basic',
3432
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3433
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3434
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3435
    },
3436
    {
3437
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3438
        source            => "{in k1 3}",
3439
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3440
        columns_expected   => [qw/k1 k1 k1/]
3441
    },
3442
    
3443
    # Table name
3444
    {
3445
        name            => 'placeholder with table name',
3446
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3447
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3448
        columns_expected  => [qw/a.k1 a.k2/]
3449
    },
3450
    {   
3451
        name            => 'placeholder in with table name',
3452
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3453
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3454
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3455
    },
3456
    {
3457
        name            => 'not contain tag',
3458
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3459
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3460
        columns_expected  => [],
3461
    }
3462
];
3463

            
3464
for (my $i = 0; $i < @$datas; $i++) {
3465
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3466
    my $dbi = DBIx::Custom->new;
3467
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3468
    my $query = $builder->build_query($data->{source});
3469
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
micro optimization
Yuki Kimoto authored on 2011-11-16
3470
    is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3471
}
3472

            
cleanup
Yuki Kimoto authored on 2011-08-13
3473
$dbi = DBIx::Custom->new;
3474
$builder = $dbi->query_builder;
3475
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3476
    p => sub {
3477
        my @args = @_;
3478
        
3479
        my $expand    = "? $args[0] $args[1]";
3480
        my $columns = [2];
3481
        return [$expand, $columns];
3482
    }
3483
);
3484

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3495
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3496
    q => 'string'
3497
});
3498

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3502
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3503
   r => sub {} 
3504
});
3505

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3509
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3510
   s => sub { return ["a", ""]} 
3511
});
3512

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3516
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3517
    t => sub {return ["a", []]}
3518
);
3519

            
3520

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

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

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

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

            
3536
test 'variouse source';
3537
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3538
$query = $builder->build_query($source);
3539
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3540

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

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

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

            
3553
$source = "a {= b} }";
3554
eval{$builder->build_query($source)};
3555
like($@, qr/unexpected "}"/, "error : 1");
3556

            
3557
$source = "a {= {}";
3558
eval{$builder->build_query($source)};
3559
like($@, qr/unexpected "{"/, "error : 2");
3560

            
3561
test 'select() sqlfilter option';
3562
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3563
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3564
eval { $dbi->execute("drop table $table1") };
3565
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3566
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3567
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3568
$rows = $dbi->select(
3569
    table => $table1,
3570
    column => $key1,
3571
    sqlfilter => sub {
3572
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
3573
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
3574
        return $sql;
3575
    }
3576
)->all;
3577
is_deeply($rows, [{$key1 => 1}]);
3578

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3579
test 'select() after_build_sql option';
3580
$dbi = DBIx::Custom->connect;
3581
$dbi->user_table_info($user_table_info);
3582
eval { $dbi->execute("drop table $table1") };
3583
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3584
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3585
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3586
$rows = $dbi->select(
3587
    table => $table1,
3588
    column => $key1,
3589
    after_build_sql => sub {
3590
        my $sql = shift;
3591
        $sql = "select * from ( $sql ) t where $key1 = 1";
3592
        return $sql;
3593
    }
3594
)->all;
3595
is_deeply($rows, [{$key1 => 1}]);
3596

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3597
test 'dbi method from model';
3598
$dbi = MyDBI9->connect;
3599
eval { $dbi->execute("drop table $table1") };
3600
$dbi->execute($create_table1);
3601
$dbi->setup_model;
3602
$model = $dbi->model($table1);
3603
eval{$model->execute("select * from $table1")};
3604
ok(!$@);
3605

            
3606
test 'column table option';
3607
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3608
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3609
eval { $dbi->execute("drop table $table1") };
3610
$dbi->execute($create_table1);
3611
eval { $dbi->execute("drop table $table2") };
3612
$dbi->execute($create_table2);
3613
$dbi->setup_model;
3614
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3615
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3616
$model = $dbi->model($table1);
3617
$result = $model->select(
3618
    column => [
3619
        $model->column($table2, {alias => $table2_alias})
3620
    ],
3621
    where => {"$table2_alias.$key3" => 4}
3622
);
3623
is_deeply($result->one, 
3624
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3625

            
3626
$dbi->separator('__');
3627
$result = $model->select(
3628
    column => [
3629
        $model->column($table2, {alias => $table2_alias})
3630
    ],
3631
    where => {"$table2_alias.$key3" => 4}
3632
);
3633
is_deeply($result->one, 
3634
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3635

            
3636
$dbi->separator('-');
3637
$result = $model->select(
3638
    column => [
3639
        $model->column($table2, {alias => $table2_alias})
3640
    ],
3641
    where => {"$table2_alias.$key3" => 4}
3642
);
3643
is_deeply($result->one, 
3644
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3645

            
3646
test 'create_model';
3647
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3648
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3649
eval { $dbi->execute("drop table $table1") };
3650
eval { $dbi->execute("drop table $table2") };
3651
$dbi->execute($create_table1);
3652
$dbi->execute($create_table2);
3653

            
3654
$dbi->create_model(
3655
    table => $table1,
3656
    join => [
3657
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3658
    ],
3659
    primary_key => [$key1]
3660
);
3661
$model2 = $dbi->create_model(
3662
    table => $table2
3663
);
3664
$dbi->create_model(
3665
    table => $table3,
3666
    filter => [
3667
        $key1 => {in => sub { uc $_[0] }}
3668
    ]
3669
);
3670
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3671
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3672
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3673
$model = $dbi->model($table1);
3674
$result = $model->select(
3675
    column => [$model->mycolumn, $model->column($table2)],
3676
    where => {"$table1.$key1" => 1}
3677
);
3678
is_deeply($result->one,
3679
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3680
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3681

            
3682
test 'model method';
3683
$dbi = DBIx::Custom->connect;
3684
eval { $dbi->execute("drop table $table2") };
3685
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3686
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3687
$model = $dbi->create_model(
3688
    table => $table2
3689
);
3690
$model->method(foo => sub { shift->select(@_) });
3691
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3692

            
3693
test 'model helper';
3694
$dbi = DBIx::Custom->connect;
3695
eval { $dbi->execute("drop table $table2") };
3696
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3697
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3698
$model = $dbi->create_model(
3699
    table => $table2
3700
);
3701
$model->helper(foo => sub { shift->select(@_) });
3702
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3703

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

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

            
3724

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

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

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

            
3750
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3751
$assign_clause = $dbi->update_param($param, {no_set => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
3752
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3753
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3754
where $key1 = 1
3755
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3756
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3757
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3758
$rows   = $result->all;
3759
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3760
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3761
                  "update param no_set");
3762

            
3763
            
3764
$dbi = DBIx::Custom->connect;
3765
eval { $dbi->execute("drop table $table1") };
3766
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
3767
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
3768
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3769

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3770
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3771
$assign_clause = $dbi->assign_param($param);
3772
$sql = <<"EOS";
3773
update $table1 set $assign_clause
3774
where $key1 = 1
3775
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3776
$dbi->execute($sql, $param, table => $table1);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3777
$result = $dbi->execute("select * from $table1 order by $key1");
3778
$rows   = $result->all;
3779
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3780
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3781
                  "basic");
3782

            
3783
$param = {$key2 => 11};
3784
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3785
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3786
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3787
where $key1 = 1
3788
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3789
$dbi->execute($sql, $param, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3790
$result = $dbi->execute("select * from $table1 order by $key1");
3791
$rows   = $result->all;
3792
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3793
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3794
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3795

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3796
test 'Model class';
3797
$dbi = MyDBI1->connect;
3798
eval { $dbi->execute("drop table $table1") };
3799
$dbi->execute($create_table1);
3800
$model = $dbi->model($table1);
3801
$model->insert({$key1 => 'a', $key2 => 'b'});
3802
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3803
eval { $dbi->execute("drop table $table2") };
3804
$dbi->execute($create_table2);
3805
$model = $dbi->model($table2);
3806
$model->insert({$key1 => 'a'});
3807
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3808
is($dbi->models->{$table1}, $dbi->model($table1));
3809
is($dbi->models->{$table2}, $dbi->model($table2));
3810

            
3811
$dbi = MyDBI4->connect;
3812
eval { $dbi->execute("drop table $table1") };
3813
$dbi->execute($create_table1);
3814
$model = $dbi->model($table1);
3815
$model->insert({$key1 => 'a', $key2 => 'b'});
3816
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3817
eval { $dbi->execute("drop table $table2") };
3818
$dbi->execute($create_table2);
3819
$model = $dbi->model($table2);
3820
$model->insert({$key1 => 'a'});
3821
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3822

            
3823
$dbi = MyDBI5->connect;
3824
eval { $dbi->execute("drop table $table1") };
3825
eval { $dbi->execute("drop table $table2") };
3826
$dbi->execute($create_table1);
3827
$dbi->execute($create_table2);
3828
$model = $dbi->model($table2);
3829
$model->insert({$key1 => 'a'});
3830
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
3831
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3832
$model = $dbi->model($table1);
3833
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3834

            
3835
test 'primary_key';
3836
$dbi = MyDBI1->connect;
3837
$model = $dbi->model($table1);
3838
$model->primary_key([$key1, $key2]);
3839
is_deeply($model->primary_key, [$key1, $key2]);
3840

            
3841
test 'columns';
3842
$dbi = MyDBI1->connect;
3843
$model = $dbi->model($table1);
3844
$model->columns([$key1, $key2]);
3845
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3846

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3847
test 'setup_model';
3848
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3849
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3850
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3851
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3852

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3853
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3854
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3855
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3856
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3857
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3858

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3859
test 'each_column';
3860
$dbi = DBIx::Custom->connect;
3861
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3862
eval { $dbi->execute("drop table $table1") };
3863
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3864
eval { $dbi->execute("drop table $table3") };
3865
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3866
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3867

            
3868
$infos = [];
3869
$dbi->each_column(sub {
3870
    my ($self, $table, $column, $cinfo) = @_;
3871
    
3872
    if ($table =~ /^table\d/i) {
3873
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3874
         push @$infos, $info;
3875
    }
3876
});
3877
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3878
is_deeply($infos, 
3879
    [
3880
        [$table1, $key1, $key1],
3881
        [$table1, $key2, $key2],
3882
        [$table2, $key1, $key1],
3883
        [$table2, $key3, $key3]
3884
    ]
3885
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3886
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3887

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3888
test 'each_table';
3889
$dbi = DBIx::Custom->connect;
3890
eval { $dbi->execute("drop table $table1") };
3891
eval { $dbi->execute("drop table $table2") };
3892
$dbi->execute($create_table2);
3893
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3894

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3895
$infos = [];
3896
$dbi->each_table(sub {
3897
    my ($self, $table, $table_info) = @_;
3898
    
3899
    if ($table =~ /^table\d/i) {
3900
         my $info = [$table, $table_info->{TABLE_NAME}];
3901
         push @$infos, $info;
3902
    }
3903
});
3904
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3905
is_deeply($infos, 
3906
    [
3907
        [$table1, $table1],
3908
        [$table2, $table2],
3909
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3910
);
3911

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3912
$dbi = DBIx::Custom->connect;
3913
eval { $dbi->execute("drop table $table1") };
3914
eval { $dbi->execute("drop table $table2") };
3915
$dbi->execute($create_table2);
3916
$dbi->execute($create_table1_type);
3917

            
3918
$infos = [];
3919
$dbi->user_table_info($user_table_info);
3920
$dbi->each_table(sub {
3921
    my ($self, $table, $table_info) = @_;
3922
    
3923
    if ($table =~ /^table\d/i) {
3924
         my $info = [$table, $table_info->{TABLE_NAME}];
3925
         push @$infos, $info;
3926
    }
3927
});
3928
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3929
is_deeply($infos, 
3930
    [
3931
        [$table1, $table1],
3932
        [$table2, $table2],
3933
        [$table3, $table3],
3934
    ]
3935
);
3936

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3937
test 'type_rule into';
3938
eval { $dbi->execute("drop table $table1") };
3939
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3940
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3941

            
3942

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3943
$dbi = DBIx::Custom->connect;
3944
eval { $dbi->execute("drop table $table1") };
3945
$dbi->execute($create_table1_type);
3946

            
cleanup
Yuki Kimoto authored on 2011-08-16
3947
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3948
$dbi->type_rule(
3949
    into1 => {
3950
        $date_typename => sub { '2010-' . $_[0] }
3951
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3952
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3953
$dbi->insert({$key1 => '01-01'}, table => $table1);
3954
$result = $dbi->select(table => $table1);
3955
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3956

            
3957
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3958
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3959
$dbi->execute($create_table1_type);
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
         }
3968
    ]
3969
);
3970
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3971
$result = $dbi->select(table => $table1);
3972
$row = $result->one;
3973
like($row->{$key1}, qr/^2010-01-03/);
3974
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3975

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3976
$dbi = DBIx::Custom->connect;
3977
eval { $dbi->execute("drop table $table1") };
3978
$dbi->execute($create_table1_type);
3979
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3980
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3981
$dbi->type_rule(
3982
    into1 => [
3983
        [$date_typename, $datetime_typename] => sub {
3984
            my $value = shift;
3985
            $value =~ s/02/03/g;
3986
            return $value;
3987
        }
3988
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3989
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3990
$result = $dbi->execute(
3991
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
3992
    {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
3993
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3994
$row = $result->one;
3995
like($row->{$key1}, qr/^2010-01-03/);
3996
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3997

            
3998
$dbi = DBIx::Custom->connect;
3999
eval { $dbi->execute("drop table $table1") };
4000
$dbi->execute($create_table1_type);
4001
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4002
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4003
$dbi->type_rule(
4004
    into1 => [
4005
        [$date_typename, $datetime_typename] => sub {
4006
            my $value = shift;
4007
            $value =~ s/02/03/g;
4008
            return $value;
4009
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
4010
    ]
4011
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4012
$result = $dbi->execute(
4013
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
4014
    {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
cleanup test
Yuki Kimoto authored on 2011-08-15
4015
    table => $table1
4016
);
4017
$row = $result->one;
4018
like($row->{$key1}, qr/^2010-01-03/);
4019
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4020

            
4021
$dbi = DBIx::Custom->connect;
4022
eval { $dbi->execute("drop table $table1") };
4023
$dbi->execute($create_table1_type);
4024
$dbi->register_filter(convert => sub {
4025
    my $value = shift || '';
4026
    $value =~ s/02/03/;
4027
    return $value;
4028
});
cleanup
Yuki Kimoto authored on 2011-08-16
4029
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4030
$dbi->type_rule(
4031
    from1 => {
4032
        $date_datatype => 'convert',
4033
    },
4034
    into1 => {
4035
        $date_typename => 'convert',
4036
    }
4037
);
4038
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
4039
$result = $dbi->select(table => $table1);
4040
like($result->fetch->[0], qr/^2010-03-03/);
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
4041
$result = $dbi->select(column => [$key1, $key1], table => $table1);
4042
$row = $result->fetch;
4043
like($row->[0], qr/^2010-03-03/);
4044
like($row->[1], qr/^2010-03-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4045

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

            
4071

            
4072
$dbi = DBIx::Custom->connect;
4073
eval { $dbi->execute("drop table $table1") };
4074
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4075
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4076
$dbi->type_rule(
4077
    from1 => {
4078
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4079
    },
4080
    from2 => {
4081
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4082
    },
4083
);
4084
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4085
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4086
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4087
$result->type_rule(
4088
    from1 => {
4089
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4090
    },
4091
    from2 => {
4092
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
4093
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4094
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4095
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
4096
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4097

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4098
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
4099
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
4100
eval { $dbi->execute("drop table $table1") };
4101
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4102
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4103
$dbi->type_rule(
4104
    from1 => {
4105
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4106
    },
4107
    into1 => {
4108
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4109
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4110
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4111
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4112
$result = $dbi->select(table => $table1, type_rule_off => 1);
4113
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4114

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

            
4131
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4132
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4133
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4134
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4135
$dbi->type_rule(
4136
    from1 => {
4137
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4138
    },
4139
    into1 => {
4140
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4141
    }
4142
);
4143
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4144
$result = $dbi->select(table => $table1);
4145
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4146

            
4147
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4148
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4149
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4150
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4151
$dbi->type_rule(
4152
    from1 => {
4153
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4154
    },
4155
    into1 => {
4156
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4157
    }
4158
);
4159
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4160
$result = $dbi->select(table => $table1);
4161
like($result->fetch->[0], qr/2010-01-05/);
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);
4166
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
4167
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4168
$dbi->type_rule(
4169
    into1 => {
4170
        $date_typename => 'ppp'
4171
    }
4172
);
4173
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4174
$result = $dbi->select(table => $table1);
4175
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4176

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4177
eval{$dbi->type_rule(
4178
    into1 => {
4179
        $date_typename => 'pp'
4180
    }
4181
)};
4182
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4183

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4184
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4185
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4186
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4187
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
4188
    $dbi->type_rule(
4189
        from1 => {
4190
            Date => sub { $_[0] * 2 },
4191
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
4192
    );
4193
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4194
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4195

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4196
eval {
4197
    $dbi->type_rule(
4198
        into1 => {
4199
            Date => sub { $_[0] * 2 },
4200
        }
4201
    );
4202
};
4203
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4204

            
4205
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4206
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4207
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4208
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4209
$dbi->type_rule(
4210
    from1 => {
4211
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4212
    },
4213
    into1 => {
4214
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4215
    }
4216
);
4217
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4218
$result = $dbi->select(table => $table1);
4219
$result->type_rule_off;
4220
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4221

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

            
4243
$result = $dbi->select(table => $table1);
4244
$result->type_rule(
4245
    from1 => {
4246
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4247
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4248
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4249
$row = $result->one;
4250
like($row->{$key1}, qr/2010-01-05/);
4251
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4252

            
4253
$result = $dbi->select(table => $table1);
4254
$result->type_rule(
4255
    from1 => {
4256
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4257
    }
4258
);
4259
$row = $result->one;
4260
like($row->{$key1}, qr/2010-01-05/);
4261
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4262

            
4263
$result = $dbi->select(table => $table1);
4264
$result->type_rule(
4265
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
4266
);
4267
$row = $result->one;
4268
like($row->{$key1}, qr/2010-01-05/);
4269
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4270

            
4271
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4272
$result = $dbi->select(table => $table1);
4273
$result->type_rule(
4274
    from1 => [$date_datatype => 'five']
4275
);
4276
$row = $result->one;
4277
like($row->{$key1}, qr/^2010-01-05/);
4278
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4279

            
4280
$result = $dbi->select(table => $table1);
4281
$result->type_rule(
4282
    from1 => [$date_datatype => undef]
4283
);
4284
$row = $result->one;
4285
like($row->{$key1}, qr/^2010-01-03/);
4286
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4287

            
4288
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4289
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4290
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4291
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4292
$dbi->type_rule(
4293
    from1 => {
4294
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4295
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
4296
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4297
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4298
$result = $dbi->select(table => $table1);
4299
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4300
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4301

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4302
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4303
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4304
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4305
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4306
$dbi->type_rule(
4307
    from1 => {
4308
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4309
    },
4310
);
4311
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4312
$result = $dbi->select(table => $table1);
4313
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4314
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4315

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4340
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4341
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4342
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4343
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4344
$dbi->type_rule(
4345
    into1 => {
4346
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4347
    },
4348
    into2 => {
4349
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4350
    },
4351
    from1 => {
4352
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
4353
    },
4354
    from2 => {
4355
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4356
    }
4357
);
4358
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4359
$result = $dbi->select(table => $table1);
4360
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/);
4361
$result = $dbi->select(table => $table1);
4362
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4363

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4364
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4365
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4366
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4367
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4368
$dbi->type_rule(
4369
    into1 => {
4370
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4371
    },
4372
    into2 => {
4373
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4374
    },
4375
    from1 => {
4376
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4377
    },
4378
    from2 => {
4379
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4380
    }
4381
);
4382
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4383
$result = $dbi->select(table => $table1);
4384
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
4385
$result = $dbi->select(table => $table1);
4386
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4387

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4388
test 'join';
4389
$dbi = DBIx::Custom->connect;
4390
eval { $dbi->execute("drop table $table1") };
4391
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4392
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4393
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4394
eval { $dbi->execute("drop table $table2") };
4395
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4396
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4397
eval { $dbi->execute("drop table $table3") };
4398
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4399
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4400
$rows = $dbi->select(
4401
    table => $table1,
4402
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4403
    where   => {"$table1.$key2" => 2},
4404
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4405
)->all;
4406
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4407

            
4408
$dbi = DBIx::Custom->connect;
4409
eval { $dbi->execute("drop table $table1") };
4410
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4411
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4412
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4413
eval { $dbi->execute("drop table $table2") };
4414
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4415
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4416
eval { $dbi->execute("drop table $table3") };
4417
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4418
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4419
$rows = $dbi->select(
4420
    table => $table1,
4421
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4422
    where   => {"$table1.$key2" => 2},
4423
    join  => {
4424
        clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4425
        table => [$table1, $table2]
4426
    }
4427
)->all;
4428
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
4429

            
4430
$rows = $dbi->select(
4431
    table => $table1,
4432
    where   => {$key1 => 1},
4433
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4434
)->all;
4435
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4436

            
4437
$rows = $dbi->select(
4438
    table => $table1,
4439
    where   => {$key1 => 1},
4440
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4441
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4442
)->all;
4443
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4444

            
4445
$rows = $dbi->select(
4446
    column => "$table3.$key4 as ${table3}__$key4",
4447
    table => $table1,
4448
    where   => {"$table1.$key1" => 1},
4449
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4450
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4451
)->all;
4452
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4453

            
4454
$rows = $dbi->select(
4455
    column => "$table1.$key1 as ${table1}__$key1",
4456
    table => $table1,
4457
    where   => {"$table3.$key4" => 4},
4458
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4459
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4460
)->all;
4461
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4462

            
4463
$dbi = DBIx::Custom->connect;
4464
eval { $dbi->execute("drop table $table1") };
4465
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4466
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4467
eval { $dbi->execute("drop table $table2") };
4468
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4469
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4470
$rows = $dbi->select(
4471
    table => $table1,
4472
    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",
4473
    where   => {"$table1.$key2" => 2},
4474
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4475
)->all;
4476
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4477
          'quote');
4478

            
4479

            
4480
$dbi = DBIx::Custom->connect;
4481
eval { $dbi->execute("drop table $table1") };
4482
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4483
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4484
$sql = <<"EOS";
4485
left outer join (
4486
  select * from $table1 t1
4487
  where t1.$key2 = (
4488
    select max(t2.$key2) from $table1 t2
4489
    where t1.$key1 = t2.$key1
4490
  )
4491
) $table3 on $table1.$key1 = $table3.$key1
4492
EOS
4493
$join = [$sql];
4494
$rows = $dbi->select(
4495
    table => $table1,
4496
    column => "$table3.$key1 as ${table3}__$key1",
4497
    join  => $join
4498
)->all;
4499
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4500

            
4501
$dbi = DBIx::Custom->connect;
4502
eval { $dbi->execute("drop table $table1") };
4503
eval { $dbi->execute("drop table $table2") };
4504
$dbi->execute($create_table1);
4505
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4506
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4507
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4508
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4509
$result = $dbi->select(
4510
    table => $table1,
4511
    join => [
4512
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4513
    ]
4514
);
4515
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4516
$result = $dbi->select(
4517
    table => $table1,
4518
    column => [{$table2 => [$key3]}],
4519
    join => [
4520
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4521
    ]
4522
);
4523
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4524
$result = $dbi->select(
4525
    table => $table1,
4526
    column => [{$table2 => [$key3]}],
4527
    join => [
4528
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4529
    ]
4530
);
4531
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4532

            
4533
$dbi = DBIx::Custom->connect;
4534
eval { $dbi->execute("drop table $table1") };
4535
eval { $dbi->execute("drop table $table2") };
4536
$dbi->execute($create_table1);
4537
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4538
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4539
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4540
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4541
$result = $dbi->select(
4542
    table => $table1,
4543
    column => [{$table2 => [$key3]}],
4544
    join => [
4545
        {
4546
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4547
            table => [$table1, $table2]
4548
        }
4549
    ]
4550
);
4551
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4552

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4553
$dbi = DBIx::Custom->connect;
4554
eval { $dbi->execute("drop table $table1") };
4555
eval { $dbi->execute("drop table $table2") };
4556
$dbi->execute($create_table1);
4557
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4558
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4559
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4560
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4561
$result = $dbi->select(
4562
    table => $table1,
4563
    column => [{$table2 => [$key3]}],
4564
    join => [
4565
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4566
    ]
4567
);
4568
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4569

            
4570
$dbi = DBIx::Custom->connect;
4571
eval { $dbi->execute("drop table $table1") };
4572
eval { $dbi->execute("drop table $table2") };
4573
$dbi->execute($create_table1);
4574
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4575
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4576
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4577
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4578
$result = $dbi->select(
4579
    table => $table1,
4580
    column => [{$table2 => [$key3]}],
4581
    join => [
4582
        "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4583
    ]
4584
);
4585
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4586

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4587
test 'columns';
4588
$dbi = MyDBI1->connect;
4589
$model = $dbi->model($table1);
4590

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4591
test 'count';
4592
$dbi = DBIx::Custom->connect;
4593
eval { $dbi->execute("drop table $table1") };
4594
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4595
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4596
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4597
is($dbi->count(table => $table1), 2);
4598
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4599
$model = $dbi->create_model(table => $table1);
4600
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4601

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4602
eval { $dbi->execute("drop table $table1") };
4603
eval { $dbi->execute("drop table $table2") };
4604
$dbi->execute($create_table1);
4605
$dbi->execute($create_table2);
4606
$model = $dbi->create_model(table => $table1, primary_key => $key1);
4607
$model->insert({$key1 => 1, $key2 => 2});
4608
$model = $dbi->create_model(table => $table2, primary_key => $key1,
4609
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
4610
$model->insert({$key1 => 1, $key3 => 3});
4611
is($model->count(id => 1), 1);
4612
is($model->count(where => {"$table2.$key3" => 3}), 1);
4613

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