DBIx-Custom / t / common.t /
Newer Older
4558 lines | 152.732kb
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}]);
251

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
509
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
510
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
511
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
512
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
513
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
514
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
515
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
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
Yuki Kimoto authored on 2011-11-01
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
987

            
988
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
989
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
990
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
991
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
992
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
993
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
994
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
995
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
996
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
997

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1009
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1010
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1011
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1012
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
1013
$rows = $dbi->select(table => $table1)->all;
1014
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1015

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

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

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

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

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

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

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

            
1079

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1226

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1227
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1228
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1229
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1230
$dbi->execute($create_table1);
1231

            
1232
$dbi->begin_work;
1233

            
1234
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1235
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1236
    die "Error";
test cleanup
Yuki Kimoto authored on 2011-11-01
1237
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1238
};
1239

            
1240
$dbi->rollback if $@;
1241

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

            
1246
$dbi->begin_work;
1247

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

            
1253
$dbi->commit unless $@;
1254

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1675
$where = $dbi->where;
1676
is("$where", '');
1677

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1861

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

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

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

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

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

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

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

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

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

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

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

            
1934
$dbi->apply_filter(
1935

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2070
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2071
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2072
$dbi->execute($create_table1_2);
2073
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2074
    {$key3 => 3},
2075
    primary_key => [$key1, $key2], 
2076
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2077
    where => [1, 2],
2078
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2079
is($dbi->select(table => $table1)->one->{$key1}, 1);
2080
is($dbi->select(table => $table1)->one->{$key2}, 2);
2081
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2082

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2151
$dbi->delete_all(table => $table1);
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
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2154
    table => $table1,
2155
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2156
    where => [1, 2]
2157
);
2158
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2159
is($row->{$key1}, 1);
2160
is($row->{$key2}, 2);
2161
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2162

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

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

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

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

            
2221

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2438

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2591
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2592
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2593
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2594
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2595
    table => $table1,
2596
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2597
    id => 0,
2598
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2599
is($dbi->select(table => $table1)->one->{$key1}, 0);
2600
is($dbi->select(table => $table1)->one->{$key2}, 2);
2601
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2602

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

            
2617

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

            
2633

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

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

            
2654

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

            
2673

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

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

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

            
2713

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

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

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

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

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

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

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

            
2809

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

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

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

            
2836

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3115
eval{$dbi->execute("aaa")};
cleanup test
Yuki Kimoto authored on 2011-08-15
3116
is($dbi->last_sql, 'aaa');
test cleanup
Yuki Kimoto authored on 2011-08-10
3117

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3288
eval { $dbi->execute("drop table $table1") };
3289
eval { $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->select(id => 1, query => 1);
3296
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3297
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3298
is_deeply($dbi->select(table => $table1)->one,
3299
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3300
);
3301

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

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

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

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

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

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

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

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

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3356
test 'DBIx::Custom::Result fetch_multi';
3357
eval { $dbi->execute("drop table $table1") };
3358
$dbi->execute($create_table1);
3359
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3360
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3361
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3362
$result = $dbi->select(table => $table1);
3363
$rows = $result->fetch_multi(2);
3364
is_deeply($rows, [[1, 2], [3, 4]]);
3365
$rows = $result->fetch_multi(2);
3366
is_deeply($rows, [[5, 6]]);
3367
$rows = $result->fetch_multi(2);
3368
ok(!$rows);
3369

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3476

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3680

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

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

            
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, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3707
$assign_clause = $dbi->update_param($param, {no_set => 1});
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 => 33, $key4 => 4, $key5 => 5},
3716
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3717
                  "update param no_set");
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);
test cleanup
Yuki Kimoto authored on 2011-08-10
3725

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3752
test 'Model class';
3753
$dbi = MyDBI1->connect;
3754
eval { $dbi->execute("drop table $table1") };
3755
$dbi->execute($create_table1);
3756
$model = $dbi->model($table1);
3757
$model->insert({$key1 => 'a', $key2 => 'b'});
3758
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3759
eval { $dbi->execute("drop table $table2") };
3760
$dbi->execute($create_table2);
3761
$model = $dbi->model($table2);
3762
$model->insert({$key1 => 'a'});
3763
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3764
is($dbi->models->{$table1}, $dbi->model($table1));
3765
is($dbi->models->{$table2}, $dbi->model($table2));
3766

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3898

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

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

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

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

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

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

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

            
4027

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4435

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

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

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

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

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

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

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

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