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

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

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

            
14
plan 'no_plan';
15

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

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

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

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

            
90
    use strict;
91
    use warnings;
92

            
93
    use base 'DBIx::Custom';
94

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

            
106
    package MyModel2::Base1;
107

            
108
    use strict;
109
    use warnings;
110

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

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

            
115
    use strict;
116
    use warnings;
117

            
118
    use base 'MyModel2::Base1';
119

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

            
126
    sub list { shift->select; }
127

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

            
130
    use strict;
131
    use warnings;
132

            
133
    use base 'MyModel2::Base1';
134

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

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

            
143
    package MyModel2::TABLE1;
144

            
145
    use strict;
146
    use warnings;
147

            
148
    use base 'MyModel2::Base1';
149

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

            
156
    sub list { shift->select; }
157

            
158
    package MyModel2::TABLE2;
159

            
160
    use strict;
161
    use warnings;
162

            
163
    use base 'MyModel2::Base1';
164

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

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

            
176
    use strict;
177
    use warnings;
178

            
179
    use base 'DBIx::Custom';
180

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

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

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
242
test 'execute reuse option';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
243
eval { $dbi->execute("drop table $table1") };
244
$dbi->execute($create_table1);
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
245
$reuse = {};
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
246
for my $i (1 .. 2) {
test cleanup
Yuki Kimoto authored on 2011-11-01
247
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, reuse => $reuse);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
248
}
249
$rows = $dbi->select(table => $table1)->all;
250
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 1, $key2 => 2}]);
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'});
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1200
$row = $result->fetch_one;
1201
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter");
1202

            
1203
test 'fetch_first DEPRECATED!';
1204
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1205
$result->filter({$key1 => 'three_times'});
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1206
$row = $result->fetch_first;
1207
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter");
1208

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1209
test 'filters';
1210
$dbi = DBIx::Custom->new;
1211

            
1212
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
1213
   'あ', "decode_utf8");
1214

            
1215
is($dbi->filters->{encode_utf8}->('あ'),
1216
   encode_utf8('あ'), "encode_utf8");
1217

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1228
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1229
ok(! $result->fetch_one, "rollback");
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1230

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

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

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

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

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

            
1276

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1277
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1278
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1279
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1280
$dbi->execute($create_table1);
1281

            
1282
$dbi->begin_work;
1283

            
1284
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1285
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1286
    die "Error";
test cleanup
Yuki Kimoto authored on 2011-11-01
1287
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1288
};
1289

            
1290
$dbi->rollback if $@;
1291

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

            
1296
$dbi->begin_work;
1297

            
1298
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1299
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1300
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1301
};
1302

            
1303
$dbi->commit unless $@;
1304

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

            
1309
$dbi->dbh->{AutoCommit} = 0;
1310
eval{ $dbi->begin_work };
1311
ok($@, "exception");
1312
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1313

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

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

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

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

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

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

            
1375
is($dbi->one, 1, "first");
1376
is($dbi->two, 2, "second");
1377
is($dbi->twice(5), 10 , "second");
1378

            
1379
eval {$dbi->XXXXXX};
1380
ok($@, "not exists");
1381

            
1382
test 'out filter';
1383
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1384
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1385
$dbi->execute($create_table1);
1386
$dbi->register_filter(twice => sub { $_[0] * 2 });
1387
$dbi->register_filter(three_times => sub { $_[0] * 3});
1388
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1389
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1390
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
1391
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1392
$result = $dbi->execute("select * from $table1");
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1393
$row   = $result->fetch_hash_one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1394
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1395
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1396
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1397
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1398

            
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1399
test 'fetch_hash_first DEPRECATED!';
1400
$result = $dbi->execute("select * from $table1");
1401
$row   = $result->fetch_hash_first;
1402
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1403

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

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

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

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

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

            
1473
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1474
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1475
$dbi->execute($create_table1);
1476
$dbi->register_filter(twice => sub { $_[0] * 2 });
1477
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1478
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1479
);
cleanup
Yuki Kimoto authored on 2011-11-01
1480
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1481
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
1482
                        {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1483
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1484
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1485

            
1486
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1487
eval { $dbi->execute("drop table $table1") };
1488
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1489
$dbi->execute($create_table1);
1490
$dbi->execute($create_table2);
1491
$dbi->register_filter(twice => sub { $_[0] * 2 });
1492
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1493
$dbi->apply_filter(
cleanup test
Yuki Kimoto authored on 2011-08-15
1494
    $table1, $key2 => {out => 'twice', in => 'twice'}
1495
);
1496
$dbi->apply_filter(
1497
    $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1498
);
cleanup
Yuki Kimoto authored on 2011-11-01
1499
$dbi->insert({$key1 => 5, $key2 => 2}, table => $table1, filter => {$key2 => undef});
1500
$dbi->insert({$key1 => 5, $key3 => 6}, table => $table2, filter => {$key3 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1501
$result = $dbi->select(
1502
     table => [$table1, $table2],
1503
     column => [$key2, $key3],
1504
     where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1505

            
1506
$result->filter({$key2 => 'twice'});
1507
$rows   = $result->all;
1508
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1509

            
1510
$result = $dbi->select(
1511
     table => [$table1, $table2],
1512
     column => [$key2, $key3],
1513
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1514

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

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

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

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

            
1539
test 'end_filter';
1540
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1541
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1542
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1543
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1544
$result = $dbi->select(table => $table1);
1545
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1546
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1547
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1548
is_deeply($row, [6, 40]);
1549

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1550
$dbi = DBIx::Custom->connect;
1551
eval { $dbi->execute("drop table $table1") };
1552
$dbi->execute($create_table1);
1553
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1554
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1555
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1556
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1557
$row = $result->fetch_one;
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1558
is_deeply($row, [6, 6, 40]);
1559

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

            
1570
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1571
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1572
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1573
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1574
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1575
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1576
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1577
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1578
is_deeply($row, [6, 12]);
1579

            
1580
$dbi->register_filter(five_times => sub { $_[0] * 5 });
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 });
1583
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1584
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1585
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1586

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

            
1597
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1598
$dbi->apply_filter($table1,
1599
    $key1 => {end => sub { $_[0] * 3 } },
1600
    $key2 => {end => 'five_times'}
1601
);
1602
$result = $dbi->select(table => $table1);
1603
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1604
$result->filter($key1 => undef);
1605
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1606
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1607
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1608

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1609
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1610
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1611
$result->filter($key1 => undef);
1612
$result->end_filter($key1 => undef);
1613
$row = $result->fetch;
1614
is_deeply($row, [1, 1, 40], 'apply_filter overwrite');
1615

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1616
test 'remove_end_filter and remove_filter';
1617
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1618
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1619
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1620
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1621
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1622
$row = $result
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1623
       ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1624
       ->remove_filter
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1625
       ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
test cleanup
Yuki Kimoto authored on 2011-08-10
1626
       ->remove_end_filter
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1627
       ->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1628
is_deeply($row, [1, 2]);
1629

            
1630
test 'empty where select';
1631
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1632
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1633
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1634
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1635
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1636
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1637
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1638

            
1639
test 'select query option';
1640
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1641
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1642
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1643
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1644
ok(ref $query);
cleanup
Yuki Kimoto authored on 2011-11-01
1645
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1646
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1647
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1648
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1649
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1650
ok(ref $query);
test cleanup
Yuki Kimoto authored on 2011-08-10
1651

            
1652
test 'where';
1653
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1654
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1655
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1656
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1657
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1658
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1659
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1660

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

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

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

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

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

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

            
1712
$where = $dbi->where;
1713
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1714
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1715
    where => $where
1716
);
1717
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1718
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1719

            
1720
eval {
1721
$where = $dbi->where
1722
             ->clause(['uuu']);
1723
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1724
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1725
    where => $where
1726
);
1727
};
1728
ok($@);
1729

            
1730
$where = $dbi->where;
1731
is("$where", '');
1732

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1873
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1874
             ->clause(['and', "{> $key1}", "{< $key1}" ])
1875
             ->param({$key1 => [$dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1876
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1877
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1878
    where => $where,
1879
);
1880
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1881
is_deeply($row, [{$key1 => 1, $key2 => 2},{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1882

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

            
1893
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1894
             ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1895
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1896
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1897
    where => $where,
1898
);
1899
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1900
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1901

            
1902
eval {$dbi->where(ppp => 1) };
1903
like($@, qr/invalid/);
1904

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

            
1916

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

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

            
1935
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1936
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1937
$where->param({$key1 => [undef, undef]});
1938
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1939
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1940
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1941
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1942
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1943
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1944

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

            
1946
$dbi = DBIx::Custom->connect;
1947
eval { $dbi->execute("drop table $table1") };
1948
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1949
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
1950
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1951
$where = $dbi->where
1952
             ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
1953
             ->param({$key1 => 1});
1954

            
1955
$result = $dbi->select(
1956
    table => $table1,
1957
    where => $where
1958
);
1959
$row = $result->all;
1960
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
1961

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1962
test 'register_tag_processor';
1963
$dbi = DBIx::Custom->connect;
1964
$dbi->register_tag_processor(
1965
    a => sub { 1 }
1966
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1967
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1968

            
1969
test 'register_tag';
1970
$dbi = DBIx::Custom->connect;
1971
$dbi->register_tag(
1972
    b => sub { 2 }
1973
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1974
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1975

            
1976
test 'table not specify exception';
1977
$dbi = DBIx::Custom->connect;
1978
eval {$dbi->select};
1979
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1980

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1981
test 'more tests';
1982
$dbi = DBIx::Custom->connect;
1983
eval{$dbi->apply_filter('table', 'column', [])};
1984
like($@, qr/apply_filter/);
1985

            
1986
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1987
like($@, qr/apply_filter/);
1988

            
1989
$dbi->apply_filter(
1990

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

            
2002
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2003
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2004
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2005
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2006
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2007
$dbi->apply_filter($table1, $key2, {});
2008
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
2009
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2010

            
2011
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2012
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2013
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2014
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2015
like($@, qr/not registered/);
2016
$dbi->method({one => sub { 1 }});
2017
is($dbi->one, 1);
2018

            
2019
eval{DBIx::Custom->connect(dsn => undef)};
2020
like($@, qr/_connect/);
2021

            
2022
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2023
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2024
$dbi->execute($create_table1);
2025
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
2026
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2027
             filter => {$key1 => 'twice'});
2028
$row = $dbi->select(table => $table1)->one;
2029
is_deeply($row, {$key1 => 2, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
2030
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2031
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
2032
like($@, qr//);
2033

            
2034
$dbi->register_filter(one => sub { });
2035
$dbi->default_fetch_filter('one');
2036
ok($dbi->default_fetch_filter);
2037
$dbi->default_bind_filter('one');
2038
ok($dbi->default_bind_filter);
2039
eval{$dbi->default_fetch_filter('no')};
2040
like($@, qr/not registered/);
2041
eval{$dbi->default_bind_filter('no')};
2042
like($@, qr/not registered/);
2043
$dbi->default_bind_filter(undef);
2044
ok(!defined $dbi->default_bind_filter);
2045
$dbi->default_fetch_filter(undef);
2046
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2047
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2048
like($@, qr/Tag not finished/);
2049

            
2050
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2051
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2052
$dbi->execute($create_table1);
2053
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2054
$result = $dbi->select(table => $table1);
2055
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2056
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2057
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2058
like($@, qr/not registered/);
2059
$result->default_filter(undef);
2060
ok(!defined $result->default_filter);
2061
$result->default_filter('one');
2062
is($result->default_filter->(), 1);
2063

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2064
test 'option';
2065
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
2066
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
2067
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2068
ok($dbi->dbh->{PrintError});
2069
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2070
ok($dbi->dbh->{PrintError});
2071

            
2072
test 'DBIx::Custom::Result stash()';
2073
$result = DBIx::Custom::Result->new;
2074
is_deeply($result->stash, {}, 'default');
2075
$result->stash->{foo} = 1;
2076
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2077

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2078
test 'delete_at';
2079
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2080
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2081
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2082
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2083
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2084
    table => $table1,
2085
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2086
    where => [1, 2],
2087
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2088
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2089

            
cleanup
Yuki Kimoto authored on 2011-11-01
2090
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2091
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2092
    table => $table1,
2093
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2094
    where => 1,
2095
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2096
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2097

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2112
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2113
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2114
$dbi->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2115
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2116
    primary_key => $key1, 
2117
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2118
    where => 1,
2119
);
2120

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

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

            
2138
test 'update_at';
2139
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2140
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2141
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2142
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2143
$dbi->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2144
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2145
    table => $table1,
2146
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2147
    where => [1, 2],
2148
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2149
is($dbi->select(table => $table1)->one->{$key1}, 1);
2150
is($dbi->select(table => $table1)->one->{$key2}, 2);
2151
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2152

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

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

            
2179
test 'select_at';
2180
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2181
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2182
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2183
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2184
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2185
    table => $table1,
2186
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2187
    where => [1, 2]
2188
);
2189
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2190
is($row->{$key1}, 1);
2191
is($row->{$key2}, 2);
2192
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2193

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2206
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2207
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2208
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2209
    table => $table1,
2210
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2211
    where => [1, 2]
2212
);
2213
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2214
is($row->{$key1}, 1);
2215
is($row->{$key2}, 2);
2216
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2217

            
2218
test 'model delete_at';
2219
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2220
eval { $dbi->execute("drop table $table1") };
2221
eval { $dbi->execute("drop table $table2") };
2222
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2223
$dbi->execute($create_table1_2);
2224
$dbi->execute($create_table2_2);
2225
$dbi->execute($create_table3);
test cleanup
Yuki Kimoto authored on 2011-11-01
2226
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2227
$dbi->model($table1)->delete_at(where => [1, 2]);
2228
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2229
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2230
$dbi->model($table1)->delete_at(where => [1, 2]);
2231
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2232
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2233
$dbi->model($table3)->delete_at(where => [1, 2]);
2234
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2235

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

            
2250
test 'model update_at';
2251
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2252
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2253
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2254
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2255
$dbi->model($table1)->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2256
    {$key3 => 4},
cleanup test
Yuki Kimoto authored on 2011-08-10
2257
    where => [1, 2],
2258
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2259
$result = $dbi->model($table1)->select;
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}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2264

            
2265
test 'model select_at';
2266
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2267
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2268
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2269
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2270
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2271
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2272
is($row->{$key1}, 1);
2273
is($row->{$key2}, 2);
2274
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2275

            
2276

            
2277
test 'mycolumn and column';
2278
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2279
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2280
eval { $dbi->execute("drop table $table1") };
2281
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2282
$dbi->execute($create_table1);
2283
$dbi->execute($create_table2);
2284
$dbi->separator('__');
2285
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2286
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2287
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2288
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2289
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2290
    column => [$model->mycolumn, $model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2291
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2292
);
2293
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2294
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2295

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

            
2309
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2310
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2311
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2312
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2313
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2314
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2315
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2316
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2317
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2318
is($dbi->select(table => $table1)->one->{$key1}, 1);
2319
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2320

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2321
test 'mycolumn';
2322
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2323
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2324
eval { $dbi->execute("drop table $table1") };
2325
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2326
$dbi->execute($create_table1);
2327
$dbi->execute($create_table2);
2328
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2329
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2330
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2331
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2332
$result = $model->select_at(
2333
    column => [
2334
        $model->mycolumn,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2335
        $model->column($table2)
cleanup test
Yuki Kimoto authored on 2011-08-10
2336
    ]
2337
);
2338
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2339
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2340

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

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

            
2367
$result = $model->select_at(
2368
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2369
        $model->mycolumn([$key1]),
2370
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2371
    ]
2372
);
2373
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2374
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2375

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2376
test 'merge_param';
2377
$dbi = DBIx::Custom->new;
2378
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2379
    {$key1 => 1, $key2 => 2, $key3 => 3},
2380
    {$key1 => 1, $key2 => 2},
2381
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2382
];
2383
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2384
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2385

            
2386
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2387
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2388
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2389
];
2390
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2391
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
2392

            
2393
test 'select() param option';
2394
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2395
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2396
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2397
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2398
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2399
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2400
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2401
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
2402
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
2403
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2404
    table => $table1,
2405
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2406
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2407
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
test cleanup
Yuki Kimoto authored on 2011-08-15
2408
              " $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2409
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2410
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2411
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2412

            
cleanup
Yuki Kimoto authored on 2011-10-21
2413
$rows = $dbi->select(
2414
    table => $table1,
2415
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2416
    where   => {"$table1.$key2" => 3},
2417
    join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2418
             " $table2 on $table1.$key1 = $table2.$key1",
2419
    param => {"$table2.$key3" => 5}
2420
)->all;
2421
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2422

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
2450
$dbi = DBIx::Custom->connect;
2451
eval { $dbi->execute("drop table $table1") };
2452
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2453
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2454
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
2455
$rows = $dbi->select(
2456
    table => $table1,
2457
    where => [
2458
        "$key1 = :$key1 and $key2 = :$key2",
2459
        {$key1 => 1, $key2 => 2}
2460
    ]
2461
)->all;
2462
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2463

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

            
2478
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2479
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2480
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2481
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2482
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2483
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2484
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2485
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2486
        "$key1 = :$key1 and $key2 = :$key2",
2487
         {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2488
    ]
2489
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2490
$rows = $dbi->select(table => $table1)->all;
2491
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2492

            
2493

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

            
2508
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2509
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2510
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2511
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2512
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2513
    {$key1 => 5},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2514
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2515
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2516
        "$key1 = :$key1 and $key2 = :$key2",
2517
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2518
    ]
2519
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2520
$rows = $dbi->select(table => $table1)->all;
2521
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2522

            
2523
test 'insert id and primary_key option';
2524
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2525
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2526
$dbi->execute($create_table1_2);
2527
$dbi->insert(
cleanup
Yuki Kimoto authored on 2011-11-01
2528
    {$key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2529
    primary_key => [$key1, $key2], 
2530
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2531
    id => [1, 2],
2532
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2533
is($dbi->select(table => $table1)->one->{$key1}, 1);
2534
is($dbi->select(table => $table1)->one->{$key2}, 2);
2535
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2536

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2537
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2538
$dbi->insert(
cleanup
Yuki Kimoto authored on 2011-11-01
2539
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2540
    primary_key => $key1, 
2541
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2542
    id => 0,
2543
);
2544

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2549
$dbi = DBIx::Custom->connect;
2550
eval { $dbi->execute("drop table $table1") };
2551
$dbi->execute($create_table1_2);
2552
$dbi->insert(
2553
    {$key3 => 3},
2554
    primary_key => [$key1, $key2], 
2555
    table => $table1,
2556
    id => 1,
2557
);
2558
is($dbi->select(table => $table1)->one->{$key1}, 1);
2559
ok(!$dbi->select(table => $table1)->one->{$key2});
2560
is($dbi->select(table => $table1)->one->{$key3}, 3);
2561

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

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2575
$dbi = DBIx::Custom->connect;
2576
eval { $dbi->execute("drop table $table1") };
2577
$dbi->execute($create_table1_2);
2578
$param = {$key3 => 3, $key2 => 4};
2579
$dbi->insert(
2580
    $param,
2581
    primary_key => [$key1, $key2], 
2582
    table => $table1,
2583
    id => [1, 2],
2584
);
2585
is($dbi->select(table => $table1)->one->{$key1}, 1);
2586
is($dbi->select(table => $table1)->one->{$key2}, 4);
2587
is($dbi->select(table => $table1)->one->{$key3}, 3);
2588
is_deeply($param, {$key3 => 3, $key2 => 4});
2589

            
added test
Yuki Kimoto authored on 2011-10-25
2590
$dbi = DBIx::Custom->connect;
2591
eval { $dbi->execute("drop table $table1") };
2592
$dbi->execute($create_table1_2);
2593
$param = {$key3 => 3, $key2 => 4};
2594
$query = $dbi->insert(
2595
    $param,
2596
    primary_key => [$key1, $key2], 
2597
    table => $table1,
2598
    id => [1, 2],
2599
    query => 1
2600
);
micro optimization
Yuki Kimoto authored on 2011-11-16
2601
ok(ref $query);
added test
Yuki Kimoto authored on 2011-10-25
2602
is_deeply($param, {$key3 => 3, $key2 => 4});
2603

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2646
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2647
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2648
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2649
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2650
    table => $table1,
2651
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2652
    id => 0,
2653
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2654
is($dbi->select(table => $table1)->one->{$key1}, 0);
2655
is($dbi->select(table => $table1)->one->{$key2}, 2);
2656
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2657

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

            
2672

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

            
2688

            
2689
test 'delete and id option';
2690
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2691
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2692
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2693
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2694
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2695
    table => $table1,
2696
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2697
    id => [1, 2],
2698
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2699
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2700

            
cleanup
Yuki Kimoto authored on 2011-11-01
2701
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2702
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2703
    table => $table1,
2704
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2705
    id => 0,
2706
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2707
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2708

            
2709

            
2710
test 'model delete and id option';
2711
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2712
eval { $dbi->execute("drop table $table1") };
2713
eval { $dbi->execute("drop table $table2") };
2714
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2715
$dbi->execute($create_table1_2);
2716
$dbi->execute($create_table2_2);
2717
$dbi->execute($create_table3);
cleanup
Yuki Kimoto authored on 2011-11-01
2718
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2719
$dbi->model($table1)->delete(id => [1, 2]);
2720
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2721
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2722
$dbi->model($table1)->delete(id => [1, 2]);
2723
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2724
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2725
$dbi->model($table3)->delete(id => [1, 2]);
2726
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2727

            
2728

            
2729
test 'select and id option';
2730
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2731
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2732
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2733
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2734
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2735
    table => $table1,
2736
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2737
    id => [1, 2]
2738
);
2739
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2740
is($row->{$key1}, 1);
2741
is($row->{$key2}, 2);
2742
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2743

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2756
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2757
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2758
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2759
    table => $table1,
2760
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2761
    id => [1, 2]
2762
);
2763
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2764
is($row->{$key1}, 1);
2765
is($row->{$key2}, 2);
2766
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2767

            
2768

            
2769
test 'model select_at';
2770
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2771
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2772
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2773
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2774
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2775
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2776
is($row->{$key1}, 1);
2777
is($row->{$key2}, 2);
2778
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2779

            
2780
test 'column separator is default .';
2781
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2782
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2783
eval { $dbi->execute("drop table $table1") };
2784
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2785
$dbi->execute($create_table1);
2786
$dbi->execute($create_table2);
2787
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2788
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2789
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2790
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2791
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2792
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2793
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2794
);
2795
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2796
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2797

            
2798
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2799
    column => [$model->column($table2 => [$key1, $key3])],
2800
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2801
);
2802
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2803
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2804

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2805
test 'separator';
2806
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2807
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2808
eval { $dbi->execute("drop table $table1") };
2809
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2810
$dbi->execute($create_table1);
2811
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2812

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2813
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2814
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2815
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2816
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2817
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2818
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2819
);
2820
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2821
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2822
);
2823
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2824
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2825
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2826
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2827
$result = $model->select(
2828
    column => [
2829
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2830
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2831
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2832
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2833
);
2834
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2835
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2836
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2837

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2851
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2852
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2853
$result = $model->select(
2854
    column => [
2855
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2856
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2857
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2858
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2859
);
2860
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2861
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2862
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2863

            
2864

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2865
test 'filter_off';
2866
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2867
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2868
eval { $dbi->execute("drop table $table1") };
2869
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2870
$dbi->execute($create_table1);
2871
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2872

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2873
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2874
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2875
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2876
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2877
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2878
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2879
);
2880
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2881
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2882
$model = $dbi->model($table1);
2883
$result = $model->select(column => $key1);
2884
$result->filter($key1 => sub { $_[0] * 2 });
2885
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2886

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2887
test 'available_datetype';
2888
$dbi = DBIx::Custom->connect;
2889
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2890

            
2891

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2892
test 'select prefix option';
2893
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2894
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2895
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2896
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2897
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2898
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2899

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

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

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2911
$dbi = DBIx::Custom->connect;
2912
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2913
    id => {key => "$table1.id"},
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2914
    author => ["$table1.author" => $dbi->like_value],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2915
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2916
);
2917
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2918
  "$table1.price" => 1900});
2919

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

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

            
2934
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2935
    id => {key => "$table1.id"},
2936
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2937
);
2938
is_deeply($param, {"$table1.price" => undef});
2939

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

            
2946
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2947
    id => {key => "$table1.id"},
added tests
Yuki Kimoto authored on 2011-08-26
2948
    price => ["$table1.price", sub { '%' . $_[0] }]
2949
);
2950
is_deeply($param, {"$table1.price" => '%a'});
2951

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2952
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2953
    price => sub { '%' . $_[0] },
2954
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2955
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2956
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2957

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

            
2963
$where = $dbi->where;
2964
$where->clause(['and', ":${key1}{=}"]);
2965
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
2966
$where->param($param);
2967
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2968
$row = $result->all;
2969
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2970

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

            
2981
$where = $dbi->where;
2982
$where->clause(['and', ":${key1}{=}"]);
2983
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
2984
$where->param($param);
2985
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2986
$row = $result->all;
2987
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2988
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2989
$row = $result->all;
2990
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2991

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2993
$where = $dbi->where;
2994
$where->clause(['and', ":${key1}{=}"]);
2995
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
2996
  ->pass([$key1, $key2])->map;
2997
$where->param($param);
2998
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2999
$row = $result->all;
3000
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3001

            
3002
$where = $dbi->where;
3003
$where->clause(['and', ":${key1}{=}"]);
3004
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
3005
$where->param($param);
3006
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3007
$row = $result->all;
3008
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3009

            
3010
$where = $dbi->where;
3011
$where->clause(['and', ":${key1}{=}"]);
3012
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
3013
  ->pass([$key1, $key2])->map;
3014
$where->param($param);
3015
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3016
$row = $result->all;
3017
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3018

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3020
$where = $dbi->where;
3021
$where->clause(['and', ":${key1}{=}"]);
3022
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
3023
$where->param($param);
3024
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3025
$row = $result->all;
3026
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3027

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

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

            
3047
$where = $dbi->where;
3048
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3049
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3050
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3051
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3052
);
3053
$where->param($param);
3054
is_deeply($where->param, {});
3055

            
3056
$where = $dbi->where;
3057
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3058
    id => {key => "$table1.id"},
3059
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3060
);
3061
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
3062

            
3063
$where = $dbi->where;
3064
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3065
    id => {key => "$table1.id", condition => 'exists'},
3066
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3067
);
3068
is_deeply($param, {"$table1.price" => '%a'});
3069

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

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

            
3088
$where = $dbi->where;
3089
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3090
    id => {key => "$table1.id", condition => 'length'},
3091
    author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
3092
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3093
);
3094
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
3095
  "$table1.price" => 1900});
3096

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3102
test 'order';
3103
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3104
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3105
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3106
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3107
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3108
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3109
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3110
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3111
$order->prepend($key1, "$key2 desc");
3112
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3113
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
3114
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3115
$order->prepend("$key1 desc");
3116
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3117
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
3118
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3119

            
3120
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3121
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3122
$result = $dbi->select(table => $table1,
3123
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3124
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3125
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
3126
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
3127
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
3128
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3129

            
3130
test 'tag_parse';
3131
$dbi = DBIx::Custom->connect;
3132
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3133
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3134
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3135
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3136
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3137
ok($@);
3138

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3139
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3140
{
3141
    $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3142
    $dbi = DBIx::Custom->connect;
3143
    eval { $dbi->execute("drop table $table1") };
3144
    $dbi->execute($create_table1);
3145
    $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3146
    eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3147
    ok($@);
cleanup
Yuki Kimoto authored on 2011-11-16
3148
    eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) };
3149
    ok($@);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3150
    delete$ENV{DBIX_CUSTOM_TAG_PARSE};
3151
}
3152

            
3153
{
3154
    $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3155
    $dbi = DBIx::Custom->connect;
3156
    eval { $dbi->execute("drop table $table1") };
3157
    $dbi->execute($create_table1);
3158
    $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-16
3159
    is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3160
    delete$ENV{DBIX_CUSTOM_TAG_PARSE};
3161
}
3162

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3163
test 'last_sql';
3164
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3165
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3166
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3167
$dbi->execute("select * from $table1");
micro optimization
Yuki Kimoto authored on 2011-11-18
3168
is($dbi->last_sql, " select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3169

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3201
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3202
$result = $dbi->execute(
3203
    $source,
cleanup
Yuki Kimoto authored on 2011-11-01
3204
    {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3205
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3206
);
3207
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3208
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3209

            
3210
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3211
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3212
$dbi->execute($create_table1_highperformance);
3213
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3214
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3215
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3216
];
3217
{
3218
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3219
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3220
      $query ||= $dbi->insert($row, table => $table1, query => 1);
3221
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
3222
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3223
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3224
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3225
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3226
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3227
      ]
3228
    );
3229
}
3230

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3231
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3232
$dbi->execute($create_table1_highperformance);
3233
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3234
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3235
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3236
];
3237
{
3238
    my $query;
3239
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
3240
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3241
      $query ||= $dbi->insert($row, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
3242
      $sth ||= $query->{sth};
test cleanup
Yuki Kimoto authored on 2011-08-10
3243
      $sth->execute(map { $row->{$_} } sort keys %$row);
3244
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3245
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3246
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3247
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3248
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3249
      ]
3250
    );
3251
}
3252

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

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3274
eval { $dbi->execute("drop table $table1") };
3275
$dbi->execute($create_table1);
3276
{
3277
    $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3278
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3279
    eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3280
    like($@, qr/primary_key/);
3281
    delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
3282
}
3283

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

            
3294
eval { $dbi->execute("drop table $table1") };
3295
$dbi->execute($create_table1);
3296
{
3297
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3298
    $model->insert({$key1 => 1});
3299
    eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3300
    is($result->one->{$key1}, 1);
3301
}
3302

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3303
test 'id option more';
3304
eval { $dbi->execute("drop table $table1") };
3305
$dbi->execute($create_table1_highperformance);
3306
$row = {
3307
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3308
};
3309
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3310
$model->insert($row);
3311
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3312
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3313
is_deeply($dbi->select(table => $table1)->one,
3314
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3315
);
3316

            
3317
eval { $dbi->execute("drop table $table1") };
3318
eval { $dbi->execute("drop table $table2") };
3319
$dbi->execute($create_table1);
3320
$dbi->execute($create_table2);
3321
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3322
$model->insert({$key1 => 1, $key2 => 2});
3323
$model = $dbi->create_model(table => $table2, primary_key => $key1,
3324
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
3325
$model->insert({$key1 => 1, $key3 => 3});
3326
$result = $model->select(
3327
    column => {$table1 => ["$key2"]},
3328
    id => 1
3329
);
3330
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3331

            
3332
eval { $dbi->execute("drop table $table1") };
3333
$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->delete(id => 1, query => 1);
3340
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3341
is_deeply($dbi->select(table => $table1)->all, []);
3342

            
3343
eval { $dbi->execute("drop table $table1") };
3344
eval { $dbi->execute($create_table1_highperformance) };
3345
$row = {
3346
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3347
};
3348
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3349
$model->insert($row);
3350
$query = $model->select(id => 1, query => 1);
3351
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3352
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3353
is_deeply($dbi->select(table => $table1)->one,
3354
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3355
);
3356

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3357
test 'result';
3358
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3359
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3360
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3361
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3362
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3363

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3364
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3365
@rows = ();
3366
while (my $row = $result->fetch) {
3367
    push @rows, [@$row];
3368
}
3369
is_deeply(\@rows, [[1, 2], [3, 4]]);
3370

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3371
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3372
@rows = ();
3373
while (my $row = $result->fetch_hash) {
3374
    push @rows, {%$row};
3375
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3376
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3377

            
3378
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3379
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3380
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3381
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3382
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3383

            
3384
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3385
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3386
$rows = $result->fetch_all;
3387
is_deeply($rows, [[1, 2], [3, 4]]);
3388

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

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

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

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3411
test 'DBIx::Custom::Result fetch_multi';
3412
eval { $dbi->execute("drop table $table1") };
3413
$dbi->execute($create_table1);
3414
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3415
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3416
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3417
$result = $dbi->select(table => $table1);
3418
$rows = $result->fetch_multi(2);
3419
is_deeply($rows, [[1, 2], [3, 4]]);
3420
$rows = $result->fetch_multi(2);
3421
is_deeply($rows, [[5, 6]]);
3422
$rows = $result->fetch_multi(2);
3423
ok(!$rows);
3424

            
3425
test 'DBIx::Custom::Result fetch_hash_multi';
3426
eval { $dbi->execute("drop table $table1") };
3427
$dbi->execute($create_table1);
3428
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3429
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3430
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3431
$result = $dbi->select(table => $table1);
3432
$rows = $result->fetch_hash_multi(2);
3433
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3434
$rows = $result->fetch_hash_multi(2);
3435
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3436
$rows = $result->fetch_hash_multi(2);
3437
ok(!$rows);
3438

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3439
test "query_builder";
3440
$datas = [
3441
    # Basic tests
3442
    {   name            => 'placeholder basic',
3443
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3444
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3445
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3446
    },
3447
    {
3448
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3449
        source            => "{in k1 3}",
3450
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3451
        columns_expected   => [qw/k1 k1 k1/]
3452
    },
3453
    
3454
    # Table name
3455
    {
3456
        name            => 'placeholder with table name',
3457
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3458
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3459
        columns_expected  => [qw/a.k1 a.k2/]
3460
    },
3461
    {   
3462
        name            => 'placeholder in with table name',
3463
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3464
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3465
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3466
    },
3467
    {
3468
        name            => 'not contain tag',
3469
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3470
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3471
        columns_expected  => [],
3472
    }
3473
];
3474

            
3475
for (my $i = 0; $i < @$datas; $i++) {
3476
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3477
    my $dbi = DBIx::Custom->new;
3478
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3479
    my $query = $builder->build_query($data->{source});
3480
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
micro optimization
Yuki Kimoto authored on 2011-11-16
3481
    is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3482
}
3483

            
cleanup
Yuki Kimoto authored on 2011-08-13
3484
$dbi = DBIx::Custom->new;
3485
$builder = $dbi->query_builder;
3486
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3487
    p => sub {
3488
        my @args = @_;
3489
        
3490
        my $expand    = "? $args[0] $args[1]";
3491
        my $columns = [2];
3492
        return [$expand, $columns];
3493
    }
3494
);
3495

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3506
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3507
    q => 'string'
3508
});
3509

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3513
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3514
   r => sub {} 
3515
});
3516

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3520
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3521
   s => sub { return ["a", ""]} 
3522
});
3523

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3527
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3528
    t => sub {return ["a", []]}
3529
);
3530

            
3531

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

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

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

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

            
3547
test 'variouse source';
3548
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3549
$query = $builder->build_query($source);
3550
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3551

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

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

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

            
3564
$source = "a {= b} }";
3565
eval{$builder->build_query($source)};
3566
like($@, qr/unexpected "}"/, "error : 1");
3567

            
3568
$source = "a {= {}";
3569
eval{$builder->build_query($source)};
3570
like($@, qr/unexpected "{"/, "error : 2");
3571

            
3572
test 'select() sqlfilter option';
3573
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3574
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3575
eval { $dbi->execute("drop table $table1") };
3576
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3577
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3578
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3579
$rows = $dbi->select(
3580
    table => $table1,
3581
    column => $key1,
3582
    sqlfilter => sub {
3583
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
3584
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
3585
        return $sql;
3586
    }
3587
)->all;
3588
is_deeply($rows, [{$key1 => 1}]);
3589

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3590
test 'select() after_build_sql option';
3591
$dbi = DBIx::Custom->connect;
3592
$dbi->user_table_info($user_table_info);
3593
eval { $dbi->execute("drop table $table1") };
3594
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3595
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3596
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3597
$rows = $dbi->select(
3598
    table => $table1,
3599
    column => $key1,
3600
    after_build_sql => sub {
3601
        my $sql = shift;
3602
        $sql = "select * from ( $sql ) t where $key1 = 1";
3603
        return $sql;
3604
    }
3605
)->all;
3606
is_deeply($rows, [{$key1 => 1}]);
3607

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3608
test 'dbi method from model';
3609
$dbi = MyDBI9->connect;
3610
eval { $dbi->execute("drop table $table1") };
3611
$dbi->execute($create_table1);
3612
$dbi->setup_model;
3613
$model = $dbi->model($table1);
3614
eval{$model->execute("select * from $table1")};
3615
ok(!$@);
3616

            
3617
test 'column table option';
3618
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3619
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3620
eval { $dbi->execute("drop table $table1") };
3621
$dbi->execute($create_table1);
3622
eval { $dbi->execute("drop table $table2") };
3623
$dbi->execute($create_table2);
3624
$dbi->setup_model;
3625
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3626
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3627
$model = $dbi->model($table1);
3628
$result = $model->select(
3629
    column => [
3630
        $model->column($table2, {alias => $table2_alias})
3631
    ],
3632
    where => {"$table2_alias.$key3" => 4}
3633
);
3634
is_deeply($result->one, 
3635
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3636

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

            
3647
$dbi->separator('-');
3648
$result = $model->select(
3649
    column => [
3650
        $model->column($table2, {alias => $table2_alias})
3651
    ],
3652
    where => {"$table2_alias.$key3" => 4}
3653
);
3654
is_deeply($result->one, 
3655
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3656

            
3657
test 'create_model';
3658
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3659
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3660
eval { $dbi->execute("drop table $table1") };
3661
eval { $dbi->execute("drop table $table2") };
3662
$dbi->execute($create_table1);
3663
$dbi->execute($create_table2);
3664

            
3665
$dbi->create_model(
3666
    table => $table1,
3667
    join => [
3668
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3669
    ],
3670
    primary_key => [$key1]
3671
);
3672
$model2 = $dbi->create_model(
3673
    table => $table2
3674
);
3675
$dbi->create_model(
3676
    table => $table3,
3677
    filter => [
3678
        $key1 => {in => sub { uc $_[0] }}
3679
    ]
3680
);
3681
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3682
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3683
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3684
$model = $dbi->model($table1);
3685
$result = $model->select(
3686
    column => [$model->mycolumn, $model->column($table2)],
3687
    where => {"$table1.$key1" => 1}
3688
);
3689
is_deeply($result->one,
3690
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3691
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3692

            
3693
test 'model method';
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);
cleanup test
Yuki Kimoto authored on 2011-08-15
3698
$model = $dbi->create_model(
3699
    table => $table2
3700
);
3701
$model->method(foo => sub { shift->select(@_) });
3702
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3703

            
3704
test 'model helper';
3705
$dbi = DBIx::Custom->connect;
3706
eval { $dbi->execute("drop table $table2") };
3707
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3708
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3709
$model = $dbi->create_model(
3710
    table => $table2
3711
);
3712
$model->helper(foo => sub { shift->select(@_) });
3713
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3714

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

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

            
3735

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

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

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

            
3761
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3762
$assign_clause = $dbi->update_param($param, {no_set => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
3763
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3764
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3765
where $key1 = 1
3766
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3767
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3768
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3769
$rows   = $result->all;
3770
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3771
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3772
                  "update param no_set");
3773

            
3774
            
3775
$dbi = DBIx::Custom->connect;
3776
eval { $dbi->execute("drop table $table1") };
3777
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
3778
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
3779
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3780

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

            
3794
$param = {$key2 => 11};
3795
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3796
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3797
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3798
where $key1 = 1
3799
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3800
$dbi->execute($sql, $param, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3801
$result = $dbi->execute("select * from $table1 order by $key1");
3802
$rows   = $result->all;
3803
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3804
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3805
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3806

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3807
test 'Model class';
3808
$dbi = MyDBI1->connect;
3809
eval { $dbi->execute("drop table $table1") };
3810
$dbi->execute($create_table1);
3811
$model = $dbi->model($table1);
3812
$model->insert({$key1 => 'a', $key2 => 'b'});
3813
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3814
eval { $dbi->execute("drop table $table2") };
3815
$dbi->execute($create_table2);
3816
$model = $dbi->model($table2);
3817
$model->insert({$key1 => 'a'});
3818
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3819
is($dbi->models->{$table1}, $dbi->model($table1));
3820
is($dbi->models->{$table2}, $dbi->model($table2));
3821

            
3822
$dbi = MyDBI4->connect;
3823
eval { $dbi->execute("drop table $table1") };
3824
$dbi->execute($create_table1);
3825
$model = $dbi->model($table1);
3826
$model->insert({$key1 => 'a', $key2 => 'b'});
3827
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3828
eval { $dbi->execute("drop table $table2") };
3829
$dbi->execute($create_table2);
3830
$model = $dbi->model($table2);
3831
$model->insert({$key1 => 'a'});
3832
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3833

            
3834
$dbi = MyDBI5->connect;
3835
eval { $dbi->execute("drop table $table1") };
3836
eval { $dbi->execute("drop table $table2") };
3837
$dbi->execute($create_table1);
3838
$dbi->execute($create_table2);
3839
$model = $dbi->model($table2);
3840
$model->insert({$key1 => 'a'});
3841
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
3842
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3843
$model = $dbi->model($table1);
3844
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3845

            
3846
test 'primary_key';
3847
$dbi = MyDBI1->connect;
3848
$model = $dbi->model($table1);
3849
$model->primary_key([$key1, $key2]);
3850
is_deeply($model->primary_key, [$key1, $key2]);
3851

            
3852
test 'columns';
3853
$dbi = MyDBI1->connect;
3854
$model = $dbi->model($table1);
3855
$model->columns([$key1, $key2]);
3856
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3857

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3858
test 'setup_model';
3859
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3860
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3861
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3862
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3863

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3864
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3865
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3866
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3867
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3868
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3869

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3870
test 'each_column';
3871
$dbi = DBIx::Custom->connect;
3872
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3873
eval { $dbi->execute("drop table $table1") };
3874
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3875
eval { $dbi->execute("drop table $table3") };
3876
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3877
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3878

            
3879
$infos = [];
3880
$dbi->each_column(sub {
3881
    my ($self, $table, $column, $cinfo) = @_;
3882
    
3883
    if ($table =~ /^table\d/i) {
3884
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3885
         push @$infos, $info;
3886
    }
3887
});
3888
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3889
is_deeply($infos, 
3890
    [
3891
        [$table1, $key1, $key1],
3892
        [$table1, $key2, $key2],
3893
        [$table2, $key1, $key1],
3894
        [$table2, $key3, $key3]
3895
    ]
3896
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3897
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3898

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3906
$infos = [];
3907
$dbi->each_table(sub {
3908
    my ($self, $table, $table_info) = @_;
3909
    
3910
    if ($table =~ /^table\d/i) {
3911
         my $info = [$table, $table_info->{TABLE_NAME}];
3912
         push @$infos, $info;
3913
    }
3914
});
3915
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3916
is_deeply($infos, 
3917
    [
3918
        [$table1, $table1],
3919
        [$table2, $table2],
3920
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3921
);
3922

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3923
$dbi = DBIx::Custom->connect;
3924
eval { $dbi->execute("drop table $table1") };
3925
eval { $dbi->execute("drop table $table2") };
3926
$dbi->execute($create_table2);
3927
$dbi->execute($create_table1_type);
3928

            
3929
$infos = [];
3930
$dbi->user_table_info($user_table_info);
3931
$dbi->each_table(sub {
3932
    my ($self, $table, $table_info) = @_;
3933
    
3934
    if ($table =~ /^table\d/i) {
3935
         my $info = [$table, $table_info->{TABLE_NAME}];
3936
         push @$infos, $info;
3937
    }
3938
});
3939
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3940
is_deeply($infos, 
3941
    [
3942
        [$table1, $table1],
3943
        [$table2, $table2],
3944
        [$table3, $table3],
3945
    ]
3946
);
3947

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3948
test 'type_rule into';
3949
eval { $dbi->execute("drop table $table1") };
3950
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3951
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3952

            
3953

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3954
$dbi = DBIx::Custom->connect;
3955
eval { $dbi->execute("drop table $table1") };
3956
$dbi->execute($create_table1_type);
3957

            
cleanup
Yuki Kimoto authored on 2011-08-16
3958
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3959
$dbi->type_rule(
3960
    into1 => {
3961
        $date_typename => sub { '2010-' . $_[0] }
3962
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3963
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3964
$dbi->insert({$key1 => '01-01'}, table => $table1);
3965
$result = $dbi->select(table => $table1);
3966
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3967

            
3968
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3969
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3970
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3971
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3972
$dbi->type_rule(
3973
    into1 => [
3974
         [$date_typename, $datetime_typename] => sub {
3975
            my $value = shift;
3976
            $value =~ s/02/03/g;
3977
            return $value;
3978
         }
3979
    ]
3980
);
3981
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3982
$result = $dbi->select(table => $table1);
3983
$row = $result->one;
3984
like($row->{$key1}, qr/^2010-01-03/);
3985
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3986

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3987
$dbi = DBIx::Custom->connect;
3988
eval { $dbi->execute("drop table $table1") };
3989
$dbi->execute($create_table1_type);
3990
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3991
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3992
$dbi->type_rule(
3993
    into1 => [
3994
        [$date_typename, $datetime_typename] => sub {
3995
            my $value = shift;
3996
            $value =~ s/02/03/g;
3997
            return $value;
3998
        }
3999
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4000
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4001
$result = $dbi->execute(
4002
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
4003
    {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
4004
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4005
$row = $result->one;
4006
like($row->{$key1}, qr/^2010-01-03/);
4007
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4008

            
4009
$dbi = DBIx::Custom->connect;
4010
eval { $dbi->execute("drop table $table1") };
4011
$dbi->execute($create_table1_type);
4012
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4013
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4014
$dbi->type_rule(
4015
    into1 => [
4016
        [$date_typename, $datetime_typename] => sub {
4017
            my $value = shift;
4018
            $value =~ s/02/03/g;
4019
            return $value;
4020
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
4021
    ]
4022
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4023
$result = $dbi->execute(
4024
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
4025
    {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
cleanup test
Yuki Kimoto authored on 2011-08-15
4026
    table => $table1
4027
);
4028
$row = $result->one;
4029
like($row->{$key1}, qr/^2010-01-03/);
4030
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4031

            
4032
$dbi = DBIx::Custom->connect;
4033
eval { $dbi->execute("drop table $table1") };
4034
$dbi->execute($create_table1_type);
4035
$dbi->register_filter(convert => sub {
4036
    my $value = shift || '';
4037
    $value =~ s/02/03/;
4038
    return $value;
4039
});
cleanup
Yuki Kimoto authored on 2011-08-16
4040
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4041
$dbi->type_rule(
4042
    from1 => {
4043
        $date_datatype => 'convert',
4044
    },
4045
    into1 => {
4046
        $date_typename => 'convert',
4047
    }
4048
);
4049
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
4050
$result = $dbi->select(table => $table1);
4051
like($result->fetch->[0], qr/^2010-03-03/);
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
4052
$result = $dbi->select(column => [$key1, $key1], table => $table1);
4053
$row = $result->fetch;
4054
like($row->[0], qr/^2010-03-03/);
4055
like($row->[1], qr/^2010-03-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4056

            
4057
test 'type_rule and filter order';
4058
$dbi = DBIx::Custom->connect;
4059
eval { $dbi->execute("drop table $table1") };
4060
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4061
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4062
$dbi->type_rule(
4063
    into1 => {
4064
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4065
    },
4066
    into2 => {
4067
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4068
    },
4069
    from1 => {
4070
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4071
    },
4072
    from2 => {
4073
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
4074
    }
4075
);
4076
$dbi->insert({$key1 => '2010-01-03'}, 
4077
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
4078
$result = $dbi->select(table => $table1);
4079
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4080
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4081

            
4082

            
4083
$dbi = DBIx::Custom->connect;
4084
eval { $dbi->execute("drop table $table1") };
4085
$dbi->execute($create_table1_type);
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
$dbi->type_rule(
4088
    from1 => {
4089
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4090
    },
4091
    from2 => {
4092
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4093
    },
4094
);
4095
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4096
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4097
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4098
$result->type_rule(
4099
    from1 => {
4100
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4101
    },
4102
    from2 => {
4103
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
4104
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4105
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4106
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4107
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4108

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

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

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

            
4158
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4159
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4160
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4161
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4162
$dbi->type_rule(
4163
    from1 => {
4164
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4165
    },
4166
    into1 => {
4167
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4168
    }
4169
);
4170
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4171
$result = $dbi->select(table => $table1);
4172
like($result->fetch->[0], qr/2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4173

            
4174
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4175
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4176
$dbi->execute($create_table1_type);
4177
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
4178
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4179
$dbi->type_rule(
4180
    into1 => {
4181
        $date_typename => 'ppp'
4182
    }
4183
);
4184
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4185
$result = $dbi->select(table => $table1);
4186
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4187

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4188
eval{$dbi->type_rule(
4189
    into1 => {
4190
        $date_typename => 'pp'
4191
    }
4192
)};
4193
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4194

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4195
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4196
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4197
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4198
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
4199
    $dbi->type_rule(
4200
        from1 => {
4201
            Date => sub { $_[0] * 2 },
4202
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
4203
    );
4204
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4205
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4206

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4207
eval {
4208
    $dbi->type_rule(
4209
        into1 => {
4210
            Date => sub { $_[0] * 2 },
4211
        }
4212
    );
4213
};
4214
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4215

            
4216
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4217
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4218
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4219
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4220
$dbi->type_rule(
4221
    from1 => {
4222
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4223
    },
4224
    into1 => {
4225
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4226
    }
4227
);
4228
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4229
$result = $dbi->select(table => $table1);
4230
$result->type_rule_off;
4231
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4232

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

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

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

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

            
4282
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4283
$result = $dbi->select(table => $table1);
4284
$result->type_rule(
4285
    from1 => [$date_datatype => 'five']
4286
);
4287
$row = $result->one;
4288
like($row->{$key1}, qr/^2010-01-05/);
4289
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4290

            
4291
$result = $dbi->select(table => $table1);
4292
$result->type_rule(
4293
    from1 => [$date_datatype => undef]
4294
);
4295
$row = $result->one;
4296
like($row->{$key1}, qr/^2010-01-03/);
4297
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4298

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4313
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4314
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4315
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4316
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4317
$dbi->type_rule(
4318
    from1 => {
4319
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4320
    },
4321
);
4322
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4323
$result = $dbi->select(table => $table1);
4324
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4325
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4326

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4351
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4352
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4353
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4354
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4355
$dbi->type_rule(
4356
    into1 => {
4357
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4358
    },
4359
    into2 => {
4360
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4361
    },
4362
    from1 => {
4363
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
4364
    },
4365
    from2 => {
4366
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4367
    }
4368
);
4369
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4370
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4371
like($result->type_rule1_off->fetch_one->[0], qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4372
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4373
like($result->type_rule1_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4374

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4375
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4376
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4377
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4378
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4379
$dbi->type_rule(
4380
    into1 => {
4381
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4382
    },
4383
    into2 => {
4384
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4385
    },
4386
    from1 => {
4387
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4388
    },
4389
    from2 => {
4390
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4391
    }
4392
);
4393
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4394
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4395
like($result->type_rule2_off->fetch_one->[0], qr/^2010-01-06/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4396
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4397
like($result->type_rule2_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4398

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4399
test 'join';
4400
$dbi = DBIx::Custom->connect;
4401
eval { $dbi->execute("drop table $table1") };
4402
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4403
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4404
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4405
eval { $dbi->execute("drop table $table2") };
4406
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4407
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4408
eval { $dbi->execute("drop table $table3") };
4409
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4410
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4411
$rows = $dbi->select(
4412
    table => $table1,
4413
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4414
    where   => {"$table1.$key2" => 2},
4415
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4416
)->all;
4417
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4418

            
4419
$dbi = DBIx::Custom->connect;
4420
eval { $dbi->execute("drop table $table1") };
4421
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4422
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4423
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4424
eval { $dbi->execute("drop table $table2") };
4425
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4426
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4427
eval { $dbi->execute("drop table $table3") };
4428
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4429
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4430
$rows = $dbi->select(
4431
    table => $table1,
4432
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4433
    where   => {"$table1.$key2" => 2},
4434
    join  => {
4435
        clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4436
        table => [$table1, $table2]
4437
    }
4438
)->all;
4439
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
4440

            
4441
$rows = $dbi->select(
4442
    table => $table1,
4443
    where   => {$key1 => 1},
4444
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4445
)->all;
4446
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4447

            
4448
$rows = $dbi->select(
4449
    table => $table1,
4450
    where   => {$key1 => 1},
4451
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4452
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4453
)->all;
4454
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4455

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

            
4465
$rows = $dbi->select(
4466
    column => "$table1.$key1 as ${table1}__$key1",
4467
    table => $table1,
4468
    where   => {"$table3.$key4" => 4},
4469
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4470
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4471
)->all;
4472
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4473

            
4474
$dbi = DBIx::Custom->connect;
4475
eval { $dbi->execute("drop table $table1") };
4476
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4477
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4478
eval { $dbi->execute("drop table $table2") };
4479
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4480
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4481
$rows = $dbi->select(
4482
    table => $table1,
4483
    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",
4484
    where   => {"$table1.$key2" => 2},
4485
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4486
)->all;
4487
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4488
          'quote');
4489

            
4490

            
4491
$dbi = DBIx::Custom->connect;
4492
eval { $dbi->execute("drop table $table1") };
4493
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4494
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4495
$sql = <<"EOS";
4496
left outer join (
4497
  select * from $table1 t1
4498
  where t1.$key2 = (
4499
    select max(t2.$key2) from $table1 t2
4500
    where t1.$key1 = t2.$key1
4501
  )
4502
) $table3 on $table1.$key1 = $table3.$key1
4503
EOS
4504
$join = [$sql];
4505
$rows = $dbi->select(
4506
    table => $table1,
4507
    column => "$table3.$key1 as ${table3}__$key1",
4508
    join  => $join
4509
)->all;
4510
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4511

            
4512
$dbi = DBIx::Custom->connect;
4513
eval { $dbi->execute("drop table $table1") };
4514
eval { $dbi->execute("drop table $table2") };
4515
$dbi->execute($create_table1);
4516
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4517
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4518
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4519
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4520
$result = $dbi->select(
4521
    table => $table1,
4522
    join => [
4523
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4524
    ]
4525
);
4526
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4527
$result = $dbi->select(
4528
    table => $table1,
4529
    column => [{$table2 => [$key3]}],
4530
    join => [
4531
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4532
    ]
4533
);
4534
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4535
$result = $dbi->select(
4536
    table => $table1,
4537
    column => [{$table2 => [$key3]}],
4538
    join => [
4539
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4540
    ]
4541
);
4542
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4543

            
4544
$dbi = DBIx::Custom->connect;
4545
eval { $dbi->execute("drop table $table1") };
4546
eval { $dbi->execute("drop table $table2") };
4547
$dbi->execute($create_table1);
4548
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4549
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4550
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4551
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4552
$result = $dbi->select(
4553
    table => $table1,
4554
    column => [{$table2 => [$key3]}],
4555
    join => [
4556
        {
4557
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4558
            table => [$table1, $table2]
4559
        }
4560
    ]
4561
);
4562
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4563

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

            
4581
$dbi = DBIx::Custom->connect;
4582
eval { $dbi->execute("drop table $table1") };
4583
eval { $dbi->execute("drop table $table2") };
4584
$dbi->execute($create_table1);
4585
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4586
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4587
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4588
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4589
$result = $dbi->select(
4590
    table => $table1,
4591
    column => [{$table2 => [$key3]}],
4592
    join => [
4593
        "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4594
    ]
4595
);
4596
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4597

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4598
test 'columns';
4599
$dbi = MyDBI1->connect;
4600
$model = $dbi->model($table1);
4601

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4602
test 'count';
4603
$dbi = DBIx::Custom->connect;
4604
eval { $dbi->execute("drop table $table1") };
4605
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4606
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4607
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4608
is($dbi->count(table => $table1), 2);
4609
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4610
$model = $dbi->create_model(table => $table1);
4611
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4612

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4613
eval { $dbi->execute("drop table $table1") };
4614
eval { $dbi->execute("drop table $table2") };
4615
$dbi->execute($create_table1);
4616
$dbi->execute($create_table2);
4617
$model = $dbi->create_model(table => $table1, primary_key => $key1);
4618
$model->insert({$key1 => 1, $key2 => 2});
4619
$model = $dbi->create_model(table => $table2, primary_key => $key1,
4620
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
4621
$model->insert({$key1 => 1, $key3 => 3});
4622
is($model->count(id => 1), 1);
4623
is($model->count(where => {"$table2.$key3" => 3}), 1);
4624

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