DBIx-Custom / t / common.t /
Newer Older
4528 lines | 151.974kb
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;
cleanup test
Yuki Kimoto authored on 2011-08-15
84

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

            
89
    use strict;
90
    use warnings;
91

            
92
    use base 'DBIx::Custom';
93

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

            
105
    package MyModel2::Base1;
106

            
107
    use strict;
108
    use warnings;
109

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

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

            
114
    use strict;
115
    use warnings;
116

            
117
    use base 'MyModel2::Base1';
118

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

            
125
    sub list { shift->select; }
126

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

            
129
    use strict;
130
    use warnings;
131

            
132
    use base 'MyModel2::Base1';
133

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

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

            
142
    package MyModel2::TABLE1;
143

            
144
    use strict;
145
    use warnings;
146

            
147
    use base 'MyModel2::Base1';
148

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

            
155
    sub list { shift->select; }
156

            
157
    package MyModel2::TABLE2;
158

            
159
    use strict;
160
    use warnings;
161

            
162
    use base 'MyModel2::Base1';
163

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

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

            
175
    use strict;
176
    use warnings;
177

            
178
    use base 'DBIx::Custom';
179

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
269
test 'DBIx::Custom::Result test';
270
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
271
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
272
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
273
$source = "select $key1, $key2 from $table1";
274
$query = $dbi->create_query($source);
275
$result = $dbi->execute($query);
cleanup
Yuki Kimoto authored on 2011-08-15
276

            
cleanup test
Yuki Kimoto authored on 2011-08-15
277
@rows = ();
278
while (my $row = $result->fetch) {
279
    push @rows, [@$row];
280
}
281
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
cleanup
Yuki Kimoto authored on 2011-08-15
282

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
298
test 'Insert query return value';
299
$source = "insert into $table1 {insert_param $key1 $key2}";
300
$query = $dbi->execute($source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
301
$ret_val = $dbi->execute($query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
302
ok($ret_val);
test cleanup
Yuki Kimoto authored on 2011-08-10
303

            
cleanup test
Yuki Kimoto authored on 2011-08-15
304
test 'Direct query';
305
$dbi->delete_all(table => $table1);
306
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
test cleanup
Yuki Kimoto authored on 2011-11-01
307
$dbi->execute($insert_source, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
308
$result = $dbi->execute("select * from $table1");
309
$rows = $result->all;
310
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
311

            
312
test 'Filter basic';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
313
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-08
314
$dbi->register_filter(twice       => sub { $_[0] * 2}, 
315
                    three_times => sub { $_[0] * 3});
316

            
cleanup test
Yuki Kimoto authored on 2011-08-15
317
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
318
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
319
$insert_query->filter({$key1 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
320
$dbi->execute($insert_query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
321
$result = $dbi->execute("select * from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
322
$rows = $result->filter({$key2 => 'three_times'})->all;
323
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
324

            
325
test 'Filter in';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
326
$dbi->delete_all(table => $table1);
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
Yuki Kimoto authored on 2011-11-01
329
$dbi->execute($insert_query, {$key1 => 2, $key2 => 4});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
330
$select_source = "select * from $table1 where {in $table1.$key1 2} and {in $table1.$key2 2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
331
$select_query = $dbi->execute($select_source,{}, query => 1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
332
$select_query->filter({"$table1.$key1" => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
333
$result = $dbi->execute($select_query, {"$table1.$key1" => [1,5], "$table1.$key2" => [2,4]});
cleanup test
Yuki Kimoto authored on 2011-08-08
334
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
335
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
336

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
407
$source = "select * from $table1 where $key1 = \n:$key1\n and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-11-01
408
$result = $dbi->execute($source, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-08
409
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
410
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
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 or $key1 = :$key1";
test cleanup
Yuki Kimoto authored on 2011-11-01
413
$result = $dbi->execute($source, {$key1 => [1, 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 = :$table1.$key1 and $key2 = :$table1.$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
418
$result = $dbi->execute(
419
    $source,
test cleanup
Yuki Kimoto authored on 2011-11-01
420
    {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
421
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
cleanup test
Yuki Kimoto authored on 2011-08-08
422
);
423
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
424
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
425

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
439
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
440
$dbi->insert({$key1 => 'a:b c:d', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
441
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
442
$result = $dbi->execute(
443
    $source,
test cleanup
Yuki Kimoto authored on 2011-11-01
444
    {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
445
);
446
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
447
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
448

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

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

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

            
added tests
Yuki Kimoto authored on 2011-11-01
465
eval { $dbi->execute("drop table $table1") };
466
$dbi->execute($create_table1);
467
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
468
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
469
$result = $dbi->execute("select * from $table1");
470
$rows   = $result->all;
471
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
472

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
494
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
495
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
496
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
test cleanup
Yuki Kimoto authored on 2011-11-01
497
$dbi->insert({select => 1}, table => 'table');
cleanup test
Yuki Kimoto authored on 2011-08-10
498
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
499
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
500
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
cleanup test
Yuki Kimoto authored on 2011-08-10
501

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
502
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
503
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
504
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
505
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
506
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
507
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
508
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
509

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

            
updated pod
Yuki Kimoto authored on 2011-09-02
518
eval { $dbi->execute("drop table $table1") };
519
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
520
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
updated pod
Yuki Kimoto authored on 2011-09-02
521
  wrap => {$key1 => sub { "$_[0] - 1" }});
test cleanup
Yuki Kimoto authored on 2011-11-01
522
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
updated pod
Yuki Kimoto authored on 2011-09-02
523
$result = $dbi->execute("select * from $table1");
524
$rows   = $result->all;
525
is_deeply($rows, [{$key1 => 0, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
526

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

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

            
547
eval { $dbi->execute("drop table $table1") };
548
$dbi->execute($create_table1);
549
$dbi->insert_timestamp(
550
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
551
);
552
$dbi->insert(table => $table1, timestamp => 1);
553
$result = $dbi->execute("select * from $table1");
554
$rows   = $result->all;
555
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
556

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

            
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, updated_at => $key3);
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->{$key3}, 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, created_at => $key2, 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->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
586
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
587
is($row->{$key2}, $row->{$key3});
588

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

            
600
eval { $dbi->execute("drop table $table1") };
601
$dbi->execute($create_table1_2);
602
$param = {$key1 => 1};
603
$model = $dbi->create_model(table => $table1, updated_at => $key3);
604
$model->insert($param);
605
$result = $dbi->select(table => $table1);
606
is_deeply($param, {$key1 => 1});
607
$row   = $result->one;
608
is($row->{$key1}, 1);
609
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
610

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
624
test 'update_or_insert';
625
eval { $dbi->execute("drop table $table1") };
626
$dbi->execute($create_table1);
627
$dbi->update_or_insert(
628
    {$key2 => 2},
629
    table => $table1,
630
    primary_key => $key1,
631
    id => 1
632
);
633
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
634
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
635

            
636
$dbi->update_or_insert(
637
    {$key2 => 3},
638
    table => $table1,
639
    primary_key => $key1,
640
    id => 1
641
);
642
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
643
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
644

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
645
eval {
646
    $dbi->update_or_insert(
647
        {$key2 => 3},
648
        table => $table1,
649
    );
650
};
651

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
654
eval {
655
    $dbi->insert({$key1 => 1}, table => $table1);
656
    $dbi->update_or_insert(
657
        {$key2 => 3},
658
        table => $table1,
659
        primary_key => $key1,
660
        id => 1
661
    );
662
};
663
like($@, qr/one/);
664

            
micro optimization
Yuki Kimoto authored on 2011-10-31
665
test 'model update_or_insert';
666
eval { $dbi->execute("drop table $table1") };
667
$dbi->execute($create_table1);
668
$model = $dbi->create_model(
669
    table => $table1,
670
    primary_key => $key1
671
);
672
$model->update_or_insert({$key2 => 2}, id => 1);
673
$row = $model->select(id => 1)->one;
674
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
675

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
676
eval {
677
    $model->insert({$key1 => 1});
678
    $model->update_or_insert(
679
        {$key2 => 3},
680
        id => 1
681
    );
682
};
683
like($@, qr/one/);
684

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
685
test 'default_bind_filter';
686
$dbi->execute("delete from $table1");
687
$dbi->register_filter(
688
    twice       => sub { $_[0] * 2 },
689
    three_times => sub { $_[0] * 3 }
690
);
691
$dbi->default_bind_filter('twice');
cleanup
Yuki Kimoto authored on 2011-11-01
692
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
693
$result = $dbi->execute("select * from $table1");
694
$rows   = $result->all;
695
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
696
$dbi->default_bind_filter(undef);
697

            
test cleanup
Yuki Kimoto authored on 2011-08-10
698
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
699
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
700
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
701
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
702
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
703
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
704
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
705
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
706
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
707
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
708
                  "basic");
added tests
Yuki Kimoto authored on 2011-11-01
709

            
710
eval { $dbi->execute("drop table $table1") };
711
$dbi->execute($create_table1_2);
712
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
713
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
714
$dbi->update(param => {$key2 => 11}, table => $table1, where => {$key1 => 1});
715
$result = $dbi->execute("select * from $table1 order by $key1");
716
$rows   = $result->all;
717
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
718
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
719
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
720
                  
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
721
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
722
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
723
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
724
$dbi->update({$key2 => 12}, table => $table1, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
725
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
726
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
727
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
728
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
729
                  "update key same as search key");
730

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
738
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
739
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
740
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
741
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
742
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
743
              filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
744
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
745
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
746
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
747
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
748
                  "filter");
749

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
755
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
756
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
757
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
758
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
759
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
760
$where->param({$key1 => 1, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
761
$dbi->update({$key1 => 3}, table => $table1, where => $where);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
762
$result = $dbi->select(table => $table1);
763
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
764

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
765
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
766
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
767
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
768
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
769
    {$key1 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
770
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
771
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
772
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
773
        {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
774
    ]
775
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
776
$result = $dbi->select(table => $table1);
777
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
778

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
795
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
796
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
797
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
798
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
799
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
800
$dbi->insert({select => 1}, table => 'table');
801
$dbi->update({update => 2}, table => 'table', where => {select => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
802
$result = $dbi->execute("select * from ${q}table$p");
803
$rows   = $result->all;
804
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
805

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

            
809
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
810
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
811
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
812
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
813
$dbi->insert({select => 1}, table => 'table');
814
$dbi->update({update => 2}, table => 'table', where => {'table.select' => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
815
$result = $dbi->execute("select * from ${q}table$p");
816
$rows   = $result->all;
817
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
818

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
819
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
820
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
821
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
822
$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
823
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
824
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
825
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
826
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
827
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
828
                  "basic");
829

            
updated pod
Yuki Kimoto authored on 2011-09-02
830
eval { $dbi->execute("drop table $table1") };
831
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
832
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
833
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
834
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
updated pod
Yuki Kimoto authored on 2011-09-02
835
wrap => {$key2 => sub { "$_[0] - 1" }});
836
$result = $dbi->execute("select * from $table1 order by $key1");
837
$rows   = $result->all;
838
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5},
839
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
840
                  "basic");
841

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

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
853
eval { $dbi->execute("drop table $table1") };
854
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
855
$dbi->update_timestamp(
856
    $key1 => '5'
857
);
test cleanup
Yuki Kimoto authored on 2011-11-01
858
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
859
$dbi->update(table => $table1, timestamp => 1, where => {$key2 => 2});
860
$result = $dbi->execute("select * from $table1");
861
$rows   = $result->all;
862
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
863

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
864
eval { $dbi->execute("drop table $table1") };
865
$dbi->execute($create_table1);
866
$dbi->update_timestamp(
867
    [$key1, $key2] => sub { '5' }
868
);
test cleanup
Yuki Kimoto authored on 2011-11-01
869
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
870
$dbi->update_all(table => $table1, timestamp => 1);
871
$result = $dbi->execute("select * from $table1");
872
$rows   = $result->all;
873
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
874

            
875
eval { $dbi->execute("drop table $table1") };
876
$dbi->execute($create_table1);
877
$dbi->update_timestamp(
878
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
879
);
test cleanup
Yuki Kimoto authored on 2011-11-01
880
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
881
$dbi->update_all(table => $table1, timestamp => 1);
882
$result = $dbi->execute("select * from $table1");
883
$rows   = $result->all;
884
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
885

            
micro optimization and
Yuki Kimoto authored on 2011-10-25
886
eval { $dbi->execute("drop table $table1") };
887
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
888
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
889
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
890
$param = {$key2 => 11};
891
$dbi->update($param, table => $table1, where => {$key1 => 1});
892
is_deeply($param, {$key2 => 11});
893
$result = $dbi->execute("select * from $table1 order by $key1");
894
$rows   = $result->all;
895
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
896
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
897
                  "basic");
898

            
899
eval { $dbi->execute("drop table $table1") };
900
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
901
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
902
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
903
$param = {$key2 => 11};
904
$dbi->update($param, table => $table1, where => {$key2 => 2});
905
is_deeply($param, {$key2 => 11});
906
$result = $dbi->execute("select * from $table1 order by $key1");
907
$rows   = $result->all;
908
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
909
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
910
                  "basic");
911

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
912
eval { $dbi->execute("drop table $table1") };
913
$dbi->execute($create_table1_2);
914
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
915
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
916
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key1 => 1});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
917
$result = $dbi->select(table => $table1);
918
is_deeply($param, {$key3 => 4});
919
$row   = $result->one;
920
is($row->{$key3}, 4);
921
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
922

            
923
eval { $dbi->execute("drop table $table1") };
924
$dbi->execute($create_table1_2);
925
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
926
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
927
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key3 => 3});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
928
$result = $dbi->select(table => $table1);
929
is_deeply($param, {$key3 => 4});
930
$row   = $result->one;
931
is($row->{$key3}, 4);
932
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
933

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
934
eval { $dbi->execute("drop table $table1") };
935
$dbi->execute($create_table1_2);
936
$model = $dbi->create_model(table => $table1, updated_at => $key2);
937
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
938
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
939
$model->update($param, where => {$key1 => 1});
940
$result = $dbi->select(table => $table1);
941
is_deeply($param, {$key3 => 4});
942
$row   = $result->one;
943
is($row->{$key3}, 4);
944
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
945

            
test cleanup
Yuki Kimoto authored on 2011-08-10
946
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
947
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
948
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
949
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
950
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
951
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
952
$dbi->update_all({$key2 => 10}, table => $table1, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
953
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
954
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
955
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
956
                  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
957
                  "filter");
958

            
959

            
960
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
961
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
962
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
963
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
964
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
965
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
966
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
967
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
968
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
969

            
cleanup test
Yuki Kimoto authored on 2011-08-15
970
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
971
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
972
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
973
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
974
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
975
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
976
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
977
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
978

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
981
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
982
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
983
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
984
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
985
$rows = $dbi->select(table => $table1)->all;
986
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
987

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
999
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1000
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1001
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1002
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1003
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1004
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1005
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1006
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
1007
        {ke1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
1008
    ]
1009
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1010
$result = $dbi->select(table => $table1);
1011
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1012

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1013
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1014
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1015
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1016
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
1017
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1018
$rows   = $result->all;
1019
is_deeply($rows, [], "basic");
1020

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1030
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
1031
$dbi = DBIx::Custom->connect;
1032
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1033
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1034
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1035
$dbi->insert({select => 1}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1036
$dbi->delete(table => 'table', where => {select => 1});
1037
$result = $dbi->execute("select * from ${q}table$p");
1038
$rows   = $result->all;
1039
is_deeply($rows, [], "reserved word");
1040

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

            
1051

            
1052
test 'select';
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
Yuki Kimoto authored on 2011-11-01
1055
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1056
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1057
$rows = $dbi->select(table => $table1)->all;
1058
is_deeply($rows, [{$key1 => 1, $key2 => 2},
1059
                  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
1060

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1075
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1076
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
1077
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1078
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1079
    table => [$table1, $table2],
1080
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
1081
    where   => {"$table1.$key2" => 2},
1082
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1083
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1084
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
1085

            
1086
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1087
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1088
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1089
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1090
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1091
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
1092

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

            
1102
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1103
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1104
$dbi->register_filter(
1105
    twice       => sub { $_[0] * 2 },
1106
    three_times => sub { $_[0] * 3 }
1107
);
1108
$dbi->default_fetch_filter('twice');
1109
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1110
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1111
$result = $dbi->select(table => $table1);
1112
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1113
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1114
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1115

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1116
$dbi->default_fetch_filter('twice');
1117
eval { $dbi->execute("drop table $table1") };
1118
$dbi->execute($create_table1);
1119
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1120
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1121
$result->filter({$key1 => 'three_times'});
1122
$row = $result->fetch_first;
1123
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter");
1124

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1125
test 'filters';
1126
$dbi = DBIx::Custom->new;
1127

            
1128
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
1129
   'あ', "decode_utf8");
1130

            
1131
is($dbi->filters->{encode_utf8}->('あ'),
1132
   encode_utf8('あ'), "encode_utf8");
1133

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1134
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1135
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1136
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1137
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1138
$dbi->begin_work;
1139
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1140
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1141
$dbi->rollback;
1142
$dbi->dbh->{AutoCommit} = 1;
1143

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

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

            
1148
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1149
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1150
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1151
$dbi->begin_work;
1152
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1153
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1154
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1155
$dbi->commit;
1156
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1157
$result = $dbi->select(table => $table1);
1158
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1159
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1160

            
1161
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1162
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1163
$dbi->execute($create_table1);
1164
{
1165
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1166
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1167
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1168
    like($@, qr/\.t /, "fail : not verbose");
1169
}
1170
{
1171
    local $Carp::Verbose = 1;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1172
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1173
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1174
}
1175

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

            
1181
{
1182
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1183
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1184
    like($@, qr/\Q.t /, "caller spec : not vebose");
1185
}
1186
{
1187
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1188
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1189
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1190
}
1191

            
1192

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1193
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1194
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1195
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1196
$dbi->execute($create_table1);
1197

            
1198
$dbi->begin_work;
1199

            
1200
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1201
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1202
    die "Error";
test cleanup
Yuki Kimoto authored on 2011-11-01
1203
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1204
};
1205

            
1206
$dbi->rollback if $@;
1207

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

            
1212
$dbi->begin_work;
1213

            
1214
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1215
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1216
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1217
};
1218

            
1219
$dbi->commit unless $@;
1220

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

            
1225
$dbi->dbh->{AutoCommit} = 0;
1226
eval{ $dbi->begin_work };
1227
ok($@, "exception");
1228
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1229

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1230
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1231
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1232
$dbi->cache(1);
1233
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1234
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1235
$dbi->execute($source, {}, query => 1);
1236
is_deeply($dbi->{_cached}->{$source}, 
cleanup test
Yuki Kimoto authored on 2011-08-15
1237
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1238

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1239
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1240
$dbi->execute($create_table1);
1241
$dbi->{_cached} = {};
1242
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1243
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1244
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1245

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

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

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

            
1277
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1278
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1279
    one => sub { 1 }
1280
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1281
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1282
    two => sub { 2 }
1283
);
1284
$dbi->method({
1285
    twice => sub {
1286
        my $self = shift;
1287
        return $_[0] * 2;
1288
    }
1289
});
1290

            
1291
is($dbi->one, 1, "first");
1292
is($dbi->two, 2, "second");
1293
is($dbi->twice(5), 10 , "second");
1294

            
1295
eval {$dbi->XXXXXX};
1296
ok($@, "not exists");
1297

            
1298
test 'out filter';
1299
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1300
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1301
$dbi->execute($create_table1);
1302
$dbi->register_filter(twice => sub { $_[0] * 2 });
1303
$dbi->register_filter(three_times => sub { $_[0] * 3});
1304
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1305
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1306
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
1307
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1308
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1309
$row   = $result->fetch_hash_first;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1310
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1311
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1312
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1313
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1314

            
1315
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1316
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1317
$dbi->execute($create_table1);
1318
$dbi->register_filter(twice => sub { $_[0] * 2 });
1319
$dbi->register_filter(three_times => sub { $_[0] * 3});
1320
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1321
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1322
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1323
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1324
    $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1325
); 
test cleanup
Yuki Kimoto authored on 2011-11-01
1326
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1327
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1328
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1329
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1330

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

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

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

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

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

            
1397
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1398
eval { $dbi->execute("drop table $table1") };
1399
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1400
$dbi->execute($create_table1);
1401
$dbi->execute($create_table2);
1402
$dbi->register_filter(twice => sub { $_[0] * 2 });
1403
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1404
$dbi->apply_filter(
cleanup test
Yuki Kimoto authored on 2011-08-15
1405
    $table1, $key2 => {out => 'twice', in => 'twice'}
1406
);
1407
$dbi->apply_filter(
1408
    $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1409
);
cleanup
Yuki Kimoto authored on 2011-11-01
1410
$dbi->insert({$key1 => 5, $key2 => 2}, table => $table1, filter => {$key2 => undef});
1411
$dbi->insert({$key1 => 5, $key3 => 6}, table => $table2, filter => {$key3 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1412
$result = $dbi->select(
1413
     table => [$table1, $table2],
1414
     column => [$key2, $key3],
1415
     where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1416

            
1417
$result->filter({$key2 => 'twice'});
1418
$rows   = $result->all;
1419
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1420

            
1421
$result = $dbi->select(
1422
     table => [$table1, $table2],
1423
     column => [$key2, $key3],
1424
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1425

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

            
1430
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1431
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1432
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1433
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1434
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1435
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1436

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1437
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1438
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1439
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1440
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1441
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1442
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1443

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

            
1450
test 'end_filter';
1451
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1452
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1453
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1454
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1455
$result = $dbi->select(table => $table1);
1456
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1457
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1458
$row = $result->fetch_first;
1459
is_deeply($row, [6, 40]);
1460

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1461
$dbi = DBIx::Custom->connect;
1462
eval { $dbi->execute("drop table $table1") };
1463
$dbi->execute($create_table1);
1464
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1465
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1466
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1467
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
1468
$row = $result->fetch_first;
1469
is_deeply($row, [6, 6, 40]);
1470

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1471
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1472
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1473
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1474
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1475
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1476
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1477
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1478
$row = $result->fetch_first;
1479
is_deeply($row, [6, 12]);
1480

            
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
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1486
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1487
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1488
$row = $result->fetch_first;
1489
is_deeply($row, [6, 12]);
1490

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

            
1498
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1499
$dbi->apply_filter($table1,
1500
    $key1 => {end => sub { $_[0] * 3 } },
1501
    $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1502
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1503
$result = $dbi->select(table => $table1);
1504
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1505
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1506
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1507

            
1508
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1509
$dbi->apply_filter($table1,
1510
    $key1 => {end => sub { $_[0] * 3 } },
1511
    $key2 => {end => 'five_times'}
1512
);
1513
$result = $dbi->select(table => $table1);
1514
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1515
$result->filter($key1 => undef);
1516
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1517
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1518
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1519

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1520
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1521
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1522
$result->filter($key1 => undef);
1523
$result->end_filter($key1 => undef);
1524
$row = $result->fetch;
1525
is_deeply($row, [1, 1, 40], 'apply_filter overwrite');
1526

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

            
1541
test 'empty where select';
1542
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1543
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1544
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1545
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1546
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1547
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1548
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1549

            
1550
test 'select query option';
1551
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1552
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1553
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1554
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1555
is(ref $query, 'DBIx::Custom::Query');
cleanup
Yuki Kimoto authored on 2011-11-01
1556
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1557
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1558
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1559
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1560
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1561
is(ref $query, 'DBIx::Custom::Query');
1562

            
1563
test 'where';
1564
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1565
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1566
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1567
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1568
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1569
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1570
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1571

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

            
1576
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1577
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1578
    where => $where
1579
);
1580
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1581
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1582

            
1583
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1584
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1585
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1586
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
1587
        {$key1 => 1}
test cleanup
Yuki Kimoto authored on 2011-08-10
1588
    ]
1589
);
1590
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1591
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1592

            
1593
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1594
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1595
             ->param({$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1596
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1597
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1598
    where => $where
1599
);
1600
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1601
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1602

            
1603
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1604
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
test cleanup
Yuki Kimoto authored on 2011-08-10
1605
             ->param({});
1606
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1607
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1608
    where => $where,
1609
);
1610
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1611
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1612

            
1613
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1614
             ->clause(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"])
1615
             ->param({$key1 => [0, 3], $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1616
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1617
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1618
    where => $where,
1619
); 
1620
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1621
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1622

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

            
1631
eval {
1632
$where = $dbi->where
1633
             ->clause(['uuu']);
1634
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1635
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1636
    where => $where
1637
);
1638
};
1639
ok($@);
1640

            
1641
$where = $dbi->where;
1642
is("$where", '');
1643

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1813
eval {$dbi->where(ppp => 1) };
1814
like($@, qr/invalid/);
1815

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

            
1827

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

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

            
1846
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1847
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1848
$where->param({$key1 => [undef, undef]});
1849
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1850
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1851
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1852
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1853
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1854
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1855

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

            
1857
$dbi = DBIx::Custom->connect;
1858
eval { $dbi->execute("drop table $table1") };
1859
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1860
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
1861
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1862
$where = $dbi->where
1863
             ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
1864
             ->param({$key1 => 1});
1865

            
1866
$result = $dbi->select(
1867
    table => $table1,
1868
    where => $where
1869
);
1870
$row = $result->all;
1871
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
1872

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1873
test 'register_tag_processor';
1874
$dbi = DBIx::Custom->connect;
1875
$dbi->register_tag_processor(
1876
    a => sub { 1 }
1877
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1878
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1879

            
1880
test 'register_tag';
1881
$dbi = DBIx::Custom->connect;
1882
$dbi->register_tag(
1883
    b => sub { 2 }
1884
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1885
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1886

            
1887
test 'table not specify exception';
1888
$dbi = DBIx::Custom->connect;
1889
eval {$dbi->select};
1890
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1891

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1892
test 'more tests';
1893
$dbi = DBIx::Custom->connect;
1894
eval{$dbi->apply_filter('table', 'column', [])};
1895
like($@, qr/apply_filter/);
1896

            
1897
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1898
like($@, qr/apply_filter/);
1899

            
1900
$dbi->apply_filter(
1901

            
1902
);
1903
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1904
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1905
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1906
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1907
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1908
$dbi->apply_filter($table1, $key2, 
test cleanup
Yuki Kimoto authored on 2011-08-10
1909
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1910
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
1911
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1912

            
1913
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1914
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1915
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1916
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1917
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1918
$dbi->apply_filter($table1, $key2, {});
1919
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1920
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1921

            
1922
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1923
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1924
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1925
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1926
like($@, qr/not registered/);
1927
$dbi->method({one => sub { 1 }});
1928
is($dbi->one, 1);
1929

            
1930
eval{DBIx::Custom->connect(dsn => undef)};
1931
like($@, qr/_connect/);
1932

            
1933
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1934
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1935
$dbi->execute($create_table1);
1936
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
1937
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1938
             filter => {$key1 => 'twice'});
1939
$row = $dbi->select(table => $table1)->one;
1940
is_deeply($row, {$key1 => 2, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
1941
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1942
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
1943
like($@, qr//);
1944

            
1945
$dbi->register_filter(one => sub { });
1946
$dbi->default_fetch_filter('one');
1947
ok($dbi->default_fetch_filter);
1948
$dbi->default_bind_filter('one');
1949
ok($dbi->default_bind_filter);
1950
eval{$dbi->default_fetch_filter('no')};
1951
like($@, qr/not registered/);
1952
eval{$dbi->default_bind_filter('no')};
1953
like($@, qr/not registered/);
1954
$dbi->default_bind_filter(undef);
1955
ok(!defined $dbi->default_bind_filter);
1956
$dbi->default_fetch_filter(undef);
1957
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1958
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1959
like($@, qr/Tag not finished/);
1960

            
1961
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1962
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1963
$dbi->execute($create_table1);
1964
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1965
$result = $dbi->select(table => $table1);
1966
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1967
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1968
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1969
like($@, qr/not registered/);
1970
$result->default_filter(undef);
1971
ok(!defined $result->default_filter);
1972
$result->default_filter('one');
1973
is($result->default_filter->(), 1);
1974

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1975
test 'option';
1976
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
1977
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
1978
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
1979
ok($dbi->dbh->{PrintError});
1980
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
1981
ok($dbi->dbh->{PrintError});
1982

            
1983
test 'DBIx::Custom::Result stash()';
1984
$result = DBIx::Custom::Result->new;
1985
is_deeply($result->stash, {}, 'default');
1986
$result->stash->{foo} = 1;
1987
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
1988

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1989
test 'delete_at';
1990
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1991
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1992
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
1993
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
1994
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1995
    table => $table1,
1996
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1997
    where => [1, 2],
1998
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1999
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2000

            
cleanup
Yuki Kimoto authored on 2011-11-01
2001
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2002
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2003
    table => $table1,
2004
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2005
    where => 1,
2006
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2007
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2008

            
2009
test 'insert_at';
2010
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2011
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2012
$dbi->execute($create_table1_2);
2013
$dbi->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2014
    {$key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2015
    primary_key => [$key1, $key2], 
2016
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2017
    where => [1, 2],
2018
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2019
is($dbi->select(table => $table1)->one->{$key1}, 1);
2020
is($dbi->select(table => $table1)->one->{$key2}, 2);
2021
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2022

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2023
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2024
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2025
$dbi->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2026
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2027
    primary_key => $key1, 
2028
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2029
    where => 1,
2030
);
2031

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

            
2036
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2037
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2038
$dbi->execute($create_table1_2);
2039
$dbi->insert_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2040
    {$key3 => 3},
2041
    primary_key => [$key1, $key2], 
2042
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2043
    where => [1, 2],
2044
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2045
is($dbi->select(table => $table1)->one->{$key1}, 1);
2046
is($dbi->select(table => $table1)->one->{$key2}, 2);
2047
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2048

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2117
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2118
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2119
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2120
    table => $table1,
2121
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2122
    where => [1, 2]
2123
);
2124
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2125
is($row->{$key1}, 1);
2126
is($row->{$key2}, 2);
2127
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2128

            
2129
test 'model delete_at';
2130
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2131
eval { $dbi->execute("drop table $table1") };
2132
eval { $dbi->execute("drop table $table2") };
2133
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2134
$dbi->execute($create_table1_2);
2135
$dbi->execute($create_table2_2);
2136
$dbi->execute($create_table3);
test cleanup
Yuki Kimoto authored on 2011-11-01
2137
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2138
$dbi->model($table1)->delete_at(where => [1, 2]);
2139
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2140
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2141
$dbi->model($table1)->delete_at(where => [1, 2]);
2142
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2143
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2144
$dbi->model($table3)->delete_at(where => [1, 2]);
2145
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2146

            
2147
test 'model insert_at';
2148
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2149
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2150
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2151
$dbi->model($table1)->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2152
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2153
    where => [1, 2],
2154
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2155
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2156
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2157
is($row->{$key1}, 1);
2158
is($row->{$key2}, 2);
2159
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2160

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

            
2176
test 'model select_at';
2177
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2178
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2179
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2180
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2181
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2182
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2183
is($row->{$key1}, 1);
2184
is($row->{$key2}, 2);
2185
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2186

            
2187

            
2188
test 'mycolumn and column';
2189
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2190
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2191
eval { $dbi->execute("drop table $table1") };
2192
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2193
$dbi->execute($create_table1);
2194
$dbi->execute($create_table2);
2195
$dbi->separator('__');
2196
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2197
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2198
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2199
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2200
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2201
    column => [$model->mycolumn, $model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2202
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2203
);
2204
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2205
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2206

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2207
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2208
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2209
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2210
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2211
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2212
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2213
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2214
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2215
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2216
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2217
is($dbi->select(table => $table1)->one->{$key1}, 1);
2218
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2219

            
2220
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2221
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2222
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2223
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2224
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2225
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2226
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2227
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2228
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2229
is($dbi->select(table => $table1)->one->{$key1}, 1);
2230
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2231

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2232
eval { $dbi->values_clause({";" => 1}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
2233
like($@, qr/not safety/);
test cleanup
Yuki Kimoto authored on 2011-08-10
2234

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2235
test 'mycolumn';
2236
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2237
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2238
eval { $dbi->execute("drop table $table1") };
2239
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2240
$dbi->execute($create_table1);
2241
$dbi->execute($create_table2);
2242
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2243
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2244
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2245
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2246
$result = $model->select_at(
2247
    column => [
2248
        $model->mycolumn,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2249
        $model->column($table2)
cleanup test
Yuki Kimoto authored on 2011-08-10
2250
    ]
2251
);
2252
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2253
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2254

            
2255
$result = $model->select_at(
2256
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2257
        $model->mycolumn([$key1]),
2258
        $model->column($table2 => [$key1])
cleanup test
Yuki Kimoto authored on 2011-08-10
2259
    ]
2260
);
2261
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2262
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2263
$result = $model->select_at(
2264
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2265
        $model->mycolumn([$key1]),
2266
        {$table2 => [$key1]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2267
    ]
2268
);
2269
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2270
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2271

            
2272
$result = $model->select_at(
2273
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2274
        $model->mycolumn([$key1]),
2275
        ["$table2.$key1", as => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2276
    ]
2277
);
2278
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2279
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2280

            
2281
$result = $model->select_at(
2282
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2283
        $model->mycolumn([$key1]),
2284
        ["$table2.$key1" => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2285
    ]
2286
);
2287
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2288
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2289

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2290
test 'merge_param';
2291
$dbi = DBIx::Custom->new;
2292
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2293
    {$key1 => 1, $key2 => 2, $key3 => 3},
2294
    {$key1 => 1, $key2 => 2},
2295
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2296
];
2297
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2298
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2299

            
2300
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2301
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2302
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2303
];
2304
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2305
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
2306

            
2307
test 'select() param option';
2308
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2309
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2310
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2311
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2312
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2313
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2314
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2315
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
2316
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
2317
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2318
    table => $table1,
2319
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2320
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2321
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
test cleanup
Yuki Kimoto authored on 2011-08-15
2322
              " $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2323
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2324
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2325
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2326

            
cleanup
Yuki Kimoto authored on 2011-10-21
2327
$rows = $dbi->select(
2328
    table => $table1,
2329
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2330
    where   => {"$table1.$key2" => 3},
2331
    join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2332
             " $table2 on $table1.$key1 = $table2.$key1",
2333
    param => {"$table2.$key3" => 5}
2334
)->all;
2335
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2336

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2337
test 'select() string where';
2338
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2339
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2340
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2341
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2342
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2343
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2344
    table => $table1,
2345
    where => "$key1 = :$key1 and $key2 = :$key2",
2346
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2347
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2348
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2349

            
2350
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2351
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2352
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2353
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2354
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2355
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2356
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2357
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2358
        "$key1 = :$key1 and $key2 = :$key2",
2359
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2360
    ]
2361
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2362
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2363

            
cleanup
Yuki Kimoto authored on 2011-10-21
2364
$dbi = DBIx::Custom->connect;
2365
eval { $dbi->execute("drop table $table1") };
2366
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2367
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2368
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
2369
$rows = $dbi->select(
2370
    table => $table1,
2371
    where => [
2372
        "$key1 = :$key1 and $key2 = :$key2",
2373
        {$key1 => 1, $key2 => 2}
2374
    ]
2375
)->all;
2376
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2377

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

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

            
2407

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2451
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2452
$dbi->insert(
cleanup
Yuki Kimoto authored on 2011-11-01
2453
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2454
    primary_key => $key1, 
2455
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2456
    id => 0,
2457
);
2458

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2463
$dbi = DBIx::Custom->connect;
2464
eval { $dbi->execute("drop table $table1") };
2465
$dbi->execute($create_table1_2);
2466
$dbi->insert(
2467
    {$key3 => 3},
2468
    primary_key => [$key1, $key2], 
2469
    table => $table1,
2470
    id => 1,
2471
);
2472
is($dbi->select(table => $table1)->one->{$key1}, 1);
2473
ok(!$dbi->select(table => $table1)->one->{$key2});
2474
is($dbi->select(table => $table1)->one->{$key3}, 3);
2475

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

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2489
$dbi = DBIx::Custom->connect;
2490
eval { $dbi->execute("drop table $table1") };
2491
$dbi->execute($create_table1_2);
2492
$param = {$key3 => 3, $key2 => 4};
2493
$dbi->insert(
2494
    $param,
2495
    primary_key => [$key1, $key2], 
2496
    table => $table1,
2497
    id => [1, 2],
2498
);
2499
is($dbi->select(table => $table1)->one->{$key1}, 1);
2500
is($dbi->select(table => $table1)->one->{$key2}, 4);
2501
is($dbi->select(table => $table1)->one->{$key3}, 3);
2502
is_deeply($param, {$key3 => 3, $key2 => 4});
2503

            
added test
Yuki Kimoto authored on 2011-10-25
2504
$dbi = DBIx::Custom->connect;
2505
eval { $dbi->execute("drop table $table1") };
2506
$dbi->execute($create_table1_2);
2507
$param = {$key3 => 3, $key2 => 4};
2508
$query = $dbi->insert(
2509
    $param,
2510
    primary_key => [$key1, $key2], 
2511
    table => $table1,
2512
    id => [1, 2],
2513
    query => 1
2514
);
2515
is(ref $query, 'DBIx::Custom::Query');
2516
is_deeply($param, {$key3 => 3, $key2 => 4});
2517

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2518
test 'model insert id and primary_key option';
2519
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2520
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2521
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2522
$dbi->model($table1)->insert(
cleanup
Yuki Kimoto authored on 2011-11-01
2523
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2524
    id => [1, 2],
2525
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2526
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2527
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2528
is($row->{$key1}, 1);
2529
is($row->{$key2}, 2);
2530
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2531

            
2532
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2533
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2534
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2535
$dbi->model($table1)->insert(
2536
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2537
    id => [1, 2]
2538
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2539
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2540
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2541
is($row->{$key1}, 1);
2542
is($row->{$key2}, 2);
2543
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2544

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2560
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2561
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2562
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2563
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2564
    table => $table1,
2565
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2566
    id => 0,
2567
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2568
is($dbi->select(table => $table1)->one->{$key1}, 0);
2569
is($dbi->select(table => $table1)->one->{$key2}, 2);
2570
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2571

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

            
2586

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

            
2602

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

            
cleanup
Yuki Kimoto authored on 2011-11-01
2615
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2616
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2617
    table => $table1,
2618
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2619
    id => 0,
2620
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2621
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2622

            
2623

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

            
2642

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2658
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2659
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2660
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2661
    table => $table1,
2662
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2663
    id => 0,
2664
);
2665
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2666
is($row->{$key1}, 0);
2667
is($row->{$key2}, 2);
2668
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2669

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2670
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2671
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2672
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2673
    table => $table1,
2674
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2675
    id => [1, 2]
2676
);
2677
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2678
is($row->{$key1}, 1);
2679
is($row->{$key2}, 2);
2680
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2681

            
2682

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

            
2694
test 'column separator is default .';
2695
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2696
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2697
eval { $dbi->execute("drop table $table1") };
2698
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2699
$dbi->execute($create_table1);
2700
$dbi->execute($create_table2);
2701
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2702
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2703
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2704
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2705
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2706
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2707
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2708
);
2709
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2710
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2711

            
2712
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2713
    column => [$model->column($table2 => [$key1, $key3])],
2714
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2715
);
2716
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2717
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2718

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2719
test 'separator';
2720
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2721
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2722
eval { $dbi->execute("drop table $table1") };
2723
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2724
$dbi->execute($create_table1);
2725
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2726

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2727
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2728
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2729
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2730
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2731
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2732
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2733
);
2734
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2735
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2736
);
2737
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2738
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2739
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2740
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2741
$result = $model->select(
2742
    column => [
2743
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2744
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2745
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2746
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2747
);
2748
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2749
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2750
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2751

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2752
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2753
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2754
$result = $model->select(
2755
    column => [
2756
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2757
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2758
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2759
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2760
);
2761
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2762
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
2763
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2764

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2765
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2766
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2767
$result = $model->select(
2768
    column => [
2769
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2770
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2771
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2772
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2773
);
2774
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2775
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2776
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2777

            
2778

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2779
test 'filter_off';
2780
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2781
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2782
eval { $dbi->execute("drop table $table1") };
2783
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2784
$dbi->execute($create_table1);
2785
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2786

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2787
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2788
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2789
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2790
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2791
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2792
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2793
);
2794
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2795
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2796
$model = $dbi->model($table1);
2797
$result = $model->select(column => $key1);
2798
$result->filter($key1 => sub { $_[0] * 2 });
2799
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2800

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2801
test 'available_datetype';
2802
$dbi = DBIx::Custom->connect;
2803
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2804

            
2805

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2806
test 'select prefix option';
2807
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2808
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2809
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2810
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2811
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2812
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2813

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

            
added tests
Yuki Kimoto authored on 2011-08-26
2815
test 'mapper';
2816
$dbi = DBIx::Custom->connect;
2817
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2818
    id => {key => "$table1.id"},
2819
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2820
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
2821
);
2822
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2823
  "$table1.price" => 1900});
2824

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2825
$dbi = DBIx::Custom->connect;
2826
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2827
    id => {key => "$table1.id"},
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2828
    author => ["$table1.author" => $dbi->like_value],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2829
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2830
);
2831
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2832
  "$table1.price" => 1900});
2833

            
added tests
Yuki Kimoto authored on 2011-08-26
2834
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2835
    id => {key => "$table1.id"},
2836
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2837
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
2838
);
2839
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2840

            
2841
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2842
    id => {key => "$table1.id"},
2843
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2844
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
added tests
Yuki Kimoto authored on 2011-08-26
2845
);
2846
is_deeply($param, {});
2847

            
2848
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2849
    id => {key => "$table1.id"},
2850
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2851
);
2852
is_deeply($param, {"$table1.price" => undef});
2853

            
2854
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2855
    id => {key => "$table1.id", condition => 'exists'},
2856
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
2857
);
2858
is_deeply($param, {"$table1.price" => '%a'});
2859

            
2860
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2861
    id => {key => "$table1.id"},
added tests
Yuki Kimoto authored on 2011-08-26
2862
    price => ["$table1.price", sub { '%' . $_[0] }]
2863
);
2864
is_deeply($param, {"$table1.price" => '%a'});
2865

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2866
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2867
    price => sub { '%' . $_[0] },
2868
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2869
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2870
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2871

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

            
2877
$where = $dbi->where;
2878
$where->clause(['and', ":${key1}{=}"]);
2879
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
2880
$where->param($param);
2881
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2882
$row = $result->all;
2883
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2884

            
2885
$where = $dbi->where;
2886
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2887
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
2888
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2889
$row = $result->all;
2890
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2891
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2892
$row = $result->all;
2893
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2894

            
2895
$where = $dbi->where;
2896
$where->clause(['and', ":${key1}{=}"]);
2897
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
2898
$where->param($param);
2899
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2900
$row = $result->all;
2901
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2902
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2903
$row = $result->all;
2904
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2905

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2907
$where = $dbi->where;
2908
$where->clause(['and', ":${key1}{=}"]);
2909
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
2910
  ->pass([$key1, $key2])->map;
2911
$where->param($param);
2912
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2913
$row = $result->all;
2914
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2915

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

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

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2934
$where = $dbi->where;
2935
$where->clause(['and', ":${key1}{=}"]);
2936
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
2937
$where->param($param);
2938
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2939
$row = $result->all;
2940
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2941

            
2942
$where = $dbi->where;
2943
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2944
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2945
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2946
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2947
);
2948
$where->param($param);
2949
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2950
  "$table1.price" => 1900});
2951

            
2952
$where = $dbi->where;
2953
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2954
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2955
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2956
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2957
);
2958
$where->param($param);
2959
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2960

            
2961
$where = $dbi->where;
2962
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2963
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2964
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2965
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2966
);
2967
$where->param($param);
2968
is_deeply($where->param, {});
2969

            
2970
$where = $dbi->where;
2971
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2972
    id => {key => "$table1.id"},
2973
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2974
);
2975
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
2976

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

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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3016
test 'order';
3017
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3018
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3019
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3020
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3021
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3022
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3023
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3024
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3025
$order->prepend($key1, "$key2 desc");
3026
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3027
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
3028
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3029
$order->prepend("$key1 desc");
3030
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3031
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
3032
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3033

            
3034
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3035
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3036
$result = $dbi->select(table => $table1,
3037
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3038
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3039
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
3040
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
3041
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
3042
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3043

            
3044
test 'tag_parse';
3045
$dbi = DBIx::Custom->connect;
3046
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3047
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3048
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3049
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3050
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3051
ok($@);
3052

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3053
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3054
{
3055
    $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3056
    $dbi = DBIx::Custom->connect;
3057
    eval { $dbi->execute("drop table $table1") };
3058
    $dbi->execute($create_table1);
3059
    $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3060
    eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3061
    ok($@);
3062
    delete$ENV{DBIX_CUSTOM_TAG_PARSE};
3063
}
3064

            
3065
{
3066
    $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3067
    $dbi = DBIx::Custom->connect;
3068
    eval { $dbi->execute("drop table $table1") };
3069
    $dbi->execute($create_table1);
3070
    $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3071
    is($dbi->select(table => $table1)->one->{$key1}, 1);
3072
    delete$ENV{DBIX_CUSTOM_TAG_PARSE};
3073
}
3074

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3075
test 'last_sql';
3076
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3077
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3078
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3079
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
3080
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3081

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3113
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3114
$result = $dbi->execute(
3115
    $source,
cleanup
Yuki Kimoto authored on 2011-11-01
3116
    {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3117
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3118
);
3119
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3120
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3121

            
3122
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3123
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3124
$dbi->execute($create_table1_highperformance);
3125
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3126
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3127
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3128
];
3129
{
3130
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3131
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3132
      $query ||= $dbi->insert($row, table => $table1, query => 1);
3133
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
3134
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3135
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3136
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3137
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3138
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3139
      ]
3140
    );
3141
}
3142

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3143
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3144
$dbi->execute($create_table1_highperformance);
3145
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3146
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3147
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3148
];
3149
{
3150
    my $query;
3151
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
3152
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3153
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3154
      $sth ||= $query->sth;
3155
      $sth->execute(map { $row->{$_} } sort keys %$row);
3156
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3157
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3158
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3159
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3160
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3161
      ]
3162
    );
3163
}
3164

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3165
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3166
$dbi->execute($create_table1_highperformance);
3167
$rows = [
3168
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
3169
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
3170
];
3171
{
3172
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3173
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3174
    for my $row (@$rows) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3175
      $query ||= $model->insert($row, query => 1);
3176
      $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3177
    }
3178
    is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3179
      [
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3180
          {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3181
          {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3182
      ]
3183
    );
3184
}
3185

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3186
eval { $dbi->execute("drop table $table1") };
3187
$dbi->execute($create_table1);
3188
{
3189
    $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3190
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3191
    eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3192
    like($@, qr/primary_key/);
3193
    delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
3194
}
3195

            
3196
{
3197
    $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3198
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3199
    $model->insert({$key1 => 1});
3200
    $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3201
      table => $table1, primary_key => $key1);
3202
    is($result->one->{$key1}, 1);
3203
    delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
3204
}
3205

            
3206
eval { $dbi->execute("drop table $table1") };
3207
$dbi->execute($create_table1);
3208
{
3209
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3210
    $model->insert({$key1 => 1});
3211
    eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3212
    is($result->one->{$key1}, 1);
3213
}
3214

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3215
test 'id option more';
3216
eval { $dbi->execute("drop table $table1") };
3217
$dbi->execute($create_table1_highperformance);
3218
$row = {
3219
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3220
};
3221
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3222
$model->insert($row);
3223
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3224
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3225
is_deeply($dbi->select(table => $table1)->one,
3226
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3227
);
3228

            
3229
eval { $dbi->execute("drop table $table1") };
3230
eval { $dbi->execute("drop table $table2") };
3231
$dbi->execute($create_table1);
3232
$dbi->execute($create_table2);
3233
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3234
$model->insert({$key1 => 1, $key2 => 2});
3235
$model = $dbi->create_model(table => $table2, primary_key => $key1,
3236
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
3237
$model->insert({$key1 => 1, $key3 => 3});
3238
$result = $model->select(
3239
    column => {$table1 => ["$key2"]},
3240
    id => 1
3241
);
3242
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3243

            
3244
eval { $dbi->execute("drop table $table1") };
3245
$dbi->execute($create_table1_highperformance);
3246
$row = {
3247
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3248
};
3249
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3250
$model->insert($row);
3251
$query = $model->delete(id => 1, query => 1);
3252
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3253
is_deeply($dbi->select(table => $table1)->all, []);
3254

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3269
test 'result';
3270
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3271
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3272
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3273
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3274
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3275

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3276
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3277
@rows = ();
3278
while (my $row = $result->fetch) {
3279
    push @rows, [@$row];
3280
}
3281
is_deeply(\@rows, [[1, 2], [3, 4]]);
3282

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3283
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3284
@rows = ();
3285
while (my $row = $result->fetch_hash) {
3286
    push @rows, {%$row};
3287
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3288
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3289

            
3290
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3291
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3292
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3293
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3294
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3295

            
3296
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3297
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3298
$rows = $result->fetch_all;
3299
is_deeply($rows, [[1, 2], [3, 4]]);
3300

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3305
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3306
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3307
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3308
$rows = $result->fetch_all;
3309
is_deeply($rows, [[3, 2], [9, 4]], "array");
3310

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

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3323
test 'DBIx::Custom::Result fetch_multi';
3324
eval { $dbi->execute("drop table $table1") };
3325
$dbi->execute($create_table1);
3326
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3327
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3328
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3329
$result = $dbi->select(table => $table1);
3330
$rows = $result->fetch_multi(2);
3331
is_deeply($rows, [[1, 2], [3, 4]]);
3332
$rows = $result->fetch_multi(2);
3333
is_deeply($rows, [[5, 6]]);
3334
$rows = $result->fetch_multi(2);
3335
ok(!$rows);
3336

            
3337
test 'DBIx::Custom::Result fetch_hash_multi';
3338
eval { $dbi->execute("drop table $table1") };
3339
$dbi->execute($create_table1);
3340
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3341
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3342
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3343
$result = $dbi->select(table => $table1);
3344
$rows = $result->fetch_hash_multi(2);
3345
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3346
$rows = $result->fetch_hash_multi(2);
3347
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3348
$rows = $result->fetch_hash_multi(2);
3349
ok(!$rows);
3350

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3351
test "query_builder";
3352
$datas = [
3353
    # Basic tests
3354
    {   name            => 'placeholder basic',
3355
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3356
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3357
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3358
    },
3359
    {
3360
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3361
        source            => "{in k1 3}",
3362
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3363
        columns_expected   => [qw/k1 k1 k1/]
3364
    },
3365
    
3366
    # Table name
3367
    {
3368
        name            => 'placeholder with table name',
3369
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3370
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3371
        columns_expected  => [qw/a.k1 a.k2/]
3372
    },
3373
    {   
3374
        name            => 'placeholder in with table name',
3375
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3376
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3377
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3378
    },
3379
    {
3380
        name            => 'not contain tag',
3381
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3382
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3383
        columns_expected  => [],
3384
    }
3385
];
3386

            
3387
for (my $i = 0; $i < @$datas; $i++) {
3388
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3389
    my $dbi = DBIx::Custom->new;
3390
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3391
    my $query = $builder->build_query($data->{source});
3392
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3393
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3394
}
3395

            
cleanup
Yuki Kimoto authored on 2011-08-13
3396
$dbi = DBIx::Custom->new;
3397
$builder = $dbi->query_builder;
3398
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3399
    p => sub {
3400
        my @args = @_;
3401
        
3402
        my $expand    = "? $args[0] $args[1]";
3403
        my $columns = [2];
3404
        return [$expand, $columns];
3405
    }
3406
);
3407

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3418
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3419
    q => 'string'
3420
});
3421

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3425
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3426
   r => sub {} 
3427
});
3428

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3432
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3433
   s => sub { return ["a", ""]} 
3434
});
3435

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3439
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3440
    t => sub {return ["a", []]}
3441
);
3442

            
3443

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

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

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

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

            
3459
test 'variouse source';
3460
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3461
$query = $builder->build_query($source);
3462
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3463

            
3464
$source = "abc";
3465
$query = $builder->build_query($source);
3466
is($query->sql, 'abc', "basic : 2");
3467

            
3468
$source = "{= a}";
3469
$query = $builder->build_query($source);
3470
is($query->sql, 'a = ?', "only tag");
3471

            
3472
$source = "000";
3473
$query = $builder->build_query($source);
3474
is($query->sql, '000', "contain 0 value");
3475

            
3476
$source = "a {= b} }";
3477
eval{$builder->build_query($source)};
3478
like($@, qr/unexpected "}"/, "error : 1");
3479

            
3480
$source = "a {= {}";
3481
eval{$builder->build_query($source)};
3482
like($@, qr/unexpected "{"/, "error : 2");
3483

            
3484
test 'select() sqlfilter option';
3485
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3486
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3487
eval { $dbi->execute("drop table $table1") };
3488
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3489
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3490
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3491
$rows = $dbi->select(
3492
    table => $table1,
3493
    column => $key1,
3494
    sqlfilter => sub {
3495
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
3496
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
3497
        return $sql;
3498
    }
3499
)->all;
3500
is_deeply($rows, [{$key1 => 1}]);
3501

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3502
test 'select() after_build_sql option';
3503
$dbi = DBIx::Custom->connect;
3504
$dbi->user_table_info($user_table_info);
3505
eval { $dbi->execute("drop table $table1") };
3506
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3507
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3508
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3509
$rows = $dbi->select(
3510
    table => $table1,
3511
    column => $key1,
3512
    after_build_sql => sub {
3513
        my $sql = shift;
3514
        $sql = "select * from ( $sql ) t where $key1 = 1";
3515
        return $sql;
3516
    }
3517
)->all;
3518
is_deeply($rows, [{$key1 => 1}]);
3519

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3520
test 'dbi method from model';
3521
$dbi = MyDBI9->connect;
3522
eval { $dbi->execute("drop table $table1") };
3523
$dbi->execute($create_table1);
3524
$dbi->setup_model;
3525
$model = $dbi->model($table1);
3526
eval{$model->execute("select * from $table1")};
3527
ok(!$@);
3528

            
3529
test 'column table option';
3530
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3531
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3532
eval { $dbi->execute("drop table $table1") };
3533
$dbi->execute($create_table1);
3534
eval { $dbi->execute("drop table $table2") };
3535
$dbi->execute($create_table2);
3536
$dbi->setup_model;
3537
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3538
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3539
$model = $dbi->model($table1);
3540
$result = $model->select(
3541
    column => [
3542
        $model->column($table2, {alias => $table2_alias})
3543
    ],
3544
    where => {"$table2_alias.$key3" => 4}
3545
);
3546
is_deeply($result->one, 
3547
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3548

            
3549
$dbi->separator('__');
3550
$result = $model->select(
3551
    column => [
3552
        $model->column($table2, {alias => $table2_alias})
3553
    ],
3554
    where => {"$table2_alias.$key3" => 4}
3555
);
3556
is_deeply($result->one, 
3557
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3558

            
3559
$dbi->separator('-');
3560
$result = $model->select(
3561
    column => [
3562
        $model->column($table2, {alias => $table2_alias})
3563
    ],
3564
    where => {"$table2_alias.$key3" => 4}
3565
);
3566
is_deeply($result->one, 
3567
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3568

            
3569
test 'create_model';
3570
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3571
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3572
eval { $dbi->execute("drop table $table1") };
3573
eval { $dbi->execute("drop table $table2") };
3574
$dbi->execute($create_table1);
3575
$dbi->execute($create_table2);
3576

            
3577
$dbi->create_model(
3578
    table => $table1,
3579
    join => [
3580
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3581
    ],
3582
    primary_key => [$key1]
3583
);
3584
$model2 = $dbi->create_model(
3585
    table => $table2
3586
);
3587
$dbi->create_model(
3588
    table => $table3,
3589
    filter => [
3590
        $key1 => {in => sub { uc $_[0] }}
3591
    ]
3592
);
3593
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3594
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3595
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3596
$model = $dbi->model($table1);
3597
$result = $model->select(
3598
    column => [$model->mycolumn, $model->column($table2)],
3599
    where => {"$table1.$key1" => 1}
3600
);
3601
is_deeply($result->one,
3602
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3603
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3604

            
3605
test 'model method';
3606
$dbi = DBIx::Custom->connect;
3607
eval { $dbi->execute("drop table $table2") };
3608
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3609
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3610
$model = $dbi->create_model(
3611
    table => $table2
3612
);
3613
$model->method(foo => sub { shift->select(@_) });
3614
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3615

            
3616
test 'model helper';
3617
$dbi = DBIx::Custom->connect;
3618
eval { $dbi->execute("drop table $table2") };
3619
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3620
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3621
$model = $dbi->create_model(
3622
    table => $table2
3623
);
3624
$model->helper(foo => sub { shift->select(@_) });
3625
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3626

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

            
3634
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3635
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3636
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3637
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3638
where $key1 = 1
3639
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3640
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3641
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3642
$rows   = $result->all;
3643
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3644
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3645
                  "basic");
3646

            
3647

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

            
3654
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3655
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3656
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3657
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3658
where $key1 = 1
3659
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3660
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3661
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3662
$rows   = $result->all;
3663
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3664
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3665
                  "basic");
3666

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

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

            
3686
            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3687
eval { $dbi->assign_clause({";" => 1}) };
cleanup test
Yuki Kimoto authored on 2011-08-15
3688
like($@, qr/not safety/);
3689

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

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

            
3709
$param = {$key2 => 11};
3710
$assign_clause = $dbi->assign_clause($param);
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, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3716
$result = $dbi->execute("select * from $table1 order by $key1");
3717
$rows   = $result->all;
3718
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3719
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3720
                  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3721

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3722
test 'Model class';
3723
$dbi = MyDBI1->connect;
3724
eval { $dbi->execute("drop table $table1") };
3725
$dbi->execute($create_table1);
3726
$model = $dbi->model($table1);
3727
$model->insert({$key1 => 'a', $key2 => 'b'});
3728
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3729
eval { $dbi->execute("drop table $table2") };
3730
$dbi->execute($create_table2);
3731
$model = $dbi->model($table2);
3732
$model->insert({$key1 => 'a'});
3733
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3734
is($dbi->models->{$table1}, $dbi->model($table1));
3735
is($dbi->models->{$table2}, $dbi->model($table2));
3736

            
3737
$dbi = MyDBI4->connect;
3738
eval { $dbi->execute("drop table $table1") };
3739
$dbi->execute($create_table1);
3740
$model = $dbi->model($table1);
3741
$model->insert({$key1 => 'a', $key2 => 'b'});
3742
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3743
eval { $dbi->execute("drop table $table2") };
3744
$dbi->execute($create_table2);
3745
$model = $dbi->model($table2);
3746
$model->insert({$key1 => 'a'});
3747
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3748

            
3749
$dbi = MyDBI5->connect;
3750
eval { $dbi->execute("drop table $table1") };
3751
eval { $dbi->execute("drop table $table2") };
3752
$dbi->execute($create_table1);
3753
$dbi->execute($create_table2);
3754
$model = $dbi->model($table2);
3755
$model->insert({$key1 => 'a'});
3756
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
3757
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3758
$model = $dbi->model($table1);
3759
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3760

            
3761
test 'primary_key';
3762
$dbi = MyDBI1->connect;
3763
$model = $dbi->model($table1);
3764
$model->primary_key([$key1, $key2]);
3765
is_deeply($model->primary_key, [$key1, $key2]);
3766

            
3767
test 'columns';
3768
$dbi = MyDBI1->connect;
3769
$model = $dbi->model($table1);
3770
$model->columns([$key1, $key2]);
3771
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3772

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3773
test 'setup_model';
3774
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3775
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3776
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3777
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3778

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3779
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3780
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3781
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3782
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3783
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3784

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3785
test 'each_column';
3786
$dbi = DBIx::Custom->connect;
3787
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3788
eval { $dbi->execute("drop table $table1") };
3789
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3790
eval { $dbi->execute("drop table $table3") };
3791
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3792
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3793

            
3794
$infos = [];
3795
$dbi->each_column(sub {
3796
    my ($self, $table, $column, $cinfo) = @_;
3797
    
3798
    if ($table =~ /^table\d/i) {
3799
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3800
         push @$infos, $info;
3801
    }
3802
});
3803
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3804
is_deeply($infos, 
3805
    [
3806
        [$table1, $key1, $key1],
3807
        [$table1, $key2, $key2],
3808
        [$table2, $key1, $key1],
3809
        [$table2, $key3, $key3]
3810
    ]
3811
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3812
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3813

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3814
test 'each_table';
3815
$dbi = DBIx::Custom->connect;
3816
eval { $dbi->execute("drop table $table1") };
3817
eval { $dbi->execute("drop table $table2") };
3818
$dbi->execute($create_table2);
3819
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3820

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3821
$infos = [];
3822
$dbi->each_table(sub {
3823
    my ($self, $table, $table_info) = @_;
3824
    
3825
    if ($table =~ /^table\d/i) {
3826
         my $info = [$table, $table_info->{TABLE_NAME}];
3827
         push @$infos, $info;
3828
    }
3829
});
3830
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3831
is_deeply($infos, 
3832
    [
3833
        [$table1, $table1],
3834
        [$table2, $table2],
3835
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3836
);
3837

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3838
$dbi = DBIx::Custom->connect;
3839
eval { $dbi->execute("drop table $table1") };
3840
eval { $dbi->execute("drop table $table2") };
3841
$dbi->execute($create_table2);
3842
$dbi->execute($create_table1_type);
3843

            
3844
$infos = [];
3845
$dbi->user_table_info($user_table_info);
3846
$dbi->each_table(sub {
3847
    my ($self, $table, $table_info) = @_;
3848
    
3849
    if ($table =~ /^table\d/i) {
3850
         my $info = [$table, $table_info->{TABLE_NAME}];
3851
         push @$infos, $info;
3852
    }
3853
});
3854
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3855
is_deeply($infos, 
3856
    [
3857
        [$table1, $table1],
3858
        [$table2, $table2],
3859
        [$table3, $table3],
3860
    ]
3861
);
3862

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3863
test 'type_rule into';
3864
eval { $dbi->execute("drop table $table1") };
3865
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3866
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3867

            
3868

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

            
cleanup
Yuki Kimoto authored on 2011-08-16
3873
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3874
$dbi->type_rule(
3875
    into1 => {
3876
        $date_typename => sub { '2010-' . $_[0] }
3877
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3878
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3879
$dbi->insert({$key1 => '01-01'}, table => $table1);
3880
$result = $dbi->select(table => $table1);
3881
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3882

            
3883
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3884
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3885
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3886
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3887
$dbi->type_rule(
3888
    into1 => [
3889
         [$date_typename, $datetime_typename] => sub {
3890
            my $value = shift;
3891
            $value =~ s/02/03/g;
3892
            return $value;
3893
         }
3894
    ]
3895
);
3896
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3897
$result = $dbi->select(table => $table1);
3898
$row = $result->one;
3899
like($row->{$key1}, qr/^2010-01-03/);
3900
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
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
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
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, $datetime_typename] => sub {
3910
            my $value = shift;
3911
            $value =~ s/02/03/g;
3912
            return $value;
3913
        }
3914
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3915
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3916
$result = $dbi->execute(
3917
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
3918
    {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
3919
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3920
$row = $result->one;
3921
like($row->{$key1}, qr/^2010-01-03/);
3922
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3923

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

            
3947
$dbi = DBIx::Custom->connect;
3948
eval { $dbi->execute("drop table $table1") };
3949
$dbi->execute($create_table1_type);
3950
$dbi->register_filter(convert => sub {
3951
    my $value = shift || '';
3952
    $value =~ s/02/03/;
3953
    return $value;
3954
});
cleanup
Yuki Kimoto authored on 2011-08-16
3955
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3956
$dbi->type_rule(
3957
    from1 => {
3958
        $date_datatype => 'convert',
3959
    },
3960
    into1 => {
3961
        $date_typename => 'convert',
3962
    }
3963
);
3964
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3965
$result = $dbi->select(table => $table1);
3966
like($result->fetch->[0], qr/^2010-03-03/);
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3967
$result = $dbi->select(column => [$key1, $key1], table => $table1);
3968
$row = $result->fetch;
3969
like($row->[0], qr/^2010-03-03/);
3970
like($row->[1], qr/^2010-03-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
3971

            
3972
test 'type_rule and filter order';
3973
$dbi = DBIx::Custom->connect;
3974
eval { $dbi->execute("drop table $table1") };
3975
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3976
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3977
$dbi->type_rule(
3978
    into1 => {
3979
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3980
    },
3981
    into2 => {
3982
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3983
    },
3984
    from1 => {
3985
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3986
    },
3987
    from2 => {
3988
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
3989
    }
3990
);
3991
$dbi->insert({$key1 => '2010-01-03'}, 
3992
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
3993
$result = $dbi->select(table => $table1);
3994
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3995
like($result->fetch_first->[0], qr/^2010-01-09/);
3996

            
3997

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4024
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
4025
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
4026
eval { $dbi->execute("drop table $table1") };
4027
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4028
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4029
$dbi->type_rule(
4030
    from1 => {
4031
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4032
    },
4033
    into1 => {
4034
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4035
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4036
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4037
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4038
$result = $dbi->select(table => $table1, type_rule_off => 1);
4039
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4040

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4041
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4042
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4043
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4044
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4045
$dbi->type_rule(
4046
    from1 => {
4047
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4048
    },
4049
    into1 => {
4050
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4051
    }
4052
);
4053
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4054
$result = $dbi->select(table => $table1, type_rule_off => 1);
4055
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4056

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

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

            
4089
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4090
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4091
$dbi->execute($create_table1_type);
4092
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
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
    into1 => {
4096
        $date_typename => 'ppp'
4097
    }
4098
);
4099
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4100
$result = $dbi->select(table => $table1);
4101
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4102

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4103
eval{$dbi->type_rule(
4104
    into1 => {
4105
        $date_typename => 'pp'
4106
    }
4107
)};
4108
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4109

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4110
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4111
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4112
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4113
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
4114
    $dbi->type_rule(
4115
        from1 => {
4116
            Date => sub { $_[0] * 2 },
4117
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
4118
    );
4119
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4120
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4121

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4122
eval {
4123
    $dbi->type_rule(
4124
        into1 => {
4125
            Date => sub { $_[0] * 2 },
4126
        }
4127
    );
4128
};
4129
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4130

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

            
4148
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4149
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4150
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4151
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4152
$dbi->type_rule(
4153
    from1 => {
4154
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4155
        $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4156
    },
cleanup test
Yuki Kimoto authored on 2011-08-10
4157
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4158
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
4159
$result = $dbi->select(table => $table1);
4160
$result->type_rule(
4161
    from1 => {
4162
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4163
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4164
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4165
$row = $result->one;
4166
like($row->{$key1}, qr/^2010-01-05/);
4167
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4168

            
4169
$result = $dbi->select(table => $table1);
4170
$result->type_rule(
4171
    from1 => {
4172
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4173
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4174
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4175
$row = $result->one;
4176
like($row->{$key1}, qr/2010-01-05/);
4177
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4178

            
4179
$result = $dbi->select(table => $table1);
4180
$result->type_rule(
4181
    from1 => {
4182
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4183
    }
4184
);
4185
$row = $result->one;
4186
like($row->{$key1}, qr/2010-01-05/);
4187
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4188

            
4189
$result = $dbi->select(table => $table1);
4190
$result->type_rule(
4191
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
4192
);
4193
$row = $result->one;
4194
like($row->{$key1}, qr/2010-01-05/);
4195
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4196

            
4197
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4198
$result = $dbi->select(table => $table1);
4199
$result->type_rule(
4200
    from1 => [$date_datatype => 'five']
4201
);
4202
$row = $result->one;
4203
like($row->{$key1}, qr/^2010-01-05/);
4204
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4205

            
4206
$result = $dbi->select(table => $table1);
4207
$result->type_rule(
4208
    from1 => [$date_datatype => undef]
4209
);
4210
$row = $result->one;
4211
like($row->{$key1}, qr/^2010-01-03/);
4212
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4213

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4228
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4229
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4230
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4231
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4232
$dbi->type_rule(
4233
    from1 => {
4234
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4235
    },
4236
);
4237
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4238
$result = $dbi->select(table => $table1);
4239
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4240
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4241

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4242
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4243
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4244
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4245
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4246
$dbi->type_rule(
4247
    into1 => {
4248
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4249
    },
4250
    into2 => {
4251
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4252
    },
4253
    from1 => {
4254
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4255
    },
4256
    from2 => {
4257
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4258
    }
4259
);
4260
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4261
$result = $dbi->select(table => $table1);
4262
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/);
4263
$result = $dbi->select(table => $table1);
4264
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4265

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4314
test 'join';
4315
$dbi = DBIx::Custom->connect;
4316
eval { $dbi->execute("drop table $table1") };
4317
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4318
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4319
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4320
eval { $dbi->execute("drop table $table2") };
4321
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4322
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4323
eval { $dbi->execute("drop table $table3") };
4324
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4325
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4326
$rows = $dbi->select(
4327
    table => $table1,
4328
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4329
    where   => {"$table1.$key2" => 2},
4330
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4331
)->all;
4332
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4333

            
4334
$dbi = DBIx::Custom->connect;
4335
eval { $dbi->execute("drop table $table1") };
4336
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4337
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4338
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4339
eval { $dbi->execute("drop table $table2") };
4340
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4341
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4342
eval { $dbi->execute("drop table $table3") };
4343
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4344
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4345
$rows = $dbi->select(
4346
    table => $table1,
4347
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4348
    where   => {"$table1.$key2" => 2},
4349
    join  => {
4350
        clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4351
        table => [$table1, $table2]
4352
    }
4353
)->all;
4354
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
4355

            
4356
$rows = $dbi->select(
4357
    table => $table1,
4358
    where   => {$key1 => 1},
4359
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4360
)->all;
4361
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4362

            
4363
$rows = $dbi->select(
4364
    table => $table1,
4365
    where   => {$key1 => 1},
4366
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4367
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4368
)->all;
4369
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4370

            
4371
$rows = $dbi->select(
4372
    column => "$table3.$key4 as ${table3}__$key4",
4373
    table => $table1,
4374
    where   => {"$table1.$key1" => 1},
4375
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4376
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4377
)->all;
4378
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4379

            
4380
$rows = $dbi->select(
4381
    column => "$table1.$key1 as ${table1}__$key1",
4382
    table => $table1,
4383
    where   => {"$table3.$key4" => 4},
4384
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4385
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4386
)->all;
4387
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4388

            
4389
$dbi = DBIx::Custom->connect;
4390
eval { $dbi->execute("drop table $table1") };
4391
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4392
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4393
eval { $dbi->execute("drop table $table2") };
4394
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4395
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4396
$rows = $dbi->select(
4397
    table => $table1,
4398
    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",
4399
    where   => {"$table1.$key2" => 2},
4400
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4401
)->all;
4402
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4403
          'quote');
4404

            
4405

            
4406
$dbi = DBIx::Custom->connect;
4407
eval { $dbi->execute("drop table $table1") };
4408
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4409
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4410
$sql = <<"EOS";
4411
left outer join (
4412
  select * from $table1 t1
4413
  where t1.$key2 = (
4414
    select max(t2.$key2) from $table1 t2
4415
    where t1.$key1 = t2.$key1
4416
  )
4417
) $table3 on $table1.$key1 = $table3.$key1
4418
EOS
4419
$join = [$sql];
4420
$rows = $dbi->select(
4421
    table => $table1,
4422
    column => "$table3.$key1 as ${table3}__$key1",
4423
    join  => $join
4424
)->all;
4425
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4426

            
4427
$dbi = DBIx::Custom->connect;
4428
eval { $dbi->execute("drop table $table1") };
4429
eval { $dbi->execute("drop table $table2") };
4430
$dbi->execute($create_table1);
4431
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4432
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4433
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4434
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4435
$result = $dbi->select(
4436
    table => $table1,
4437
    join => [
4438
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4439
    ]
4440
);
4441
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4442
$result = $dbi->select(
4443
    table => $table1,
4444
    column => [{$table2 => [$key3]}],
4445
    join => [
4446
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4447
    ]
4448
);
4449
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4450
$result = $dbi->select(
4451
    table => $table1,
4452
    column => [{$table2 => [$key3]}],
4453
    join => [
4454
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4455
    ]
4456
);
4457
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4458

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

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4479
$dbi = DBIx::Custom->connect;
4480
eval { $dbi->execute("drop table $table1") };
4481
eval { $dbi->execute("drop table $table2") };
4482
$dbi->execute($create_table1);
4483
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4484
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4485
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4486
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4487
$result = $dbi->select(
4488
    table => $table1,
4489
    column => [{$table2 => [$key3]}],
4490
    join => [
4491
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4492
    ]
4493
);
4494
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4495

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4513
test 'columns';
4514
$dbi = MyDBI1->connect;
4515
$model = $dbi->model($table1);
4516

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4517
test 'count';
4518
$dbi = DBIx::Custom->connect;
4519
eval { $dbi->execute("drop table $table1") };
4520
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4521
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4522
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4523
is($dbi->count(table => $table1), 2);
4524
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4525
$model = $dbi->create_model(table => $table1);
4526
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4527

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