DBIx-Custom / t / common.t /
Newer Older
4524 lines | 151.847kb
added common test executing ...
Yuki Kimoto authored on 2011-08-07
1
use Test::More;
2
use strict;
3
use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
4
use Encode qw/encode_utf8/;
cleanup test
Yuki Kimoto authored on 2011-08-10
5
use FindBin;
cleanup
Yuki Kimoto authored on 2011-08-13
6
use Scalar::Util 'isweak';
cleanup test
Yuki Kimoto authored on 2011-08-10
7

            
added common test executing ...
Yuki Kimoto authored on 2011-08-07
8
my $dbi;
9

            
10
plan skip_all => $ENV{DBIX_CUSTOM_SKIP_MESSAGE} || 'common.t is always skipped'
11
  unless $ENV{DBIX_CUSTOM_TEST_RUN}
12
    && eval { $dbi = DBIx::Custom->connect; 1 };
13

            
14
plan 'no_plan';
15

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
16
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
finished oracle test
Yuki Kimoto authored on 2011-08-15
17
sub test { print "# $_[0]\n" }
18

            
cleanup test
Yuki Kimoto authored on 2011-08-15
19
# Constant
20
my $table1 = $dbi->table1;
21
my $table2 = $dbi->table2;
22
my $table2_alias = $dbi->table2_alias;
23
my $table3 = $dbi->table3;
24
my $key1 = $dbi->key1;
25
my $key2 = $dbi->key2;
26
my $key3 = $dbi->key3;
27
my $key4 = $dbi->key4;
28
my $key5 = $dbi->key5;
29
my $key6 = $dbi->key6;
30
my $key7 = $dbi->key7;
31
my $key8 = $dbi->key8;
32
my $key9 = $dbi->key9;
33
my $key10 = $dbi->key10;
34
my $create_table1 = $dbi->create_table1;
35
my $create_table1_2 = $dbi->create_table1_2;
36
my $create_table1_type = $dbi->create_table1_type;
37
my $create_table1_highperformance = $dbi->create_table1_highperformance;
38
my $create_table2 = $dbi->create_table2;
39
my $create_table2_2 = $dbi->create_table2_2;
40
my $create_table3 = $dbi->create_table3;
41
my $create_table_reserved = $dbi->create_table_reserved;
42
my $q = substr($dbi->quote, 0, 1);
43
my $p = substr($dbi->quote, 1, 1) || $q;
44
my $date_typename = $dbi->date_typename;
45
my $datetime_typename = $dbi->datetime_typename;
46
my $date_datatype = $dbi->date_datatype;
47
my $datetime_datatype = $dbi->datetime_datatype;
48

            
49
# Variables
50
my $builder;
51
my $datas;
52
my $sth;
53
my $source;
54
my @sources;
55
my $select_source;
56
my $insert_source;
57
my $update_source;
58
my $param;
59
my $params;
60
my $sql;
61
my $result;
62
my $row;
63
my @rows;
64
my $rows;
65
my $query;
66
my @queries;
67
my $select_query;
68
my $insert_query;
69
my $update_query;
70
my $ret_val;
71
my $infos;
72
my $model;
73
my $model2;
74
my $where;
75
my $update_param;
76
my $insert_param;
77
my $join;
78
my $binary;
added test
Yuki Kimoto authored on 2011-08-16
79
my $user_table_info;
cleanup
Yuki Kimoto authored on 2011-08-16
80
my $user_column_info;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
81
my $values_clause;
82
my $assign_clause;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
83
my $reuse;
cleanup test
Yuki Kimoto authored on 2011-08-15
84

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

            
89
    use strict;
90
    use warnings;
91

            
92
    use base 'DBIx::Custom';
93

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

            
105
    package MyModel2::Base1;
106

            
107
    use strict;
108
    use warnings;
109

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

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

            
114
    use strict;
115
    use warnings;
116

            
117
    use base 'MyModel2::Base1';
118

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

            
125
    sub list { shift->select; }
126

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

            
129
    use strict;
130
    use warnings;
131

            
132
    use base 'MyModel2::Base1';
133

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

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

            
142
    package MyModel2::TABLE1;
143

            
144
    use strict;
145
    use warnings;
146

            
147
    use base 'MyModel2::Base1';
148

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

            
155
    sub list { shift->select; }
156

            
157
    package MyModel2::TABLE2;
158

            
159
    use strict;
160
    use warnings;
161

            
162
    use base 'MyModel2::Base1';
163

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

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

            
175
    use strict;
176
    use warnings;
177

            
178
    use base 'DBIx::Custom';
179

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
959

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

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

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

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

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

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

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

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

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

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

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

            
1051

            
1052
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1053
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1054
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1055
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1056
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1057
$rows = $dbi->select(table => $table1)->all;
1058
is_deeply($rows, [{$key1 => 1, $key2 => 2},
1059
                  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
1060

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

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

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

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

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

            
1086
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1087
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1088
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1089
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1090
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1091
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], "relation : no exists where");
test cleanup
Yuki Kimoto authored on 2011-08-10
1092

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1192

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

            
1198
$dbi->begin_work;
1199

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

            
1206
$dbi->rollback if $@;
1207

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

            
1212
$dbi->begin_work;
1213

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

            
1219
$dbi->commit unless $@;
1220

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1827

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

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

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

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

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

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

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

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

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

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

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

            
1900
$dbi->apply_filter(
1901

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2187

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2404

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2583

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

            
2599

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

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

            
2620

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

            
2639

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

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

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

            
2679

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

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

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

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

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

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

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

            
2775

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

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

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

            
2802

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2958
$where = $dbi->where;
2959
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->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 => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2963
);
2964
$where->param($param);
2965
is_deeply($where->param, {});
2966

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

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

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

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

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

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

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

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

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

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

            
3064
{
3065
    $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3066
    $dbi = DBIx::Custom->connect;
3067
    eval { $dbi->execute("drop table $table1") };
3068
    $dbi->execute($create_table1);
3069
    $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-16
3070
    is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3071
    delete$ENV{DBIX_CUSTOM_TAG_PARSE};
3072
}
3073

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3268
test 'result';
3269
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3270
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3271
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3272
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3273
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
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 = ();
3277
while (my $row = $result->fetch) {
3278
    push @rows, [@$row];
3279
}
3280
is_deeply(\@rows, [[1, 2], [3, 4]]);
3281

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3442

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3646

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

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

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

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

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

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

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

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

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

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

            
3757
test 'primary_key';
3758
$dbi = MyDBI1->connect;
3759
$model = $dbi->model($table1);
3760
$model->primary_key([$key1, $key2]);
3761
is_deeply($model->primary_key, [$key1, $key2]);
3762

            
3763
test 'columns';
3764
$dbi = MyDBI1->connect;
3765
$model = $dbi->model($table1);
3766
$model->columns([$key1, $key2]);
3767
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3768

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

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

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

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

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

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

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

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

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

            
3864

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3865
$dbi = DBIx::Custom->connect;
3866
eval { $dbi->execute("drop table $table1") };
3867
$dbi->execute($create_table1_type);
3868

            
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 => sub { '2010-' . $_[0] }
3873
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3874
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3875
$dbi->insert({$key1 => '01-01'}, table => $table1);
3876
$result = $dbi->select(table => $table1);
3877
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3878

            
3879
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3880
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3881
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3882
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3883
$dbi->type_rule(
3884
    into1 => [
3885
         [$date_typename, $datetime_typename] => sub {
3886
            my $value = shift;
3887
            $value =~ s/02/03/g;
3888
            return $value;
3889
         }
3890
    ]
3891
);
3892
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3893
$result = $dbi->select(table => $table1);
3894
$row = $result->one;
3895
like($row->{$key1}, qr/^2010-01-03/);
3896
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3897

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3898
$dbi = DBIx::Custom->connect;
3899
eval { $dbi->execute("drop table $table1") };
3900
$dbi->execute($create_table1_type);
3901
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3902
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3903
$dbi->type_rule(
3904
    into1 => [
3905
        [$date_typename, $datetime_typename] => sub {
3906
            my $value = shift;
3907
            $value =~ s/02/03/g;
3908
            return $value;
3909
        }
3910
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3911
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3912
$result = $dbi->execute(
3913
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
3914
    {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
3915
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3916
$row = $result->one;
3917
like($row->{$key1}, qr/^2010-01-03/);
3918
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3919

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

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

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

            
3993

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

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

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

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

            
4069
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4070
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4071
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4072
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4073
$dbi->type_rule(
4074
    from1 => {
4075
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4076
    },
4077
    into1 => {
4078
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4079
    }
4080
);
4081
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4082
$result = $dbi->select(table => $table1);
4083
like($result->fetch->[0], qr/2010-01-05/);
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);
4088
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
4089
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4090
$dbi->type_rule(
4091
    into1 => {
4092
        $date_typename => 'ppp'
4093
    }
4094
);
4095
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4096
$result = $dbi->select(table => $table1);
4097
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4098

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4401

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

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

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4509
test 'columns';
4510
$dbi = MyDBI1->connect;
4511
$model = $dbi->model($table1);
4512

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

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