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

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

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

            
14
plan 'no_plan';
15

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

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

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

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

            
90
    use strict;
91
    use warnings;
92

            
93
    use base 'DBIx::Custom';
94

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

            
106
    package MyModel2::Base1;
107

            
108
    use strict;
109
    use warnings;
110

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

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

            
115
    use strict;
116
    use warnings;
117

            
118
    use base 'MyModel2::Base1';
119

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

            
126
    sub list { shift->select; }
127

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

            
130
    use strict;
131
    use warnings;
132

            
133
    use base 'MyModel2::Base1';
134

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

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

            
143
    package MyModel2::TABLE1;
144

            
145
    use strict;
146
    use warnings;
147

            
148
    use base 'MyModel2::Base1';
149

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

            
156
    sub list { shift->select; }
157

            
158
    package MyModel2::TABLE2;
159

            
160
    use strict;
161
    use warnings;
162

            
163
    use base 'MyModel2::Base1';
164

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

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

            
176
    use strict;
177
    use warnings;
178

            
179
    use base 'DBIx::Custom';
180

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
651
$dbi->update_or_insert(
652
    {$key2 => 3},
653
    table => $table1,
654
    primary_key => $key1,
655
    id => 1
656
);
657
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
658
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
659

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
660
eval {
661
    $dbi->update_or_insert(
662
        {$key2 => 3},
663
        table => $table1,
664
    );
665
};
666

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
669
eval {
670
    $dbi->insert({$key1 => 1}, table => $table1);
671
    $dbi->update_or_insert(
672
        {$key2 => 3},
673
        table => $table1,
674
        primary_key => $key1,
675
        id => 1
676
    );
677
};
678
like($@, qr/one/);
679

            
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
680
eval { $dbi->execute("drop table $table1") };
681
$dbi->execute($create_table1);
682
$dbi->update_or_insert(
683
    {},
684
    table => $table1,
685
    primary_key => $key1,
686
    id => 1
687
);
688
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
689
is($row->{$key1}, 1);
690

            
691
eval { 
692
    $affected = $dbi->update_or_insert(
693
        {},
694
        table => $table1,
695
        primary_key => $key1,
696
        id => 1
697
    );
698
};
699
is($affected, 0);
700

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
712
eval {
713
    $model->insert({$key1 => 1});
714
    $model->update_or_insert(
715
        {$key2 => 3},
716
        id => 1
717
    );
718
};
719
like($@, qr/one/);
720

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
995

            
996
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
997
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
998
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
999
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1000
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1001
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1002
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1003
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1004
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1005

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1017
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1018
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1019
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1020
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
1021
$rows = $dbi->select(table => $table1)->all;
1022
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1023

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

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

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

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

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

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

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

            
1087

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

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

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

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

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

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

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

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

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
1138
eval { $dbi->execute("drop table $table1") };
1139
$dbi->execute($create_table1);
1140
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1141
$row = $dbi->select($key1, table => $table1)->one;
1142
is_deeply($row, {$key1 => 1});
1143

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1167
test 'filters';
1168
$dbi = DBIx::Custom->new;
1169

            
1170
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
1171
   'あ', "decode_utf8");
1172

            
1173
is($dbi->filters->{encode_utf8}->('あ'),
1174
   encode_utf8('あ'), "encode_utf8");
1175

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

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

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

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

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

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

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

            
1234

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1235
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1236
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1237
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1238
$dbi->execute($create_table1);
1239

            
1240
$dbi->begin_work;
1241

            
1242
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1243
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1244
    die "Error";
test cleanup
Yuki Kimoto authored on 2011-11-01
1245
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1246
};
1247

            
1248
$dbi->rollback if $@;
1249

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

            
1254
$dbi->begin_work;
1255

            
1256
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1257
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1258
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1259
};
1260

            
1261
$dbi->commit unless $@;
1262

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

            
1267
$dbi->dbh->{AutoCommit} = 0;
1268
eval{ $dbi->begin_work };
1269
ok($@, "exception");
1270
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1271

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1281
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1282
$dbi->execute($create_table1);
1283
$dbi->{_cached} = {};
1284
$dbi->cache(0);
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
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1287

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

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

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

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

            
1333
is($dbi->one, 1, "first");
1334
is($dbi->two, 2, "second");
1335
is($dbi->twice(5), 10 , "second");
1336

            
1337
eval {$dbi->XXXXXX};
1338
ok($@, "not exists");
1339

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

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

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

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

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

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

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

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

            
1459
$result->filter({$key2 => 'twice'});
1460
$rows   = $result->all;
1461
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1462

            
1463
$result = $dbi->select(
1464
     table => [$table1, $table2],
1465
     column => [$key2, $key3],
1466
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1467

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1673
eval {
1674
$where = $dbi->where
1675
             ->clause(['uuu']);
1676
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1677
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1678
    where => $where
1679
);
1680
};
1681
ok($@);
1682

            
1683
$where = $dbi->where;
1684
is("$where", '');
1685

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1846
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1847
             ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1848
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1849
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1850
    where => $where,
1851
);
1852
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1853
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1854

            
1855
eval {$dbi->where(ppp => 1) };
1856
like($@, qr/invalid/);
1857

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

            
1869

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

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

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

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

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

            
1908
$result = $dbi->select(
1909
    table => $table1,
1910
    where => $where
1911
);
1912
$row = $result->all;
1913
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
1914

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

            
1922
test 'register_tag';
1923
$dbi = DBIx::Custom->connect;
1924
$dbi->register_tag(
1925
    b => sub { 2 }
1926
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1927
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1928

            
1929
test 'table not specify exception';
1930
$dbi = DBIx::Custom->connect;
1931
eval {$dbi->select};
1932
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1933

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1934
test 'more tests';
1935
$dbi = DBIx::Custom->connect;
1936
eval{$dbi->apply_filter('table', 'column', [])};
1937
like($@, qr/apply_filter/);
1938

            
1939
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1940
like($@, qr/apply_filter/);
1941

            
1942
$dbi->apply_filter(
1943

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

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

            
1964
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1965
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1966
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1967
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1968
like($@, qr/not registered/);
1969
$dbi->method({one => sub { 1 }});
1970
is($dbi->one, 1);
1971

            
1972
eval{DBIx::Custom->connect(dsn => undef)};
1973
like($@, qr/_connect/);
1974

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

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

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

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2017
test 'option';
2018
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
2019
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
2020
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2021
ok($dbi->dbh->{PrintError});
2022
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2023
ok($dbi->dbh->{PrintError});
2024

            
2025
test 'DBIx::Custom::Result stash()';
2026
$result = DBIx::Custom::Result->new;
2027
is_deeply($result->stash, {}, 'default');
2028
$result->stash->{foo} = 1;
2029
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2030

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

            
cleanup
Yuki Kimoto authored on 2011-11-01
2043
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2044
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2045
    table => $table1,
2046
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2047
    where => 1,
2048
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2049
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2050

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2065
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2066
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2067
$dbi->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2068
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2069
    primary_key => $key1, 
2070
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2071
    where => 1,
2072
);
2073

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2106
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2107
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2108
$dbi->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2109
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2110
    table => $table1,
2111
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2112
    where => 1,
2113
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2114
is($dbi->select(table => $table1)->one->{$key1}, 1);
2115
is($dbi->select(table => $table1)->one->{$key2}, 2);
2116
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2117

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

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

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

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

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

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

            
2203
test 'model update_at';
2204
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2205
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2206
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2207
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2208
$dbi->model($table1)->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2209
    {$key3 => 4},
cleanup test
Yuki Kimoto authored on 2011-08-10
2210
    where => [1, 2],
2211
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2212
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
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}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2217

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

            
2229

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

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

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

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

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

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

            
2320
$result = $model->select_at(
2321
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2322
        $model->mycolumn([$key1]),
2323
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2324
    ]
2325
);
2326
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2327
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2328

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2329
test 'merge_param';
2330
$dbi = DBIx::Custom->new;
2331
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2332
    {$key1 => 1, $key2 => 2, $key3 => 3},
2333
    {$key1 => 1, $key2 => 2},
2334
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2335
];
2336
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2337
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2338

            
2339
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2340
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2341
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2342
];
2343
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2344
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
2345

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2376
test 'select() string where';
2377
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2378
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2379
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2380
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2381
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2382
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2383
    table => $table1,
2384
    where => "$key1 = :$key1 and $key2 = :$key2",
2385
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2386
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2387
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2388

            
2389
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2390
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2391
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2392
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2393
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2394
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2395
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2396
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2397
        "$key1 = :$key1 and $key2 = :$key2",
2398
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2399
    ]
2400
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2401
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2402

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

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

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

            
2446

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2490
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2491
$dbi->insert(
cleanup
Yuki Kimoto authored on 2011-11-01
2492
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2493
    primary_key => $key1, 
2494
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2495
    id => 0,
2496
);
2497

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

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

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

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

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

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

            
2571
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2572
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2573
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2574
$dbi->model($table1)->insert(
2575
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2576
    id => [1, 2]
2577
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2578
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2579
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2580
is($row->{$key1}, 1);
2581
is($row->{$key2}, 2);
2582
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2583

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2599
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2600
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2601
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2602
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2603
    table => $table1,
2604
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2605
    id => 0,
2606
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2607
is($dbi->select(table => $table1)->one->{$key1}, 0);
2608
is($dbi->select(table => $table1)->one->{$key2}, 2);
2609
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2610

            
2611
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2612
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2613
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2614
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2615
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2616
    {$key3 => 4},
2617
    table => $table1,
2618
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2619
    id => [1, 2]
2620
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2621
is($dbi->select(table => $table1)->one->{$key1}, 1);
2622
is($dbi->select(table => $table1)->one->{$key2}, 2);
2623
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2624

            
2625

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

            
2641

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

            
cleanup
Yuki Kimoto authored on 2011-11-01
2654
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2655
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2656
    table => $table1,
2657
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2658
    id => 0,
2659
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2660
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2661

            
2662

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

            
2681

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

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

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

            
2721

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

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

            
2751
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2752
    column => [$model->column($table2 => [$key1, $key3])],
2753
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2754
);
2755
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2756
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2757

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2758
test 'separator';
2759
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2760
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2761
eval { $dbi->execute("drop table $table1") };
2762
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2763
$dbi->execute($create_table1);
2764
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2765

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

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

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

            
2817

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2818
test 'filter_off';
2819
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2820
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2821
eval { $dbi->execute("drop table $table1") };
2822
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2823
$dbi->execute($create_table1);
2824
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2825

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2840
test 'available_datetype';
2841
$dbi = DBIx::Custom->connect;
2842
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2843

            
2844

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

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

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

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

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

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

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

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

            
2899
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2900
    id => {key => "$table1.id"},
added tests
Yuki Kimoto authored on 2011-08-26
2901
    price => ["$table1.price", sub { '%' . $_[0] }]
2902
);
2903
is_deeply($param, {"$table1.price" => '%a'});
2904

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2905
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2906
    price => sub { '%' . $_[0] },
2907
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2908
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2909
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2910

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

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

            
2924
$where = $dbi->where;
2925
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2926
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
2927
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2928
$row = $result->all;
2929
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2930
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2931
$row = $result->all;
2932
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2933

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

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

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

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

            
2963
$where = $dbi->where;
2964
$where->clause(['and', ":${key1}{=}"]);
2965
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
2966
  ->pass([$key1, $key2])->map;
2967
$where->param($param);
2968
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2969
$row = $result->all;
2970
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2971

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3116
test 'last_sql';
3117
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3118
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3119
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3120
$dbi->execute("select * from $table1");
micro optimization
Yuki Kimoto authored on 2011-11-18
3121
is($dbi->last_sql, " select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3122

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

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

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

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

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

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

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

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

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

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

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

            
3237
{
3238
    $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3239
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3240
    $model->insert({$key1 => 1});
3241
    $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3242
      table => $table1, primary_key => $key1);
3243
    is($result->one->{$key1}, 1);
3244
    delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
3245
}
3246

            
3247
eval { $dbi->execute("drop table $table1") };
3248
$dbi->execute($create_table1);
3249
{
3250
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3251
    $model->insert({$key1 => 1});
3252
    eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3253
    is($result->one->{$key1}, 1);
3254
}
3255

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3317
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3318
@rows = ();
3319
while (my $row = $result->fetch) {
3320
    push @rows, [@$row];
3321
}
3322
is_deeply(\@rows, [[1, 2], [3, 4]]);
3323

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3324
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3325
@rows = ();
3326
while (my $row = $result->fetch_hash) {
3327
    push @rows, {%$row};
3328
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3329
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3330

            
3331
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3332
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3333
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3334
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3335
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3336

            
3337
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3338
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3339
$rows = $result->fetch_all;
3340
is_deeply($rows, [[1, 2], [3, 4]]);
3341

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3346
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3347
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3348
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3349
$rows = $result->fetch_all;
3350
is_deeply($rows, [[3, 2], [9, 4]], "array");
3351

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

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3364
test 'DBIx::Custom::Result fetch_multi';
3365
eval { $dbi->execute("drop table $table1") };
3366
$dbi->execute($create_table1);
3367
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3368
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3369
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3370
$result = $dbi->select(table => $table1);
3371
$rows = $result->fetch_multi(2);
3372
is_deeply($rows, [[1, 2], [3, 4]]);
3373
$rows = $result->fetch_multi(2);
3374
is_deeply($rows, [[5, 6]]);
3375
$rows = $result->fetch_multi(2);
3376
ok(!$rows);
3377

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3459
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3460
    q => 'string'
3461
});
3462

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3466
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3467
   r => sub {} 
3468
});
3469

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3480
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3481
    t => sub {return ["a", []]}
3482
);
3483

            
3484

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

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

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

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

            
3500
test 'variouse source';
3501
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3502
$query = $builder->build_query($source);
3503
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3504

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

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

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

            
3517
$source = "a {= b} }";
3518
eval{$builder->build_query($source)};
3519
like($@, qr/unexpected "}"/, "error : 1");
3520

            
3521
$source = "a {= {}";
3522
eval{$builder->build_query($source)};
3523
like($@, qr/unexpected "{"/, "error : 2");
3524

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3561
test 'dbi method from model';
3562
$dbi = MyDBI9->connect;
3563
eval { $dbi->execute("drop table $table1") };
3564
$dbi->execute($create_table1);
3565
$dbi->setup_model;
3566
$model = $dbi->model($table1);
3567
eval{$model->execute("select * from $table1")};
3568
ok(!$@);
3569

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

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

            
3600
$dbi->separator('-');
3601
$result = $model->select(
3602
    column => [
3603
        $model->column($table2, {alias => $table2_alias})
3604
    ],
3605
    where => {"$table2_alias.$key3" => 4}
3606
);
3607
is_deeply($result->one, 
3608
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3609

            
3610
test 'create_model';
3611
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3612
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3613
eval { $dbi->execute("drop table $table1") };
3614
eval { $dbi->execute("drop table $table2") };
3615
$dbi->execute($create_table1);
3616
$dbi->execute($create_table2);
3617

            
3618
$dbi->create_model(
3619
    table => $table1,
3620
    join => [
3621
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3622
    ],
3623
    primary_key => [$key1]
3624
);
3625
$model2 = $dbi->create_model(
3626
    table => $table2
3627
);
3628
$dbi->create_model(
3629
    table => $table3,
3630
    filter => [
3631
        $key1 => {in => sub { uc $_[0] }}
3632
    ]
3633
);
3634
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3635
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3636
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3637
$model = $dbi->model($table1);
3638
$result = $model->select(
3639
    column => [$model->mycolumn, $model->column($table2)],
3640
    where => {"$table1.$key1" => 1}
3641
);
3642
is_deeply($result->one,
3643
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3644
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3645

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

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

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

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

            
3688

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

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3760
test 'Model class';
3761
$dbi = MyDBI1->connect;
3762
eval { $dbi->execute("drop table $table1") };
3763
$dbi->execute($create_table1);
3764
$model = $dbi->model($table1);
3765
$model->insert({$key1 => 'a', $key2 => 'b'});
3766
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3767
eval { $dbi->execute("drop table $table2") };
3768
$dbi->execute($create_table2);
3769
$model = $dbi->model($table2);
3770
$model->insert({$key1 => 'a'});
3771
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3772
is($dbi->models->{$table1}, $dbi->model($table1));
3773
is($dbi->models->{$table2}, $dbi->model($table2));
3774

            
3775
$dbi = MyDBI4->connect;
3776
eval { $dbi->execute("drop table $table1") };
3777
$dbi->execute($create_table1);
3778
$model = $dbi->model($table1);
3779
$model->insert({$key1 => 'a', $key2 => 'b'});
3780
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3781
eval { $dbi->execute("drop table $table2") };
3782
$dbi->execute($create_table2);
3783
$model = $dbi->model($table2);
3784
$model->insert({$key1 => 'a'});
3785
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3786

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

            
3799
test 'primary_key';
3800
$dbi = MyDBI1->connect;
3801
$model = $dbi->model($table1);
3802
$model->primary_key([$key1, $key2]);
3803
is_deeply($model->primary_key, [$key1, $key2]);
3804

            
3805
test 'columns';
3806
$dbi = MyDBI1->connect;
3807
$model = $dbi->model($table1);
3808
$model->columns([$key1, $key2]);
3809
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3810

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3811
test 'setup_model';
3812
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3813
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3814
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3815
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3816

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3817
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3818
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3819
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3820
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3821
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3822

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3823
test 'each_column';
3824
$dbi = DBIx::Custom->connect;
3825
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3826
eval { $dbi->execute("drop table $table1") };
3827
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3828
eval { $dbi->execute("drop table $table3") };
3829
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3830
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3831

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3852
test 'each_table';
3853
$dbi = DBIx::Custom->connect;
3854
eval { $dbi->execute("drop table $table1") };
3855
eval { $dbi->execute("drop table $table2") };
3856
$dbi->execute($create_table2);
3857
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3858

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

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3876
$dbi = DBIx::Custom->connect;
3877
eval { $dbi->execute("drop table $table1") };
3878
eval { $dbi->execute("drop table $table2") };
3879
$dbi->execute($create_table2);
3880
$dbi->execute($create_table1_type);
3881

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3901
test 'type_rule into';
3902
eval { $dbi->execute("drop table $table1") };
3903
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3904
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3905

            
3906

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3907
$dbi = DBIx::Custom->connect;
3908
eval { $dbi->execute("drop table $table1") };
3909
$dbi->execute($create_table1_type);
3910

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

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

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

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

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

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

            
4035

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4141
eval{$dbi->type_rule(
4142
    into1 => {
4143
        $date_typename => 'pp'
4144
    }
4145
)};
4146
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4147

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4160
eval {
4161
    $dbi->type_rule(
4162
        into1 => {
4163
            Date => sub { $_[0] * 2 },
4164
        }
4165
    );
4166
};
4167
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4168

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

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

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

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

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

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

            
4244
$result = $dbi->select(table => $table1);
4245
$result->type_rule(
4246
    from1 => [$date_datatype => undef]
4247
);
4248
$row = $result->one;
4249
like($row->{$key1}, qr/^2010-01-03/);
4250
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4251

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4266
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4267
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4268
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4269
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4270
$dbi->type_rule(
4271
    from1 => {
4272
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4273
    },
4274
);
4275
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4276
$result = $dbi->select(table => $table1);
4277
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4278
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4279

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

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

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

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

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

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

            
4401
$rows = $dbi->select(
4402
    table => $table1,
4403
    where   => {$key1 => 1},
4404
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4405
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4406
)->all;
4407
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4408

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

            
4418
$rows = $dbi->select(
4419
    column => "$table1.$key1 as ${table1}__$key1",
4420
    table => $table1,
4421
    where   => {"$table3.$key4" => 4},
4422
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4423
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4424
)->all;
4425
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4426

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

            
4443

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

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

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4551
test 'columns';
4552
$dbi = MyDBI1->connect;
4553
$model = $dbi->model($table1);
4554

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

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4566
eval { $dbi->execute("drop table $table1") };
4567
eval { $dbi->execute("drop table $table2") };
4568
$dbi->execute($create_table1);
4569
$dbi->execute($create_table2);
4570
$model = $dbi->create_model(table => $table1, primary_key => $key1);
4571
$model->insert({$key1 => 1, $key2 => 2});
4572
$model = $dbi->create_model(table => $table2, primary_key => $key1,
4573
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
4574
$model->insert({$key1 => 1, $key3 => 3});
4575
is($model->count(id => 1), 1);
4576
is($model->count(where => {"$table2.$key3" => 3}), 1);
4577

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