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

            
1116
test 'filters';
1117
$dbi = DBIx::Custom->new;
1118

            
1119
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
1120
   'あ', "decode_utf8");
1121

            
1122
is($dbi->filters->{encode_utf8}->('あ'),
1123
   encode_utf8('あ'), "encode_utf8");
1124

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1125
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1126
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1127
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1128
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1129
$dbi->begin_work;
1130
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1131
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1132
$dbi->rollback;
1133
$dbi->dbh->{AutoCommit} = 1;
1134

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

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

            
1139
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1140
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1141
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1142
$dbi->begin_work;
1143
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1144
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1145
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1146
$dbi->commit;
1147
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1148
$result = $dbi->select(table => $table1);
1149
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1150
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1151

            
1152
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1153
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1154
$dbi->execute($create_table1);
1155
{
1156
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1157
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1158
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1159
    like($@, qr/\.t /, "fail : not verbose");
1160
}
1161
{
1162
    local $Carp::Verbose = 1;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1163
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1164
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1165
}
1166

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

            
1172
{
1173
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1174
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1175
    like($@, qr/\Q.t /, "caller spec : not vebose");
1176
}
1177
{
1178
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1179
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1180
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1181
}
1182

            
1183

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1184
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1185
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1186
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1187
$dbi->execute($create_table1);
1188

            
1189
$dbi->begin_work;
1190

            
1191
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1192
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1193
    die "Error";
test cleanup
Yuki Kimoto authored on 2011-11-01
1194
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1195
};
1196

            
1197
$dbi->rollback if $@;
1198

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

            
1203
$dbi->begin_work;
1204

            
1205
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1206
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1207
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1208
};
1209

            
1210
$dbi->commit unless $@;
1211

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

            
1216
$dbi->dbh->{AutoCommit} = 0;
1217
eval{ $dbi->begin_work };
1218
ok($@, "exception");
1219
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1220

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1221
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1222
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1223
$dbi->cache(1);
1224
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1225
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1226
$dbi->execute($source, {}, query => 1);
1227
is_deeply($dbi->{_cached}->{$source}, 
cleanup test
Yuki Kimoto authored on 2011-08-15
1228
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1229

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1230
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1231
$dbi->execute($create_table1);
1232
$dbi->{_cached} = {};
1233
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1234
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1235
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1236

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

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

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

            
1268
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1269
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1270
    one => sub { 1 }
1271
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1272
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1273
    two => sub { 2 }
1274
);
1275
$dbi->method({
1276
    twice => sub {
1277
        my $self = shift;
1278
        return $_[0] * 2;
1279
    }
1280
});
1281

            
1282
is($dbi->one, 1, "first");
1283
is($dbi->two, 2, "second");
1284
is($dbi->twice(5), 10 , "second");
1285

            
1286
eval {$dbi->XXXXXX};
1287
ok($@, "not exists");
1288

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

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

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

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

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

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

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

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

            
1408
$result->filter({$key2 => 'twice'});
1409
$rows   = $result->all;
1410
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1411

            
1412
$result = $dbi->select(
1413
     table => [$table1, $table2],
1414
     column => [$key2, $key3],
1415
     where => {$key2 => 1, $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 : omit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1420

            
1421
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1422
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1423
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1424
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1425
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1426
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1427

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

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

            
1441
test 'end_filter';
1442
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1443
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1444
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1445
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1446
$result = $dbi->select(table => $table1);
1447
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1448
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1449
$row = $result->fetch_first;
1450
is_deeply($row, [6, 40]);
1451

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

            
1462
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1463
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1464
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1465
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1466
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1467
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1468
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1469
$row = $result->fetch_first;
1470
is_deeply($row, [6, 12]);
1471

            
1472
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1473
$result = $dbi->select(table => $table1);
1474
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1475
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1476
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1477
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1478

            
1479
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1480
$dbi->apply_filter($table1,
1481
    $key1 => {end => sub { $_[0] * 3 } },
1482
    $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1483
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1484
$result = $dbi->select(table => $table1);
1485
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1486
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1487
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1488

            
1489
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1490
$dbi->apply_filter($table1,
1491
    $key1 => {end => sub { $_[0] * 3 } },
1492
    $key2 => {end => 'five_times'}
1493
);
1494
$result = $dbi->select(table => $table1);
1495
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1496
$result->filter($key1 => undef);
1497
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1498
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1499
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1500

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

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

            
1524
test 'select query option';
1525
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1526
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1527
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1528
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1529
is(ref $query, 'DBIx::Custom::Query');
cleanup
Yuki Kimoto authored on 2011-11-01
1530
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1531
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1532
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1533
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1534
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1535
is(ref $query, 'DBIx::Custom::Query');
1536

            
1537
test 'where';
1538
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1539
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1540
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1541
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1542
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1543
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1544
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1545

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

            
1550
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1551
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1552
    where => $where
1553
);
1554
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1555
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1556

            
1557
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1558
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1559
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1560
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
1561
        {$key1 => 1}
test cleanup
Yuki Kimoto authored on 2011-08-10
1562
    ]
1563
);
1564
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1565
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1566

            
1567
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1568
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1569
             ->param({$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1570
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1571
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1572
    where => $where
1573
);
1574
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1575
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1576

            
1577
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1578
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
test cleanup
Yuki Kimoto authored on 2011-08-10
1579
             ->param({});
1580
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1581
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1582
    where => $where,
1583
);
1584
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1585
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1586

            
1587
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1588
             ->clause(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"])
1589
             ->param({$key1 => [0, 3], $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1590
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1591
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1592
    where => $where,
1593
); 
1594
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1595
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1596

            
1597
$where = $dbi->where;
1598
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1599
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1600
    where => $where
1601
);
1602
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1603
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1604

            
1605
eval {
1606
$where = $dbi->where
1607
             ->clause(['uuu']);
1608
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1609
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1610
    where => $where
1611
);
1612
};
1613
ok($@);
1614

            
1615
$where = $dbi->where;
1616
is("$where", '');
1617

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1787
eval {$dbi->where(ppp => 1) };
1788
like($@, qr/invalid/);
1789

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

            
1801

            
1802
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1803
    clause => ['and', ['or'], ['or', ":$key1", ":$key2"]],
test cleanup
Yuki Kimoto authored on 2011-08-10
1804
    param => {}
1805
);
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}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1812

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

            
1820
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1821
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1822
$where->param({$key1 => [undef, undef]});
1823
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1824
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1825
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1826
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1827
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1828
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1829

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

            
1831
$dbi = DBIx::Custom->connect;
1832
eval { $dbi->execute("drop table $table1") };
1833
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1834
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
1835
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1836
$where = $dbi->where
1837
             ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
1838
             ->param({$key1 => 1});
1839

            
1840
$result = $dbi->select(
1841
    table => $table1,
1842
    where => $where
1843
);
1844
$row = $result->all;
1845
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
1846

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1847
test 'register_tag_processor';
1848
$dbi = DBIx::Custom->connect;
1849
$dbi->register_tag_processor(
1850
    a => sub { 1 }
1851
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1852
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1853

            
1854
test 'register_tag';
1855
$dbi = DBIx::Custom->connect;
1856
$dbi->register_tag(
1857
    b => sub { 2 }
1858
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1859
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1860

            
1861
test 'table not specify exception';
1862
$dbi = DBIx::Custom->connect;
1863
eval {$dbi->select};
1864
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1865

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1866
test 'more tests';
1867
$dbi = DBIx::Custom->connect;
1868
eval{$dbi->apply_filter('table', 'column', [])};
1869
like($@, qr/apply_filter/);
1870

            
1871
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1872
like($@, qr/apply_filter/);
1873

            
1874
$dbi->apply_filter(
1875

            
1876
);
1877
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1878
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1879
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1880
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1881
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1882
$dbi->apply_filter($table1, $key2, 
test cleanup
Yuki Kimoto authored on 2011-08-10
1883
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1884
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
1885
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1886

            
1887
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1888
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1889
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1890
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1891
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1892
$dbi->apply_filter($table1, $key2, {});
1893
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1894
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1895

            
1896
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1897
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1898
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1899
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1900
like($@, qr/not registered/);
1901
$dbi->method({one => sub { 1 }});
1902
is($dbi->one, 1);
1903

            
1904
eval{DBIx::Custom->connect(dsn => undef)};
1905
like($@, qr/_connect/);
1906

            
1907
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1908
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1909
$dbi->execute($create_table1);
1910
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
1911
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1912
             filter => {$key1 => 'twice'});
1913
$row = $dbi->select(table => $table1)->one;
1914
is_deeply($row, {$key1 => 2, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
1915
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1916
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
1917
like($@, qr//);
1918

            
1919
$dbi->register_filter(one => sub { });
1920
$dbi->default_fetch_filter('one');
1921
ok($dbi->default_fetch_filter);
1922
$dbi->default_bind_filter('one');
1923
ok($dbi->default_bind_filter);
1924
eval{$dbi->default_fetch_filter('no')};
1925
like($@, qr/not registered/);
1926
eval{$dbi->default_bind_filter('no')};
1927
like($@, qr/not registered/);
1928
$dbi->default_bind_filter(undef);
1929
ok(!defined $dbi->default_bind_filter);
1930
$dbi->default_fetch_filter(undef);
1931
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1932
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1933
like($@, qr/Tag not finished/);
1934

            
1935
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1936
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1937
$dbi->execute($create_table1);
1938
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1939
$result = $dbi->select(table => $table1);
1940
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1941
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1942
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1943
like($@, qr/not registered/);
1944
$result->default_filter(undef);
1945
ok(!defined $result->default_filter);
1946
$result->default_filter('one');
1947
is($result->default_filter->(), 1);
1948

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1949
test 'option';
1950
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
1951
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
1952
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
1953
ok($dbi->dbh->{PrintError});
1954
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
1955
ok($dbi->dbh->{PrintError});
1956

            
1957
test 'DBIx::Custom::Result stash()';
1958
$result = DBIx::Custom::Result->new;
1959
is_deeply($result->stash, {}, 'default');
1960
$result->stash->{foo} = 1;
1961
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
1962

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1963
test 'delete_at';
1964
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1965
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1966
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
1967
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
1968
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1969
    table => $table1,
1970
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1971
    where => [1, 2],
1972
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1973
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1974

            
cleanup
Yuki Kimoto authored on 2011-11-01
1975
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
1976
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1977
    table => $table1,
1978
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1979
    where => 1,
1980
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1981
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1982

            
1983
test 'insert_at';
1984
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1985
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1986
$dbi->execute($create_table1_2);
1987
$dbi->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
1988
    {$key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1989
    primary_key => [$key1, $key2], 
1990
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1991
    where => [1, 2],
1992
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1993
is($dbi->select(table => $table1)->one->{$key1}, 1);
1994
is($dbi->select(table => $table1)->one->{$key2}, 2);
1995
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1996

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1997
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1998
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
1999
$dbi->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2000
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2001
    primary_key => $key1, 
2002
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2003
    where => 1,
2004
);
2005

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

            
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 in progress
Yuki Kimoto authored on 2011-08-15
2014
    {$key3 => 3},
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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2038
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2039
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2040
$dbi->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2041
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2042
    table => $table1,
2043
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2044
    where => 1,
2045
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2046
is($dbi->select(table => $table1)->one->{$key1}, 1);
2047
is($dbi->select(table => $table1)->one->{$key2}, 2);
2048
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2049

            
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 in progress
Yuki Kimoto authored on 2011-08-15
2055
    {$key3 => 4},
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

            
2064
test 'select_at';
2065
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2066
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2067
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2068
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2069
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2070
    table => $table1,
2071
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2072
    where => [1, 2]
2073
);
2074
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2075
is($row->{$key1}, 1);
2076
is($row->{$key2}, 2);
2077
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2078

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2079
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2080
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2081
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2082
    table => $table1,
2083
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2084
    where => 1,
2085
);
2086
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2087
is($row->{$key1}, 1);
2088
is($row->{$key2}, 2);
2089
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2090

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2091
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2092
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2093
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2094
    table => $table1,
2095
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2096
    where => [1, 2]
2097
);
2098
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2099
is($row->{$key1}, 1);
2100
is($row->{$key2}, 2);
2101
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2102

            
2103
test 'model delete_at';
2104
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2105
eval { $dbi->execute("drop table $table1") };
2106
eval { $dbi->execute("drop table $table2") };
2107
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2108
$dbi->execute($create_table1_2);
2109
$dbi->execute($create_table2_2);
2110
$dbi->execute($create_table3);
test cleanup
Yuki Kimoto authored on 2011-11-01
2111
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2112
$dbi->model($table1)->delete_at(where => [1, 2]);
2113
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2114
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2115
$dbi->model($table1)->delete_at(where => [1, 2]);
2116
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2117
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2118
$dbi->model($table3)->delete_at(where => [1, 2]);
2119
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2120

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

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

            
2150
test 'model select_at';
2151
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2152
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2153
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2154
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2155
$result = $dbi->model($table1)->select_at(where => [1, 2]);
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

            
2162
test 'mycolumn and column';
2163
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2164
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2165
eval { $dbi->execute("drop table $table1") };
2166
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2167
$dbi->execute($create_table1);
2168
$dbi->execute($create_table2);
2169
$dbi->separator('__');
2170
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2171
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2172
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2173
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2174
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2175
    column => [$model->mycolumn, $model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2176
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2177
);
2178
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2179
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2180

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2181
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2182
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2183
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2184
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2185
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2186
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2187
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2188
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2189
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2190
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2191
is($dbi->select(table => $table1)->one->{$key1}, 1);
2192
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2193

            
2194
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2195
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2196
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2197
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2198
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2199
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2200
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2201
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2202
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2203
is($dbi->select(table => $table1)->one->{$key1}, 1);
2204
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2205

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2209
test 'mycolumn';
2210
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2211
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2212
eval { $dbi->execute("drop table $table1") };
2213
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2214
$dbi->execute($create_table1);
2215
$dbi->execute($create_table2);
2216
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2217
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2218
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2219
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2220
$result = $model->select_at(
2221
    column => [
2222
        $model->mycolumn,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2223
        $model->column($table2)
cleanup test
Yuki Kimoto authored on 2011-08-10
2224
    ]
2225
);
2226
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2227
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2228

            
2229
$result = $model->select_at(
2230
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2231
        $model->mycolumn([$key1]),
2232
        $model->column($table2 => [$key1])
cleanup test
Yuki Kimoto authored on 2011-08-10
2233
    ]
2234
);
2235
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2236
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2237
$result = $model->select_at(
2238
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2239
        $model->mycolumn([$key1]),
2240
        {$table2 => [$key1]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2241
    ]
2242
);
2243
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2244
          {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2245

            
2246
$result = $model->select_at(
2247
    column => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2248
        $model->mycolumn([$key1]),
2249
        ["$table2.$key1", as => "$table2.$key1"]
cleanup test
Yuki Kimoto authored on 2011-08-10
2250
    ]
2251
);
2252
is_deeply($result->one,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2253
          {$key1 => 1, "$table2.$key1" => 1});
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
        ["$table2.$key1" => "$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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2264
test 'merge_param';
2265
$dbi = DBIx::Custom->new;
2266
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2267
    {$key1 => 1, $key2 => 2, $key3 => 3},
2268
    {$key1 => 1, $key2 => 2},
2269
    {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2270
];
2271
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2272
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2273

            
2274
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2275
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2276
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2277
];
2278
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2279
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
2280

            
2281
test 'select() param option';
2282
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2283
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2284
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2285
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2286
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2287
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2288
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2289
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
2290
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
2291
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2292
    table => $table1,
2293
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2294
    where   => {"$table1.$key2" => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2295
    join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
test cleanup
Yuki Kimoto authored on 2011-08-15
2296
              " $table2 on $table1.$key1 = $table2.$key1"],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2297
    param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2298
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2299
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2300

            
cleanup
Yuki Kimoto authored on 2011-10-21
2301
$rows = $dbi->select(
2302
    table => $table1,
2303
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2304
    where   => {"$table1.$key2" => 3},
2305
    join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2306
             " $table2 on $table1.$key1 = $table2.$key1",
2307
    param => {"$table2.$key3" => 5}
2308
)->all;
2309
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2310

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2311
test 'select() string where';
2312
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2313
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2314
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2315
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2316
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
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
    where => "$key1 = :$key1 and $key2 = :$key2",
2320
    where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2321
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2322
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2323

            
2324
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2325
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2326
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2327
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2328
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2329
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2330
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2331
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2332
        "$key1 = :$key1 and $key2 = :$key2",
2333
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2334
    ]
2335
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2336
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2337

            
cleanup
Yuki Kimoto authored on 2011-10-21
2338
$dbi = DBIx::Custom->connect;
2339
eval { $dbi->execute("drop table $table1") };
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
Yuki Kimoto authored on 2011-10-21
2343
$rows = $dbi->select(
2344
    table => $table1,
2345
    where => [
2346
        "$key1 = :$key1 and $key2 = :$key2",
2347
        {$key1 => 1, $key2 => 2}
2348
    ]
2349
)->all;
2350
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2351

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

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

            
2381

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

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

            
2411
test 'insert id and primary_key option';
2412
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2413
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2414
$dbi->execute($create_table1_2);
2415
$dbi->insert(
cleanup
Yuki Kimoto authored on 2011-11-01
2416
    {$key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2417
    primary_key => [$key1, $key2], 
2418
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2419
    id => [1, 2],
2420
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2421
is($dbi->select(table => $table1)->one->{$key1}, 1);
2422
is($dbi->select(table => $table1)->one->{$key2}, 2);
2423
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2424

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2425
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2426
$dbi->insert(
cleanup
Yuki Kimoto authored on 2011-11-01
2427
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2428
    primary_key => $key1, 
2429
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2430
    id => 0,
2431
);
2432

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2437
$dbi = DBIx::Custom->connect;
2438
eval { $dbi->execute("drop table $table1") };
2439
$dbi->execute($create_table1_2);
2440
$dbi->insert(
2441
    {$key3 => 3},
2442
    primary_key => [$key1, $key2], 
2443
    table => $table1,
2444
    id => 1,
2445
);
2446
is($dbi->select(table => $table1)->one->{$key1}, 1);
2447
ok(!$dbi->select(table => $table1)->one->{$key2});
2448
is($dbi->select(table => $table1)->one->{$key3}, 3);
2449

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2450
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2451
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2452
$dbi->execute($create_table1_2);
2453
$dbi->insert(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2454
    {$key3 => 3},
2455
    primary_key => [$key1, $key2], 
2456
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2457
    id => [1, 2],
2458
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2459
is($dbi->select(table => $table1)->one->{$key1}, 1);
2460
is($dbi->select(table => $table1)->one->{$key2}, 2);
2461
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2462

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2463
$dbi = DBIx::Custom->connect;
2464
eval { $dbi->execute("drop table $table1") };
2465
$dbi->execute($create_table1_2);
2466
$param = {$key3 => 3, $key2 => 4};
2467
$dbi->insert(
2468
    $param,
2469
    primary_key => [$key1, $key2], 
2470
    table => $table1,
2471
    id => [1, 2],
2472
);
2473
is($dbi->select(table => $table1)->one->{$key1}, 1);
2474
is($dbi->select(table => $table1)->one->{$key2}, 4);
2475
is($dbi->select(table => $table1)->one->{$key3}, 3);
2476
is_deeply($param, {$key3 => 3, $key2 => 4});
2477

            
added test
Yuki Kimoto authored on 2011-10-25
2478
$dbi = DBIx::Custom->connect;
2479
eval { $dbi->execute("drop table $table1") };
2480
$dbi->execute($create_table1_2);
2481
$param = {$key3 => 3, $key2 => 4};
2482
$query = $dbi->insert(
2483
    $param,
2484
    primary_key => [$key1, $key2], 
2485
    table => $table1,
2486
    id => [1, 2],
2487
    query => 1
2488
);
2489
is(ref $query, 'DBIx::Custom::Query');
2490
is_deeply($param, {$key3 => 3, $key2 => 4});
2491

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2492
test 'model insert id and primary_key option';
2493
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2494
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2495
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2496
$dbi->model($table1)->insert(
cleanup
Yuki Kimoto authored on 2011-11-01
2497
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2498
    id => [1, 2],
2499
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2500
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2501
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2502
is($row->{$key1}, 1);
2503
is($row->{$key2}, 2);
2504
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2505

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2534
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2535
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2536
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2537
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2538
    table => $table1,
2539
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2540
    id => 0,
2541
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2542
is($dbi->select(table => $table1)->one->{$key1}, 0);
2543
is($dbi->select(table => $table1)->one->{$key2}, 2);
2544
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2545

            
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(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2551
    {$key3 => 4},
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

            
2560

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

            
2576

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

            
cleanup
Yuki Kimoto authored on 2011-11-01
2589
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2590
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2591
    table => $table1,
2592
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2593
    id => 0,
2594
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2595
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2596

            
2597

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

            
2616

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2644
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2645
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2646
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2647
    table => $table1,
2648
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2649
    id => [1, 2]
2650
);
2651
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2652
is($row->{$key1}, 1);
2653
is($row->{$key2}, 2);
2654
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2655

            
2656

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

            
2668
test 'column separator is default .';
2669
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2670
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2671
eval { $dbi->execute("drop table $table1") };
2672
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2673
$dbi->execute($create_table1);
2674
$dbi->execute($create_table2);
2675
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2676
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2677
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2678
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2679
$result = $model->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2680
    column => [$model->column($table2)],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2681
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2682
);
2683
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2684
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2685

            
2686
$result = $model->select(
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2687
    column => [$model->column($table2 => [$key1, $key3])],
2688
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2689
);
2690
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2691
          {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2692

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2693
test 'separator';
2694
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2695
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2696
eval { $dbi->execute("drop table $table1") };
2697
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2698
$dbi->execute($create_table1);
2699
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2700

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2701
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2702
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2703
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2704
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2705
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2706
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2707
);
2708
$model2 = $dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2709
    table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2710
);
2711
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2712
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2713
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2714
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2715
$result = $model->select(
2716
    column => [
2717
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2718
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2719
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2720
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2721
);
2722
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2723
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
2724
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2725

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2726
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2727
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2728
$result = $model->select(
2729
    column => [
2730
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2731
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2732
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2733
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2734
);
2735
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2736
          {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
2737
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2738

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2739
$dbi->separator('-');
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

            
2752

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2761
$dbi->create_model(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2762
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2763
    join => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2764
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
cleanup test
Yuki Kimoto authored on 2011-08-10
2765
    ],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2766
    primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2767
);
2768
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2769
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2770
$model = $dbi->model($table1);
2771
$result = $model->select(column => $key1);
2772
$result->filter($key1 => sub { $_[0] * 2 });
2773
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2774

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2775
test 'available_datetype';
2776
$dbi = DBIx::Custom->connect;
2777
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2778

            
2779

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2780
test 'select prefix option';
2781
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2782
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2783
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2784
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2785
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2786
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2787

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

            
added tests
Yuki Kimoto authored on 2011-08-26
2789
test 'mapper';
2790
$dbi = DBIx::Custom->connect;
2791
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2792
    id => {key => "$table1.id"},
2793
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2794
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
2795
);
2796
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2797
  "$table1.price" => 1900});
2798

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2799
$dbi = DBIx::Custom->connect;
2800
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2801
    id => {key => "$table1.id"},
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2802
    author => ["$table1.author" => $dbi->like_value],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2803
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2804
);
2805
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2806
  "$table1.price" => 1900});
2807

            
added tests
Yuki Kimoto authored on 2011-08-26
2808
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2809
    id => {key => "$table1.id"},
2810
    author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2811
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
2812
);
2813
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2814

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

            
2822
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2823
    id => {key => "$table1.id"},
2824
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2825
);
2826
is_deeply($param, {"$table1.price" => undef});
2827

            
2828
$param = $dbi->mapper(param => {price => 'a'})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2829
    id => {key => "$table1.id", condition => 'exists'},
2830
    price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
2831
);
2832
is_deeply($param, {"$table1.price" => '%a'});
2833

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

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2840
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
2841
    price => sub { '%' . $_[0] },
2842
    author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2843
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2844
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2845

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

            
2851
$where = $dbi->where;
2852
$where->clause(['and', ":${key1}{=}"]);
2853
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
2854
$where->param($param);
2855
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2856
$row = $result->all;
2857
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2858

            
2859
$where = $dbi->where;
2860
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2861
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
2862
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2863
$row = $result->all;
2864
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2865
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2866
$row = $result->all;
2867
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2868

            
2869
$where = $dbi->where;
2870
$where->clause(['and', ":${key1}{=}"]);
2871
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
2872
$where->param($param);
2873
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2874
$row = $result->all;
2875
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2876
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2877
$row = $result->all;
2878
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2879

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2881
$where = $dbi->where;
2882
$where->clause(['and', ":${key1}{=}"]);
2883
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
2884
  ->pass([$key1, $key2])->map;
2885
$where->param($param);
2886
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2887
$row = $result->all;
2888
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2889

            
2890
$where = $dbi->where;
2891
$where->clause(['and', ":${key1}{=}"]);
2892
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
2893
$where->param($param);
2894
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2895
$row = $result->all;
2896
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2897

            
2898
$where = $dbi->where;
2899
$where->clause(['and', ":${key1}{=}"]);
2900
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
2901
  ->pass([$key1, $key2])->map;
2902
$where->param($param);
2903
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2904
$row = $result->all;
2905
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2906

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

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

            
2916
$where = $dbi->where;
2917
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2918
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2919
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2920
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2921
);
2922
$where->param($param);
2923
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
2924
  "$table1.price" => 1900});
2925

            
2926
$where = $dbi->where;
2927
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2928
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2929
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2930
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2931
);
2932
$where->param($param);
2933
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2934

            
2935
$where = $dbi->where;
2936
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2937
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2938
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2939
    price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2940
);
2941
$where->param($param);
2942
is_deeply($where->param, {});
2943

            
2944
$where = $dbi->where;
2945
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2946
    id => {key => "$table1.id"},
2947
    price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2948
);
2949
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
2950

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

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

            
2967
$where = $dbi->where;
2968
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900}, condition => 'length')->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2969
    id => {key => "$table1.id"},
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2970
    author => ["$table1.author", sub { '%' . $_[0] . '%' }],
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2971
    price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2972
);
2973
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
2974
  "$table1.price" => 1900});
2975

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2990
test 'order';
2991
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2992
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2993
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2994
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
2995
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
2996
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
2997
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2998
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2999
$order->prepend($key1, "$key2 desc");
3000
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3001
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
3002
  {$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3003
$order->prepend("$key1 desc");
3004
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3005
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
3006
  {$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3007

            
3008
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3009
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3010
$result = $dbi->select(table => $table1,
3011
  column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3012
  append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3013
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
3014
  {"$table1-$key1" => 1, "$table1-$key2" => 1},
3015
  {"$table1-$key1" => 2, "$table1-$key2" => 4},
3016
  {"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3017

            
3018
test 'tag_parse';
3019
$dbi = DBIx::Custom->connect;
3020
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3021
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3022
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3023
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3024
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3025
ok($@);
3026

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3027
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3028
{
3029
    $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3030
    $dbi = DBIx::Custom->connect;
3031
    eval { $dbi->execute("drop table $table1") };
3032
    $dbi->execute($create_table1);
3033
    $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3034
    eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3035
    ok($@);
3036
    delete$ENV{DBIX_CUSTOM_TAG_PARSE};
3037
}
3038

            
3039
{
3040
    $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3041
    $dbi = DBIx::Custom->connect;
3042
    eval { $dbi->execute("drop table $table1") };
3043
    $dbi->execute($create_table1);
3044
    $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3045
    is($dbi->select(table => $table1)->one->{$key1}, 1);
3046
    delete$ENV{DBIX_CUSTOM_TAG_PARSE};
3047
}
3048

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3049
test 'last_sql';
3050
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3051
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3052
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3053
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
3054
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3055

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3087
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3088
$result = $dbi->execute(
3089
    $source,
cleanup
Yuki Kimoto authored on 2011-11-01
3090
    {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3091
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3092
);
3093
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3094
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3095

            
3096
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3097
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3098
$dbi->execute($create_table1_highperformance);
3099
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3100
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3101
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3102
];
3103
{
3104
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3105
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3106
      $query ||= $dbi->insert($row, table => $table1, query => 1);
3107
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
3108
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3109
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3110
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3111
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3112
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3113
      ]
3114
    );
3115
}
3116

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3117
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3118
$dbi->execute($create_table1_highperformance);
3119
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3120
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3121
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3122
];
3123
{
3124
    my $query;
3125
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
3126
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3127
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3128
      $sth ||= $query->sth;
3129
      $sth->execute(map { $row->{$_} } sort keys %$row);
3130
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3131
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3132
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3133
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3134
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3135
      ]
3136
    );
3137
}
3138

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3139
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3140
$dbi->execute($create_table1_highperformance);
3141
$rows = [
3142
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
3143
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
3144
];
3145
{
3146
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3147
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3148
    for my $row (@$rows) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3149
      $query ||= $model->insert($row, query => 1);
3150
      $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3151
    }
3152
    is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3153
      [
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3154
          {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3155
          {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3156
      ]
3157
    );
3158
}
3159

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3160
eval { $dbi->execute("drop table $table1") };
3161
$dbi->execute($create_table1);
3162
{
3163
    $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3164
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3165
    eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3166
    like($@, qr/primary_key/);
3167
    delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
3168
}
3169

            
3170
{
3171
    $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3172
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3173
    $model->insert({$key1 => 1});
3174
    $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3175
      table => $table1, primary_key => $key1);
3176
    is($result->one->{$key1}, 1);
3177
    delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
3178
}
3179

            
3180
eval { $dbi->execute("drop table $table1") };
3181
$dbi->execute($create_table1);
3182
{
3183
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3184
    $model->insert({$key1 => 1});
3185
    eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3186
    is($result->one->{$key1}, 1);
3187
}
3188

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3189
test 'id option more';
3190
eval { $dbi->execute("drop table $table1") };
3191
$dbi->execute($create_table1_highperformance);
3192
$row = {
3193
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3194
};
3195
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3196
$model->insert($row);
3197
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3198
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3199
is_deeply($dbi->select(table => $table1)->one,
3200
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3201
);
3202

            
3203
eval { $dbi->execute("drop table $table1") };
3204
eval { $dbi->execute("drop table $table2") };
3205
$dbi->execute($create_table1);
3206
$dbi->execute($create_table2);
3207
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3208
$model->insert({$key1 => 1, $key2 => 2});
3209
$model = $dbi->create_model(table => $table2, primary_key => $key1,
3210
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
3211
$model->insert({$key1 => 1, $key3 => 3});
3212
$result = $model->select(
3213
    column => {$table1 => ["$key2"]},
3214
    id => 1
3215
);
3216
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3217

            
3218
eval { $dbi->execute("drop table $table1") };
3219
$dbi->execute($create_table1_highperformance);
3220
$row = {
3221
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3222
};
3223
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3224
$model->insert($row);
3225
$query = $model->delete(id => 1, query => 1);
3226
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3227
is_deeply($dbi->select(table => $table1)->all, []);
3228

            
3229
eval { $dbi->execute("drop table $table1") };
3230
eval { $dbi->execute($create_table1_highperformance) };
3231
$row = {
3232
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3233
};
3234
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3235
$model->insert($row);
3236
$query = $model->select(id => 1, query => 1);
3237
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3238
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3239
is_deeply($dbi->select(table => $table1)->one,
3240
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3241
);
3242

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3243
test 'result';
3244
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3245
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3246
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3247
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3248
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3249

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3250
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3251
@rows = ();
3252
while (my $row = $result->fetch) {
3253
    push @rows, [@$row];
3254
}
3255
is_deeply(\@rows, [[1, 2], [3, 4]]);
3256

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3257
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3258
@rows = ();
3259
while (my $row = $result->fetch_hash) {
3260
    push @rows, {%$row};
3261
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3262
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3263

            
3264
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3265
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3266
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3267
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3268
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3269

            
3270
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3271
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3272
$rows = $result->fetch_all;
3273
is_deeply($rows, [[1, 2], [3, 4]]);
3274

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3279
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3280
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3281
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3282

            
3283
$rows = $result->fetch_all;
3284
is_deeply($rows, [[3, 2], [9, 4]], "array");
3285

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

            
3292
test "query_builder";
3293
$datas = [
3294
    # Basic tests
3295
    {   name            => 'placeholder basic',
3296
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3297
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3298
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3299
    },
3300
    {
3301
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3302
        source            => "{in k1 3}",
3303
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3304
        columns_expected   => [qw/k1 k1 k1/]
3305
    },
3306
    
3307
    # Table name
3308
    {
3309
        name            => 'placeholder with table name',
3310
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3311
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3312
        columns_expected  => [qw/a.k1 a.k2/]
3313
    },
3314
    {   
3315
        name            => 'placeholder in with table name',
3316
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3317
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3318
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3319
    },
3320
    {
3321
        name            => 'not contain tag',
3322
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3323
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3324
        columns_expected  => [],
3325
    }
3326
];
3327

            
3328
for (my $i = 0; $i < @$datas; $i++) {
3329
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3330
    my $dbi = DBIx::Custom->new;
3331
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3332
    my $query = $builder->build_query($data->{source});
3333
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3334
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3335
}
3336

            
cleanup
Yuki Kimoto authored on 2011-08-13
3337
$dbi = DBIx::Custom->new;
3338
$builder = $dbi->query_builder;
3339
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3340
    p => sub {
3341
        my @args = @_;
3342
        
3343
        my $expand    = "? $args[0] $args[1]";
3344
        my $columns = [2];
3345
        return [$expand, $columns];
3346
    }
3347
);
3348

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3359
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3360
    q => 'string'
3361
});
3362

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3366
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3367
   r => sub {} 
3368
});
3369

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3373
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3374
   s => sub { return ["a", ""]} 
3375
});
3376

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3380
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3381
    t => sub {return ["a", []]}
3382
);
3383

            
3384

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

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

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

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

            
3400
test 'variouse source';
3401
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3402
$query = $builder->build_query($source);
3403
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3404

            
3405
$source = "abc";
3406
$query = $builder->build_query($source);
3407
is($query->sql, 'abc', "basic : 2");
3408

            
3409
$source = "{= a}";
3410
$query = $builder->build_query($source);
3411
is($query->sql, 'a = ?', "only tag");
3412

            
3413
$source = "000";
3414
$query = $builder->build_query($source);
3415
is($query->sql, '000', "contain 0 value");
3416

            
3417
$source = "a {= b} }";
3418
eval{$builder->build_query($source)};
3419
like($@, qr/unexpected "}"/, "error : 1");
3420

            
3421
$source = "a {= {}";
3422
eval{$builder->build_query($source)};
3423
like($@, qr/unexpected "{"/, "error : 2");
3424

            
3425
test 'select() sqlfilter option';
3426
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3427
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3428
eval { $dbi->execute("drop table $table1") };
3429
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3430
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3431
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3432
$rows = $dbi->select(
3433
    table => $table1,
3434
    column => $key1,
3435
    sqlfilter => sub {
3436
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
3437
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
3438
        return $sql;
3439
    }
3440
)->all;
3441
is_deeply($rows, [{$key1 => 1}]);
3442

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3443
test 'select() after_build_sql option';
3444
$dbi = DBIx::Custom->connect;
3445
$dbi->user_table_info($user_table_info);
3446
eval { $dbi->execute("drop table $table1") };
3447
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3448
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3449
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3450
$rows = $dbi->select(
3451
    table => $table1,
3452
    column => $key1,
3453
    after_build_sql => sub {
3454
        my $sql = shift;
3455
        $sql = "select * from ( $sql ) t where $key1 = 1";
3456
        return $sql;
3457
    }
3458
)->all;
3459
is_deeply($rows, [{$key1 => 1}]);
3460

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3461
test 'dbi method from model';
3462
$dbi = MyDBI9->connect;
3463
eval { $dbi->execute("drop table $table1") };
3464
$dbi->execute($create_table1);
3465
$dbi->setup_model;
3466
$model = $dbi->model($table1);
3467
eval{$model->execute("select * from $table1")};
3468
ok(!$@);
3469

            
3470
test 'column table option';
3471
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3472
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3473
eval { $dbi->execute("drop table $table1") };
3474
$dbi->execute($create_table1);
3475
eval { $dbi->execute("drop table $table2") };
3476
$dbi->execute($create_table2);
3477
$dbi->setup_model;
3478
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3479
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3480
$model = $dbi->model($table1);
3481
$result = $model->select(
3482
    column => [
3483
        $model->column($table2, {alias => $table2_alias})
3484
    ],
3485
    where => {"$table2_alias.$key3" => 4}
3486
);
3487
is_deeply($result->one, 
3488
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3489

            
3490
$dbi->separator('__');
3491
$result = $model->select(
3492
    column => [
3493
        $model->column($table2, {alias => $table2_alias})
3494
    ],
3495
    where => {"$table2_alias.$key3" => 4}
3496
);
3497
is_deeply($result->one, 
3498
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3499

            
3500
$dbi->separator('-');
3501
$result = $model->select(
3502
    column => [
3503
        $model->column($table2, {alias => $table2_alias})
3504
    ],
3505
    where => {"$table2_alias.$key3" => 4}
3506
);
3507
is_deeply($result->one, 
3508
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3509

            
3510
test 'create_model';
3511
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3512
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3513
eval { $dbi->execute("drop table $table1") };
3514
eval { $dbi->execute("drop table $table2") };
3515
$dbi->execute($create_table1);
3516
$dbi->execute($create_table2);
3517

            
3518
$dbi->create_model(
3519
    table => $table1,
3520
    join => [
3521
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3522
    ],
3523
    primary_key => [$key1]
3524
);
3525
$model2 = $dbi->create_model(
3526
    table => $table2
3527
);
3528
$dbi->create_model(
3529
    table => $table3,
3530
    filter => [
3531
        $key1 => {in => sub { uc $_[0] }}
3532
    ]
3533
);
3534
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3535
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3536
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3537
$model = $dbi->model($table1);
3538
$result = $model->select(
3539
    column => [$model->mycolumn, $model->column($table2)],
3540
    where => {"$table1.$key1" => 1}
3541
);
3542
is_deeply($result->one,
3543
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3544
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3545

            
3546
test 'model method';
3547
$dbi = DBIx::Custom->connect;
3548
eval { $dbi->execute("drop table $table2") };
3549
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3550
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3551
$model = $dbi->create_model(
3552
    table => $table2
3553
);
3554
$model->method(foo => sub { shift->select(@_) });
3555
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3556

            
3557
test 'model helper';
3558
$dbi = DBIx::Custom->connect;
3559
eval { $dbi->execute("drop table $table2") };
3560
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3561
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3562
$model = $dbi->create_model(
3563
    table => $table2
3564
);
3565
$model->helper(foo => sub { shift->select(@_) });
3566
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3567

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

            
3575
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3576
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3577
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3578
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3579
where $key1 = 1
3580
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3581
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3582
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3583
$rows   = $result->all;
3584
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3585
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3586
                  "basic");
3587

            
3588

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

            
3595
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3596
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3597
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3598
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3599
where $key1 = 1
3600
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3601
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3602
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3603
$rows   = $result->all;
3604
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3605
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3606
                  "basic");
3607

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

            
3614
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3615
$assign_clause = $dbi->update_param($param, {no_set => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
3616
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3617
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3618
where $key1 = 1
3619
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3620
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3621
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3622
$rows   = $result->all;
3623
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3624
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3625
                  "update param no_set");
3626

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3663
test 'Model class';
3664
$dbi = MyDBI1->connect;
3665
eval { $dbi->execute("drop table $table1") };
3666
$dbi->execute($create_table1);
3667
$model = $dbi->model($table1);
3668
$model->insert({$key1 => 'a', $key2 => 'b'});
3669
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3670
eval { $dbi->execute("drop table $table2") };
3671
$dbi->execute($create_table2);
3672
$model = $dbi->model($table2);
3673
$model->insert({$key1 => 'a'});
3674
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3675
is($dbi->models->{$table1}, $dbi->model($table1));
3676
is($dbi->models->{$table2}, $dbi->model($table2));
3677

            
3678
$dbi = MyDBI4->connect;
3679
eval { $dbi->execute("drop table $table1") };
3680
$dbi->execute($create_table1);
3681
$model = $dbi->model($table1);
3682
$model->insert({$key1 => 'a', $key2 => 'b'});
3683
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3684
eval { $dbi->execute("drop table $table2") };
3685
$dbi->execute($create_table2);
3686
$model = $dbi->model($table2);
3687
$model->insert({$key1 => 'a'});
3688
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3689

            
3690
$dbi = MyDBI5->connect;
3691
eval { $dbi->execute("drop table $table1") };
3692
eval { $dbi->execute("drop table $table2") };
3693
$dbi->execute($create_table1);
3694
$dbi->execute($create_table2);
3695
$model = $dbi->model($table2);
3696
$model->insert({$key1 => 'a'});
3697
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
3698
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3699
$model = $dbi->model($table1);
3700
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3701

            
3702
test 'primary_key';
3703
$dbi = MyDBI1->connect;
3704
$model = $dbi->model($table1);
3705
$model->primary_key([$key1, $key2]);
3706
is_deeply($model->primary_key, [$key1, $key2]);
3707

            
3708
test 'columns';
3709
$dbi = MyDBI1->connect;
3710
$model = $dbi->model($table1);
3711
$model->columns([$key1, $key2]);
3712
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3713

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3714
test 'setup_model';
3715
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3716
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3717
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3718
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3719

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3720
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3721
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3722
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3723
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3724
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3725

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3726
test 'each_column';
3727
$dbi = DBIx::Custom->connect;
3728
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3729
eval { $dbi->execute("drop table $table1") };
3730
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3731
eval { $dbi->execute("drop table $table3") };
3732
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3733
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3734

            
3735
$infos = [];
3736
$dbi->each_column(sub {
3737
    my ($self, $table, $column, $cinfo) = @_;
3738
    
3739
    if ($table =~ /^table\d/i) {
3740
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3741
         push @$infos, $info;
3742
    }
3743
});
3744
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3745
is_deeply($infos, 
3746
    [
3747
        [$table1, $key1, $key1],
3748
        [$table1, $key2, $key2],
3749
        [$table2, $key1, $key1],
3750
        [$table2, $key3, $key3]
3751
    ]
3752
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3753
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3754

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3755
test 'each_table';
3756
$dbi = DBIx::Custom->connect;
3757
eval { $dbi->execute("drop table $table1") };
3758
eval { $dbi->execute("drop table $table2") };
3759
$dbi->execute($create_table2);
3760
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3761

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3762
$infos = [];
3763
$dbi->each_table(sub {
3764
    my ($self, $table, $table_info) = @_;
3765
    
3766
    if ($table =~ /^table\d/i) {
3767
         my $info = [$table, $table_info->{TABLE_NAME}];
3768
         push @$infos, $info;
3769
    }
3770
});
3771
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3772
is_deeply($infos, 
3773
    [
3774
        [$table1, $table1],
3775
        [$table2, $table2],
3776
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3777
);
3778

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3779
$dbi = DBIx::Custom->connect;
3780
eval { $dbi->execute("drop table $table1") };
3781
eval { $dbi->execute("drop table $table2") };
3782
$dbi->execute($create_table2);
3783
$dbi->execute($create_table1_type);
3784

            
3785
$infos = [];
3786
$dbi->user_table_info($user_table_info);
3787
$dbi->each_table(sub {
3788
    my ($self, $table, $table_info) = @_;
3789
    
3790
    if ($table =~ /^table\d/i) {
3791
         my $info = [$table, $table_info->{TABLE_NAME}];
3792
         push @$infos, $info;
3793
    }
3794
});
3795
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3796
is_deeply($infos, 
3797
    [
3798
        [$table1, $table1],
3799
        [$table2, $table2],
3800
        [$table3, $table3],
3801
    ]
3802
);
3803

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3804
test 'type_rule into';
3805
eval { $dbi->execute("drop table $table1") };
3806
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3807
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3808

            
3809

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3810
$dbi = DBIx::Custom->connect;
3811
eval { $dbi->execute("drop table $table1") };
3812
$dbi->execute($create_table1_type);
3813

            
cleanup
Yuki Kimoto authored on 2011-08-16
3814
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3815
$dbi->type_rule(
3816
    into1 => {
3817
        $date_typename => sub { '2010-' . $_[0] }
3818
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3819
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3820
$dbi->insert({$key1 => '01-01'}, table => $table1);
3821
$result = $dbi->select(table => $table1);
3822
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3823

            
3824
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3825
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3826
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3827
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3828
$dbi->type_rule(
3829
    into1 => [
3830
         [$date_typename, $datetime_typename] => sub {
3831
            my $value = shift;
3832
            $value =~ s/02/03/g;
3833
            return $value;
3834
         }
3835
    ]
3836
);
3837
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3838
$result = $dbi->select(table => $table1);
3839
$row = $result->one;
3840
like($row->{$key1}, qr/^2010-01-03/);
3841
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3842

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3843
$dbi = DBIx::Custom->connect;
3844
eval { $dbi->execute("drop table $table1") };
3845
$dbi->execute($create_table1_type);
3846
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3847
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3848
$dbi->type_rule(
3849
    into1 => [
3850
        [$date_typename, $datetime_typename] => sub {
3851
            my $value = shift;
3852
            $value =~ s/02/03/g;
3853
            return $value;
3854
        }
3855
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3856
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3857
$result = $dbi->execute(
3858
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
3859
    {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
3860
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3861
$row = $result->one;
3862
like($row->{$key1}, qr/^2010-01-03/);
3863
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3864

            
3865
$dbi = DBIx::Custom->connect;
3866
eval { $dbi->execute("drop table $table1") };
3867
$dbi->execute($create_table1_type);
3868
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3869
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3870
$dbi->type_rule(
3871
    into1 => [
3872
        [$date_typename, $datetime_typename] => sub {
3873
            my $value = shift;
3874
            $value =~ s/02/03/g;
3875
            return $value;
3876
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3877
    ]
3878
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3879
$result = $dbi->execute(
3880
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
3881
    {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
cleanup test
Yuki Kimoto authored on 2011-08-15
3882
    table => $table1
3883
);
3884
$row = $result->one;
3885
like($row->{$key1}, qr/^2010-01-03/);
3886
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3887

            
3888
$dbi = DBIx::Custom->connect;
3889
eval { $dbi->execute("drop table $table1") };
3890
$dbi->execute($create_table1_type);
3891
$dbi->register_filter(convert => sub {
3892
    my $value = shift || '';
3893
    $value =~ s/02/03/;
3894
    return $value;
3895
});
cleanup
Yuki Kimoto authored on 2011-08-16
3896
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3897
$dbi->type_rule(
3898
    from1 => {
3899
        $date_datatype => 'convert',
3900
    },
3901
    into1 => {
3902
        $date_typename => 'convert',
3903
    }
3904
);
3905
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3906
$result = $dbi->select(table => $table1);
3907
like($result->fetch->[0], qr/^2010-03-03/);
3908

            
3909
test 'type_rule and filter order';
3910
$dbi = DBIx::Custom->connect;
3911
eval { $dbi->execute("drop table $table1") };
3912
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3913
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3914
$dbi->type_rule(
3915
    into1 => {
3916
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3917
    },
3918
    into2 => {
3919
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3920
    },
3921
    from1 => {
3922
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3923
    },
3924
    from2 => {
3925
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
3926
    }
3927
);
3928
$dbi->insert({$key1 => '2010-01-03'}, 
3929
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
3930
$result = $dbi->select(table => $table1);
3931
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3932
like($result->fetch_first->[0], qr/^2010-01-09/);
3933

            
3934

            
3935
$dbi = DBIx::Custom->connect;
3936
eval { $dbi->execute("drop table $table1") };
3937
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3938
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3939
$dbi->type_rule(
3940
    from1 => {
3941
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3942
    },
3943
    from2 => {
3944
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3945
    },
3946
);
3947
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3948
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3949
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3950
$result->type_rule(
3951
    from1 => {
3952
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3953
    },
3954
    from2 => {
3955
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3956
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3957
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3958
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3959
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3960

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3961
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
3962
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
3963
eval { $dbi->execute("drop table $table1") };
3964
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3965
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3966
$dbi->type_rule(
3967
    from1 => {
3968
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3969
    },
3970
    into1 => {
3971
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3972
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3973
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3974
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3975
$result = $dbi->select(table => $table1, type_rule_off => 1);
3976
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3977

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3978
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3979
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3980
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3981
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3982
$dbi->type_rule(
3983
    from1 => {
3984
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3985
    },
3986
    into1 => {
3987
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3988
    }
3989
);
3990
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3991
$result = $dbi->select(table => $table1, type_rule_off => 1);
3992
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3993

            
3994
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3995
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3996
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3997
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3998
$dbi->type_rule(
3999
    from1 => {
4000
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4001
    },
4002
    into1 => {
4003
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4004
    }
4005
);
4006
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4007
$result = $dbi->select(table => $table1);
4008
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4009

            
4010
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4011
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4012
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4013
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4014
$dbi->type_rule(
4015
    from1 => {
4016
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4017
    },
4018
    into1 => {
4019
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4020
    }
4021
);
4022
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4023
$result = $dbi->select(table => $table1);
4024
like($result->fetch->[0], qr/2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4025

            
4026
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4027
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4028
$dbi->execute($create_table1_type);
4029
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
4030
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4031
$dbi->type_rule(
4032
    into1 => {
4033
        $date_typename => 'ppp'
4034
    }
4035
);
4036
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4037
$result = $dbi->select(table => $table1);
4038
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4039

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4040
eval{$dbi->type_rule(
4041
    into1 => {
4042
        $date_typename => 'pp'
4043
    }
4044
)};
4045
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4046

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4047
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4048
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4049
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4050
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
4051
    $dbi->type_rule(
4052
        from1 => {
4053
            Date => sub { $_[0] * 2 },
4054
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
4055
    );
4056
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4057
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4058

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4059
eval {
4060
    $dbi->type_rule(
4061
        into1 => {
4062
            Date => sub { $_[0] * 2 },
4063
        }
4064
    );
4065
};
4066
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4067

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

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

            
4106
$result = $dbi->select(table => $table1);
4107
$result->type_rule(
4108
    from1 => {
4109
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4110
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4111
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4112
$row = $result->one;
4113
like($row->{$key1}, qr/2010-01-05/);
4114
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4115

            
4116
$result = $dbi->select(table => $table1);
4117
$result->type_rule(
4118
    from1 => {
4119
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4120
    }
4121
);
4122
$row = $result->one;
4123
like($row->{$key1}, qr/2010-01-05/);
4124
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4125

            
4126
$result = $dbi->select(table => $table1);
4127
$result->type_rule(
4128
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
4129
);
4130
$row = $result->one;
4131
like($row->{$key1}, qr/2010-01-05/);
4132
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4133

            
4134
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4135
$result = $dbi->select(table => $table1);
4136
$result->type_rule(
4137
    from1 => [$date_datatype => 'five']
4138
);
4139
$row = $result->one;
4140
like($row->{$key1}, qr/^2010-01-05/);
4141
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4142

            
4143
$result = $dbi->select(table => $table1);
4144
$result->type_rule(
4145
    from1 => [$date_datatype => undef]
4146
);
4147
$row = $result->one;
4148
like($row->{$key1}, qr/^2010-01-03/);
4149
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4150

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4179
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4180
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4181
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4182
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4183
$dbi->type_rule(
4184
    into1 => {
4185
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4186
    },
4187
    into2 => {
4188
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4189
    },
4190
    from1 => {
4191
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4192
    },
4193
    from2 => {
4194
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4195
    }
4196
);
4197
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4198
$result = $dbi->select(table => $table1);
4199
like($result->type_rule_off->fetch_first->[0], qr/^2010-01-03/);
4200
$result = $dbi->select(table => $table1);
4201
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4202

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4203
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4204
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4205
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4206
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4207
$dbi->type_rule(
4208
    into1 => {
4209
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4210
    },
4211
    into2 => {
4212
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4213
    },
4214
    from1 => {
4215
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
4216
    },
4217
    from2 => {
4218
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4219
    }
4220
);
4221
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4222
$result = $dbi->select(table => $table1);
4223
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/);
4224
$result = $dbi->select(table => $table1);
4225
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4226

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4227
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4228
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4229
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4230
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4231
$dbi->type_rule(
4232
    into1 => {
4233
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4234
    },
4235
    into2 => {
4236
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4237
    },
4238
    from1 => {
4239
        $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4240
    },
4241
    from2 => {
4242
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4243
    }
4244
);
4245
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4246
$result = $dbi->select(table => $table1);
4247
like($result->type_rule2_off->fetch_first->[0], qr/^2010-01-06/);
4248
$result = $dbi->select(table => $table1);
4249
like($result->type_rule2_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4250

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4251
test 'join';
4252
$dbi = DBIx::Custom->connect;
4253
eval { $dbi->execute("drop table $table1") };
4254
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4255
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4256
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4257
eval { $dbi->execute("drop table $table2") };
4258
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4259
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4260
eval { $dbi->execute("drop table $table3") };
4261
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4262
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4263
$rows = $dbi->select(
4264
    table => $table1,
4265
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4266
    where   => {"$table1.$key2" => 2},
4267
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4268
)->all;
4269
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4270

            
4271
$dbi = DBIx::Custom->connect;
4272
eval { $dbi->execute("drop table $table1") };
4273
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4274
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4275
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4276
eval { $dbi->execute("drop table $table2") };
4277
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4278
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4279
eval { $dbi->execute("drop table $table3") };
4280
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4281
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4282
$rows = $dbi->select(
4283
    table => $table1,
4284
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4285
    where   => {"$table1.$key2" => 2},
4286
    join  => {
4287
        clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4288
        table => [$table1, $table2]
4289
    }
4290
)->all;
4291
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
4292

            
4293
$rows = $dbi->select(
4294
    table => $table1,
4295
    where   => {$key1 => 1},
4296
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4297
)->all;
4298
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4299

            
4300
$rows = $dbi->select(
4301
    table => $table1,
4302
    where   => {$key1 => 1},
4303
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4304
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4305
)->all;
4306
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4307

            
4308
$rows = $dbi->select(
4309
    column => "$table3.$key4 as ${table3}__$key4",
4310
    table => $table1,
4311
    where   => {"$table1.$key1" => 1},
4312
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4313
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4314
)->all;
4315
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4316

            
4317
$rows = $dbi->select(
4318
    column => "$table1.$key1 as ${table1}__$key1",
4319
    table => $table1,
4320
    where   => {"$table3.$key4" => 4},
4321
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4322
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4323
)->all;
4324
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4325

            
4326
$dbi = DBIx::Custom->connect;
4327
eval { $dbi->execute("drop table $table1") };
4328
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4329
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4330
eval { $dbi->execute("drop table $table2") };
4331
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4332
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4333
$rows = $dbi->select(
4334
    table => $table1,
4335
    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",
4336
    where   => {"$table1.$key2" => 2},
4337
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4338
)->all;
4339
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4340
          'quote');
4341

            
4342

            
4343
$dbi = DBIx::Custom->connect;
4344
eval { $dbi->execute("drop table $table1") };
4345
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4346
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4347
$sql = <<"EOS";
4348
left outer join (
4349
  select * from $table1 t1
4350
  where t1.$key2 = (
4351
    select max(t2.$key2) from $table1 t2
4352
    where t1.$key1 = t2.$key1
4353
  )
4354
) $table3 on $table1.$key1 = $table3.$key1
4355
EOS
4356
$join = [$sql];
4357
$rows = $dbi->select(
4358
    table => $table1,
4359
    column => "$table3.$key1 as ${table3}__$key1",
4360
    join  => $join
4361
)->all;
4362
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4363

            
4364
$dbi = DBIx::Custom->connect;
4365
eval { $dbi->execute("drop table $table1") };
4366
eval { $dbi->execute("drop table $table2") };
4367
$dbi->execute($create_table1);
4368
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4369
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4370
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4371
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4372
$result = $dbi->select(
4373
    table => $table1,
4374
    join => [
4375
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4376
    ]
4377
);
4378
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4379
$result = $dbi->select(
4380
    table => $table1,
4381
    column => [{$table2 => [$key3]}],
4382
    join => [
4383
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4384
    ]
4385
);
4386
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4387
$result = $dbi->select(
4388
    table => $table1,
4389
    column => [{$table2 => [$key3]}],
4390
    join => [
4391
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4392
    ]
4393
);
4394
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4395

            
4396
$dbi = DBIx::Custom->connect;
4397
eval { $dbi->execute("drop table $table1") };
4398
eval { $dbi->execute("drop table $table2") };
4399
$dbi->execute($create_table1);
4400
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4401
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4402
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4403
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4404
$result = $dbi->select(
4405
    table => $table1,
4406
    column => [{$table2 => [$key3]}],
4407
    join => [
4408
        {
4409
            clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4410
            table => [$table1, $table2]
4411
        }
4412
    ]
4413
);
4414
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4415

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4416
$dbi = DBIx::Custom->connect;
4417
eval { $dbi->execute("drop table $table1") };
4418
eval { $dbi->execute("drop table $table2") };
4419
$dbi->execute($create_table1);
4420
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4421
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4422
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4423
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4424
$result = $dbi->select(
4425
    table => $table1,
4426
    column => [{$table2 => [$key3]}],
4427
    join => [
4428
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4429
    ]
4430
);
4431
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4432

            
4433
$dbi = DBIx::Custom->connect;
4434
eval { $dbi->execute("drop table $table1") };
4435
eval { $dbi->execute("drop table $table2") };
4436
$dbi->execute($create_table1);
4437
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4438
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4439
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4440
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4441
$result = $dbi->select(
4442
    table => $table1,
4443
    column => [{$table2 => [$key3]}],
4444
    join => [
4445
        "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4446
    ]
4447
);
4448
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4449

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4450
test 'columns';
4451
$dbi = MyDBI1->connect;
4452
$model = $dbi->model($table1);
4453

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4454
test 'count';
4455
$dbi = DBIx::Custom->connect;
4456
eval { $dbi->execute("drop table $table1") };
4457
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4458
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4459
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4460
is($dbi->count(table => $table1), 2);
4461
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4462
$model = $dbi->create_model(table => $table1);
4463
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4464

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