DBIx-Custom / t / common.t /
Newer Older
4609 lines | 154.708kb
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

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

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

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

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

            
682
$dbi->update_or_insert(
683
    {$key2 => 3},
684
    table => $table1,
685
    primary_key => $key1,
686
    id => 1
687
);
688
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
689
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
690

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
691
eval {
692
    $dbi->update_or_insert(
693
        {$key2 => 3},
694
        table => $table1,
695
    );
696
};
697

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

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

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

            
722
eval { 
723
    $affected = $dbi->update_or_insert(
724
        {},
725
        table => $table1,
726
        primary_key => $key1,
727
        id => 1
728
    );
729
};
730
is($affected, 0);
731

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1026

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
1037
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
1038
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1039
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1040
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1041
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1042
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1043
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1044
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1045

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

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

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

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

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

            
1088
test 'delete error';
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 in progress
Yuki Kimoto authored on 2011-08-15
1091
eval{$dbi->delete(table => $table1)};
cleanup
Yuki Kimoto authored on 2011-10-21
1092
like($@, qr/where/, "where key-value pairs not specified");
test cleanup
Yuki Kimoto authored on 2011-08-10
1093

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

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

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

            
1118

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

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

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

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

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

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

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

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

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
1169
eval { $dbi->execute("drop table $table1") };
1170
$dbi->execute($create_table1);
1171
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1172
$row = $dbi->select($key1, table => $table1)->one;
1173
is_deeply($row, {$key1 => 1});
1174

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1198
test 'filters';
1199
$dbi = DBIx::Custom->new;
1200

            
1201
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
1202
   'あ', "decode_utf8");
1203

            
1204
is($dbi->filters->{encode_utf8}->('あ'),
1205
   encode_utf8('あ'), "encode_utf8");
1206

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

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

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

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

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

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

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

            
1265

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1266
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1267
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1268
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1269
$dbi->execute($create_table1);
1270

            
1271
$dbi->begin_work;
1272

            
1273
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1274
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1275
    die "Error";
test cleanup
Yuki Kimoto authored on 2011-11-01
1276
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1277
};
1278

            
1279
$dbi->rollback if $@;
1280

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

            
1285
$dbi->begin_work;
1286

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

            
1292
$dbi->commit unless $@;
1293

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

            
1298
$dbi->dbh->{AutoCommit} = 0;
1299
eval{ $dbi->begin_work };
1300
ok($@, "exception");
1301
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1302

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

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

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

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

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

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

            
1364
is($dbi->one, 1, "first");
1365
is($dbi->two, 2, "second");
1366
is($dbi->twice(5), 10 , "second");
1367

            
1368
eval {$dbi->XXXXXX};
1369
ok($@, "not exists");
1370

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

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

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

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

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

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

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

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

            
1490
$result->filter({$key2 => 'twice'});
1491
$rows   = $result->all;
1492
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1493

            
1494
$result = $dbi->select(
1495
     table => [$table1, $table2],
1496
     column => [$key2, $key3],
1497
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1498

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1714
$where = $dbi->where;
1715
is("$where", '');
1716

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1886
eval {$dbi->where(ppp => 1) };
1887
like($@, qr/invalid/);
1888

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

            
1900

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

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

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

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

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

            
1939
$result = $dbi->select(
1940
    table => $table1,
1941
    where => $where
1942
);
1943
$row = $result->all;
1944
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
1945

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1946
test 'register_tag_processor';
1947
$dbi = DBIx::Custom->connect;
1948
$dbi->register_tag_processor(
1949
    a => sub { 1 }
1950
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1951
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1952

            
1953
test 'register_tag';
1954
$dbi = DBIx::Custom->connect;
1955
$dbi->register_tag(
1956
    b => sub { 2 }
1957
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1958
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1959

            
1960
test 'table not specify exception';
1961
$dbi = DBIx::Custom->connect;
1962
eval {$dbi->select};
1963
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1964

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1965
test 'more tests';
1966
$dbi = DBIx::Custom->connect;
1967
eval{$dbi->apply_filter('table', 'column', [])};
1968
like($@, qr/apply_filter/);
1969

            
1970
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1971
like($@, qr/apply_filter/);
1972

            
1973
$dbi->apply_filter(
1974

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

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

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

            
2003
eval{DBIx::Custom->connect(dsn => undef)};
2004
like($@, qr/_connect/);
2005

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

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

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

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2048
test 'option';
2049
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
2050
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
2051
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2052
ok($dbi->dbh->{PrintError});
2053
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2054
ok($dbi->dbh->{PrintError});
2055

            
2056
test 'DBIx::Custom::Result stash()';
2057
$result = DBIx::Custom::Result->new;
2058
is_deeply($result->stash, {}, 'default');
2059
$result->stash->{foo} = 1;
2060
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2061

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2062
test 'delete_at';
2063
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2064
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2065
$dbi->execute($create_table1_2);
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->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2068
    table => $table1,
2069
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2070
    where => [1, 2],
2071
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2072
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2073

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2260

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

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

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

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

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

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

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

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

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

            
2377
test 'select() param option';
2378
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2379
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2380
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2381
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2382
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2383
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2384
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2385
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
2386
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
2387
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2388
    table => $table1,
2389
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2390
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2391
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
test cleanup
Yuki Kimoto authored on 2011-08-15
2392
              " $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2393
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2394
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2395
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2396

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

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

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

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

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

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

            
2477

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2642
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2643
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2644
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2645
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2646
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2647
    {$key3 => 4},
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($dbi->select(table => $table1)->one->{$key1}, 1);
2653
is($dbi->select(table => $table1)->one->{$key2}, 2);
2654
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2655

            
2656

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

            
2672

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

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

            
2693

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

            
2712

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

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

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

            
2752

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

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

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

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

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

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

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

            
2848

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2871
test 'available_datetype';
2872
$dbi = DBIx::Custom->connect;
2873
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2874

            
2875

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

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

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

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

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

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

            
2918
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2919
    id => {key => "$table1.id"},
2920
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2921
);
2922
is_deeply($param, {"$table1.price" => undef});
2923

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

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

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

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

            
2947
$where = $dbi->where;
2948
$where->clause(['and', ":${key1}{=}"]);
2949
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->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}, {$key1 => 3, $key2 => 4}]);
2954

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3114
test 'tag_parse';
3115
$dbi = DBIx::Custom->connect;
3116
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3117
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3118
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3119
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3120
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3121
ok($@);
3122

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3268
{
3269
    $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3270
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3271
    $model->insert({$key1 => 1});
3272
    $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3273
      table => $table1, primary_key => $key1);
3274
    is($result->one->{$key1}, 1);
3275
    delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
3276
}
3277

            
3278
eval { $dbi->execute("drop table $table1") };
3279
$dbi->execute($create_table1);
3280
{
3281
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3282
    $model->insert({$key1 => 1});
3283
    eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3284
    is($result->one->{$key1}, 1);
3285
}
3286

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

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

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

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

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

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

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

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

            
3368
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3369
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3370
$rows = $result->fetch_all;
3371
is_deeply($rows, [[1, 2], [3, 4]]);
3372

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3490
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3491
    q => 'string'
3492
});
3493

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3497
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3498
   r => sub {} 
3499
});
3500

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3504
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3505
   s => sub { return ["a", ""]} 
3506
});
3507

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

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

            
3515

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

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

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

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

            
3531
test 'variouse source';
3532
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3533
$query = $builder->build_query($source);
3534
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3535

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

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

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

            
3548
$source = "a {= b} }";
3549
eval{$builder->build_query($source)};
3550
like($@, qr/unexpected "}"/, "error : 1");
3551

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

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

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

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

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

            
3621
$dbi->separator('__');
3622
$result = $model->select(
3623
    column => [
3624
        $model->column($table2, {alias => $table2_alias})
3625
    ],
3626
    where => {"$table2_alias.$key3" => 4}
3627
);
3628
is_deeply($result->one, 
3629
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3630

            
3631
$dbi->separator('-');
3632
$result = $model->select(
3633
    column => [
3634
        $model->column($table2, {alias => $table2_alias})
3635
    ],
3636
    where => {"$table2_alias.$key3" => 4}
3637
);
3638
is_deeply($result->one, 
3639
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3640

            
3641
test 'create_model';
3642
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3643
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3644
eval { $dbi->execute("drop table $table1") };
3645
eval { $dbi->execute("drop table $table2") };
3646
$dbi->execute($create_table1);
3647
$dbi->execute($create_table2);
3648

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

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

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

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

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

            
3719

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

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

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

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

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

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

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

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

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

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

            
3830
test 'primary_key';
3831
$dbi = MyDBI1->connect;
3832
$model = $dbi->model($table1);
3833
$model->primary_key([$key1, $key2]);
3834
is_deeply($model->primary_key, [$key1, $key2]);
3835

            
3836
test 'columns';
3837
$dbi = MyDBI1->connect;
3838
$model = $dbi->model($table1);
3839
$model->columns([$key1, $key2]);
3840
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3841

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3848
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3849
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3850
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3851
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3852
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3853

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3883
test 'each_table';
3884
$dbi = DBIx::Custom->connect;
3885
eval { $dbi->execute("drop table $table1") };
3886
eval { $dbi->execute("drop table $table2") };
3887
$dbi->execute($create_table2);
3888
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3889

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3932
test 'type_rule into';
3933
eval { $dbi->execute("drop table $table1") };
3934
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3935
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3936

            
3937

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3938
$dbi = DBIx::Custom->connect;
3939
eval { $dbi->execute("drop table $table1") };
3940
$dbi->execute($create_table1_type);
3941

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

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

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

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

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

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

            
4066

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4172
eval{$dbi->type_rule(
4173
    into1 => {
4174
        $date_typename => 'pp'
4175
    }
4176
)};
4177
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4178

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4425
$rows = $dbi->select(
4426
    table => $table1,
4427
    where   => {$key1 => 1},
4428
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4429
)->all;
4430
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4431

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

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

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

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

            
4474

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

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

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4582
test 'columns';
4583
$dbi = MyDBI1->connect;
4584
$model = $dbi->model($table1);
4585

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

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

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