DBIx-Custom / t / common.t /
Newer Older
4561 lines | 152.803kb
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 = {};
micro optimization
Yuki Kimoto authored on 2011-11-18
246
$DB::single = 1;
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
247
for my $i (1 .. 2) {
test cleanup
Yuki Kimoto authored on 2011-11-01
248
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, reuse => $reuse);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
249
}
250
$rows = $dbi->select(table => $table1)->all;
251
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-11-18
252
ok(keys %$reuse);
253
ok((keys %$reuse)[0] !~ /\?/);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
254

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
990

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

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

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

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

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

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

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

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

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

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

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

            
1082

            
1083
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1084
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1085
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1086
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1087
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1088
$rows = $dbi->select(table => $table1)->all;
1089
is_deeply($rows, [{$key1 => 1, $key2 => 2},
1090
                  {$key1 => 3, $key2 => 4}], "table");
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, column => [$key1])->all;
1093
is_deeply($rows, [{$key1 => 1}, {$key1 => 3}], "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, where => {$key1 => 1})->all;
1096
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table and columns and where key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1097

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

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

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

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

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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1162
test 'filters';
1163
$dbi = DBIx::Custom->new;
1164

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

            
1168
is($dbi->filters->{encode_utf8}->('あ'),
1169
   encode_utf8('あ'), "encode_utf8");
1170

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

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

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

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

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

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

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

            
1229

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

            
1235
$dbi->begin_work;
1236

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

            
1243
$dbi->rollback if $@;
1244

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

            
1249
$dbi->begin_work;
1250

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

            
1256
$dbi->commit unless $@;
1257

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

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

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

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

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

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

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

            
1314
test 'method';
- 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
    one => sub { 1 }
1317
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1318
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1319
    two => sub { 2 }
1320
);
1321
$dbi->method({
1322
    twice => sub {
1323
        my $self = shift;
1324
        return $_[0] * 2;
1325
    }
1326
});
1327

            
1328
is($dbi->one, 1, "first");
1329
is($dbi->two, 2, "second");
1330
is($dbi->twice(5), 10 , "second");
1331

            
1332
eval {$dbi->XXXXXX};
1333
ok($@, "not exists");
1334

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1678
$where = $dbi->where;
1679
is("$where", '');
1680

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1850
eval {$dbi->where(ppp => 1) };
1851
like($@, qr/invalid/);
1852

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

            
1864

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

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

            
1883
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1884
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1885
$where->param({$key1 => [undef, undef]});
1886
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
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}]);
1889
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1890
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1891
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1892

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

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

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

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

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

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

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

            
1934
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1935
like($@, qr/apply_filter/);
1936

            
1937
$dbi->apply_filter(
1938

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

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

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

            
1967
eval{DBIx::Custom->connect(dsn => undef)};
1968
like($@, qr/_connect/);
1969

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2224

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2441

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2620

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

            
2636

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

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

            
2657

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

            
2676

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

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

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

            
2716

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

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

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

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

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

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

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

            
2812

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

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

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

            
2839

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3479

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3683

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3901

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

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

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

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

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

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

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

            
4030

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4438

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

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

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

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

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

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

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

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