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

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

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

            
14
plan 'no_plan';
15

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

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

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

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

            
89
    use strict;
90
    use warnings;
91

            
92
    use base 'DBIx::Custom';
93

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

            
105
    package MyModel2::Base1;
106

            
107
    use strict;
108
    use warnings;
109

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

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

            
114
    use strict;
115
    use warnings;
116

            
117
    use base 'MyModel2::Base1';
118

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

            
125
    sub list { shift->select; }
126

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

            
129
    use strict;
130
    use warnings;
131

            
132
    use base 'MyModel2::Base1';
133

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

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

            
142
    package MyModel2::TABLE1;
143

            
144
    use strict;
145
    use warnings;
146

            
147
    use base 'MyModel2::Base1';
148

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

            
155
    sub list { shift->select; }
156

            
157
    package MyModel2::TABLE2;
158

            
159
    use strict;
160
    use warnings;
161

            
162
    use base 'MyModel2::Base1';
163

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

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

            
175
    use strict;
176
    use warnings;
177

            
178
    use base 'DBIx::Custom';
179

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
959

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

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

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

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

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

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

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

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

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

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

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

            
1051

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1183

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

            
1189
$dbi->begin_work;
1190

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

            
1197
$dbi->rollback if $@;
1198

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

            
1203
$dbi->begin_work;
1204

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

            
1210
$dbi->commit unless $@;
1211

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1412
$result = $dbi->select(
1413
     table => [$table1, $table2],
1414
     column => [$key2, $key3],
1415
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1416

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1801

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

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

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

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

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

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

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

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

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

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

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

            
1874
$dbi->apply_filter(
1875

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2161

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
2338
$dbi = DBIx::Custom->connect;
2339
eval { $dbi->execute("drop table $table1") };
2340
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2341
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2342
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
2343
$rows = $dbi->select(
2344
    table => $table1,
2345
    where => [
2346
        "$key1 = :$key1 and $key2 = :$key2",
2347
        {$key1 => 1, $key2 => 2}
2348
    ]
2349
)->all;
2350
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2351

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

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

            
2381

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2560

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

            
2576

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

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

            
2597

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

            
2616

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

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

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

            
2656

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2739
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2740
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2741
$result = $model->select(
2742
    column => [
2743
        $model->mycolumn,
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2744
        {$table2 => [$key1, $key3]}
cleanup test
Yuki Kimoto authored on 2011-08-10
2745
    ],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2746
    where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2747
);
2748
is_deeply($result->one,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2749
          {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
2750
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2751

            
2752

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

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

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

            
2779

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3027
test 'last_sql';
3028
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3029
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3030
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3031
$dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-15
3032
is($dbi->last_sql, "select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3033

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3065
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3066
$result = $dbi->execute(
3067
    $source,
cleanup
Yuki Kimoto authored on 2011-11-01
3068
    {"$table1.$key1" => 1, "$table1.$key2" => 1},
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3069
    filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3070
);
3071
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3072
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3073

            
3074
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3075
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3076
$dbi->execute($create_table1_highperformance);
3077
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3078
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3079
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3080
];
3081
{
3082
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3083
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3084
      $query ||= $dbi->insert($row, table => $table1, query => 1);
3085
      $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
test cleanup
Yuki Kimoto authored on 2011-08-10
3086
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3087
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3088
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3089
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3090
          {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3091
      ]
3092
    );
3093
}
3094

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

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3117
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3118
$dbi->execute($create_table1_highperformance);
3119
$rows = [
3120
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
3121
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
3122
];
3123
{
3124
    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3125
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
3126
    for my $row (@$rows) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3127
      $query ||= $model->insert($row, query => 1);
3128
      $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3129
    }
3130
    is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3131
      [
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3132
          {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3133
          {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3134
      ]
3135
    );
3136
}
3137

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3138
test 'id option more';
3139
eval { $dbi->execute("drop table $table1") };
3140
$dbi->execute($create_table1_highperformance);
3141
$row = {
3142
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3143
};
3144
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3145
$model->insert($row);
3146
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3147
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3148
is_deeply($dbi->select(table => $table1)->one,
3149
    {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3150
);
3151

            
3152
eval { $dbi->execute("drop table $table1") };
3153
eval { $dbi->execute("drop table $table2") };
3154
$dbi->execute($create_table1);
3155
$dbi->execute($create_table2);
3156
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3157
$model->insert({$key1 => 1, $key2 => 2});
3158
$model = $dbi->create_model(table => $table2, primary_key => $key1,
3159
    join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
3160
$model->insert({$key1 => 1, $key3 => 3});
3161
$result = $model->select(
3162
    column => {$table1 => ["$key2"]},
3163
    id => 1
3164
);
3165
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3166

            
3167
eval { $dbi->execute("drop table $table1") };
3168
$dbi->execute($create_table1_highperformance);
3169
$row = {
3170
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3171
};
3172
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3173
$model->insert($row);
3174
$query = $model->delete(id => 1, query => 1);
3175
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3176
is_deeply($dbi->select(table => $table1)->all, []);
3177

            
3178
eval { $dbi->execute("drop table $table1") };
3179
eval { $dbi->execute($create_table1_highperformance) };
3180
$row = {
3181
    $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
3182
};
3183
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3184
$model->insert($row);
3185
$query = $model->select(id => 1, query => 1);
3186
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3187
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3188
is_deeply($dbi->select(table => $table1)->one,
3189
    {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
3190
);
3191

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3192
test 'result';
3193
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3194
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3195
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3196
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3197
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3198

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3199
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3200
@rows = ();
3201
while (my $row = $result->fetch) {
3202
    push @rows, [@$row];
3203
}
3204
is_deeply(\@rows, [[1, 2], [3, 4]]);
3205

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3206
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3207
@rows = ();
3208
while (my $row = $result->fetch_hash) {
3209
    push @rows, {%$row};
3210
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3211
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3212

            
3213
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3214
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3215
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3216
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3217
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3218

            
3219
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3220
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3221
$rows = $result->fetch_all;
3222
is_deeply($rows, [[1, 2], [3, 4]]);
3223

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

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

            
3232
$rows = $result->fetch_all;
3233
is_deeply($rows, [[3, 2], [9, 4]], "array");
3234

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

            
3241
test "query_builder";
3242
$datas = [
3243
    # Basic tests
3244
    {   name            => 'placeholder basic',
3245
        source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
cleanup test
Yuki Kimoto authored on 2011-08-15
3246
        sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3247
        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3248
    },
3249
    {
3250
        name            => 'placeholder in',
cleanup test
Yuki Kimoto authored on 2011-08-15
3251
        source            => "{in k1 3}",
3252
        sql_expected    => "k1 in (?, ?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3253
        columns_expected   => [qw/k1 k1 k1/]
3254
    },
3255
    
3256
    # Table name
3257
    {
3258
        name            => 'placeholder with table name',
3259
        source            => "{= a.k1} {= a.k2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3260
        sql_expected    => "a.k1 = ? a.k2 = ?",
test cleanup
Yuki Kimoto authored on 2011-08-10
3261
        columns_expected  => [qw/a.k1 a.k2/]
3262
    },
3263
    {   
3264
        name            => 'placeholder in with table name',
3265
        source            => "{in a.k1 2} {in b.k2 2}",
cleanup test
Yuki Kimoto authored on 2011-08-15
3266
        sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
test cleanup
Yuki Kimoto authored on 2011-08-10
3267
        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3268
    },
3269
    {
3270
        name            => 'not contain tag',
3271
        source            => "aaa",
cleanup test
Yuki Kimoto authored on 2011-08-15
3272
        sql_expected    => "aaa",
test cleanup
Yuki Kimoto authored on 2011-08-10
3273
        columns_expected  => [],
3274
    }
3275
];
3276

            
3277
for (my $i = 0; $i < @$datas; $i++) {
3278
    my $data = $datas->[$i];
cleanup
Yuki Kimoto authored on 2011-08-13
3279
    my $dbi = DBIx::Custom->new;
3280
    my $builder = $dbi->query_builder;
test cleanup
Yuki Kimoto authored on 2011-08-10
3281
    my $query = $builder->build_query($data->{source});
3282
    is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3283
    is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns");
3284
}
3285

            
cleanup
Yuki Kimoto authored on 2011-08-13
3286
$dbi = DBIx::Custom->new;
3287
$builder = $dbi->query_builder;
3288
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3289
    p => sub {
3290
        my @args = @_;
3291
        
3292
        my $expand    = "? $args[0] $args[1]";
3293
        my $columns = [2];
3294
        return [$expand, $columns];
3295
    }
3296
);
3297

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3308
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3309
    q => 'string'
3310
});
3311

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3315
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3316
   r => sub {} 
3317
});
3318

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3322
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3323
   s => sub { return ["a", ""]} 
3324
});
3325

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3329
$dbi->register_tag(
test cleanup
Yuki Kimoto authored on 2011-08-10
3330
    t => sub {return ["a", []]}
3331
);
3332

            
3333

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

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

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

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

            
3349
test 'variouse source';
3350
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3351
$query = $builder->build_query($source);
3352
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3353

            
3354
$source = "abc";
3355
$query = $builder->build_query($source);
3356
is($query->sql, 'abc', "basic : 2");
3357

            
3358
$source = "{= a}";
3359
$query = $builder->build_query($source);
3360
is($query->sql, 'a = ?', "only tag");
3361

            
3362
$source = "000";
3363
$query = $builder->build_query($source);
3364
is($query->sql, '000', "contain 0 value");
3365

            
3366
$source = "a {= b} }";
3367
eval{$builder->build_query($source)};
3368
like($@, qr/unexpected "}"/, "error : 1");
3369

            
3370
$source = "a {= {}";
3371
eval{$builder->build_query($source)};
3372
like($@, qr/unexpected "{"/, "error : 2");
3373

            
3374
test 'select() sqlfilter option';
3375
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3376
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3377
eval { $dbi->execute("drop table $table1") };
3378
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3379
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3380
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3381
$rows = $dbi->select(
3382
    table => $table1,
3383
    column => $key1,
3384
    sqlfilter => sub {
3385
        my $sql = shift;
test cleanup
Yuki Kimoto authored on 2011-08-15
3386
        $sql = "select * from ( $sql ) t where $key1 = 1";
cleanup test
Yuki Kimoto authored on 2011-08-15
3387
        return $sql;
3388
    }
3389
)->all;
3390
is_deeply($rows, [{$key1 => 1}]);
3391

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3392
test 'select() after_build_sql option';
3393
$dbi = DBIx::Custom->connect;
3394
$dbi->user_table_info($user_table_info);
3395
eval { $dbi->execute("drop table $table1") };
3396
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3397
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3398
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3399
$rows = $dbi->select(
3400
    table => $table1,
3401
    column => $key1,
3402
    after_build_sql => sub {
3403
        my $sql = shift;
3404
        $sql = "select * from ( $sql ) t where $key1 = 1";
3405
        return $sql;
3406
    }
3407
)->all;
3408
is_deeply($rows, [{$key1 => 1}]);
3409

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3410
test 'dbi method from model';
3411
$dbi = MyDBI9->connect;
3412
eval { $dbi->execute("drop table $table1") };
3413
$dbi->execute($create_table1);
3414
$dbi->setup_model;
3415
$model = $dbi->model($table1);
3416
eval{$model->execute("select * from $table1")};
3417
ok(!$@);
3418

            
3419
test 'column table option';
3420
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3421
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3422
eval { $dbi->execute("drop table $table1") };
3423
$dbi->execute($create_table1);
3424
eval { $dbi->execute("drop table $table2") };
3425
$dbi->execute($create_table2);
3426
$dbi->setup_model;
3427
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3428
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3429
$model = $dbi->model($table1);
3430
$result = $model->select(
3431
    column => [
3432
        $model->column($table2, {alias => $table2_alias})
3433
    ],
3434
    where => {"$table2_alias.$key3" => 4}
3435
);
3436
is_deeply($result->one, 
3437
          {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
3438

            
3439
$dbi->separator('__');
3440
$result = $model->select(
3441
    column => [
3442
        $model->column($table2, {alias => $table2_alias})
3443
    ],
3444
    where => {"$table2_alias.$key3" => 4}
3445
);
3446
is_deeply($result->one, 
3447
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3448

            
3449
$dbi->separator('-');
3450
$result = $model->select(
3451
    column => [
3452
        $model->column($table2, {alias => $table2_alias})
3453
    ],
3454
    where => {"$table2_alias.$key3" => 4}
3455
);
3456
is_deeply($result->one, 
3457
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3458

            
3459
test 'create_model';
3460
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3461
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3462
eval { $dbi->execute("drop table $table1") };
3463
eval { $dbi->execute("drop table $table2") };
3464
$dbi->execute($create_table1);
3465
$dbi->execute($create_table2);
3466

            
3467
$dbi->create_model(
3468
    table => $table1,
3469
    join => [
3470
       "left outer join $table2 on $table1.$key1 = $table2.$key1"
3471
    ],
3472
    primary_key => [$key1]
3473
);
3474
$model2 = $dbi->create_model(
3475
    table => $table2
3476
);
3477
$dbi->create_model(
3478
    table => $table3,
3479
    filter => [
3480
        $key1 => {in => sub { uc $_[0] }}
3481
    ]
3482
);
3483
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3484
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3485
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3486
$model = $dbi->model($table1);
3487
$result = $model->select(
3488
    column => [$model->mycolumn, $model->column($table2)],
3489
    where => {"$table1.$key1" => 1}
3490
);
3491
is_deeply($result->one,
3492
          {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
3493
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3494

            
3495
test 'model method';
3496
$dbi = DBIx::Custom->connect;
3497
eval { $dbi->execute("drop table $table2") };
3498
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3499
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3500
$model = $dbi->create_model(
3501
    table => $table2
3502
);
3503
$model->method(foo => sub { shift->select(@_) });
3504
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3505

            
3506
test 'model helper';
3507
$dbi = DBIx::Custom->connect;
3508
eval { $dbi->execute("drop table $table2") };
3509
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3510
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3511
$model = $dbi->create_model(
3512
    table => $table2
3513
);
3514
$model->helper(foo => sub { shift->select(@_) });
3515
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3516

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

            
3524
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3525
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3526
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3527
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3528
where $key1 = 1
3529
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3530
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3531
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3532
$rows   = $result->all;
3533
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3534
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3535
                  "basic");
3536

            
3537

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

            
3544
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3545
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3546
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3547
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3548
where $key1 = 1
3549
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3550
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3551
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3552
$rows   = $result->all;
3553
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3554
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3555
                  "basic");
3556

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

            
3563
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3564
$assign_clause = $dbi->update_param($param, {no_set => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
3565
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3566
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3567
where $key1 = 1
3568
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3569
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3570
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3571
$rows   = $result->all;
3572
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
3573
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3574
                  "update param no_set");
3575

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3586
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3587
$assign_clause = $dbi->assign_param($param);
3588
$sql = <<"EOS";
3589
update $table1 set $assign_clause
3590
where $key1 = 1
3591
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3592
$dbi->execute($sql, $param, table => $table1);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3593
$result = $dbi->execute("select * from $table1 order by $key1");
3594
$rows   = $result->all;
3595
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
3596
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3597
                  "basic");
3598

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3612
test 'Model class';
3613
$dbi = MyDBI1->connect;
3614
eval { $dbi->execute("drop table $table1") };
3615
$dbi->execute($create_table1);
3616
$model = $dbi->model($table1);
3617
$model->insert({$key1 => 'a', $key2 => 'b'});
3618
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3619
eval { $dbi->execute("drop table $table2") };
3620
$dbi->execute($create_table2);
3621
$model = $dbi->model($table2);
3622
$model->insert({$key1 => 'a'});
3623
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3624
is($dbi->models->{$table1}, $dbi->model($table1));
3625
is($dbi->models->{$table2}, $dbi->model($table2));
3626

            
3627
$dbi = MyDBI4->connect;
3628
eval { $dbi->execute("drop table $table1") };
3629
$dbi->execute($create_table1);
3630
$model = $dbi->model($table1);
3631
$model->insert({$key1 => 'a', $key2 => 'b'});
3632
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3633
eval { $dbi->execute("drop table $table2") };
3634
$dbi->execute($create_table2);
3635
$model = $dbi->model($table2);
3636
$model->insert({$key1 => 'a'});
3637
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3638

            
3639
$dbi = MyDBI5->connect;
3640
eval { $dbi->execute("drop table $table1") };
3641
eval { $dbi->execute("drop table $table2") };
3642
$dbi->execute($create_table1);
3643
$dbi->execute($create_table2);
3644
$model = $dbi->model($table2);
3645
$model->insert({$key1 => 'a'});
3646
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
3647
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3648
$model = $dbi->model($table1);
3649
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3650

            
3651
test 'primary_key';
3652
$dbi = MyDBI1->connect;
3653
$model = $dbi->model($table1);
3654
$model->primary_key([$key1, $key2]);
3655
is_deeply($model->primary_key, [$key1, $key2]);
3656

            
3657
test 'columns';
3658
$dbi = MyDBI1->connect;
3659
$model = $dbi->model($table1);
3660
$model->columns([$key1, $key2]);
3661
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3662

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3663
test 'setup_model';
3664
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3665
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3666
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3667
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3668

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3669
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3670
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3671
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3672
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3673
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3674

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3675
test 'each_column';
3676
$dbi = DBIx::Custom->connect;
3677
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3678
eval { $dbi->execute("drop table $table1") };
3679
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3680
eval { $dbi->execute("drop table $table3") };
3681
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3682
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3683

            
3684
$infos = [];
3685
$dbi->each_column(sub {
3686
    my ($self, $table, $column, $cinfo) = @_;
3687
    
3688
    if ($table =~ /^table\d/i) {
3689
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3690
         push @$infos, $info;
3691
    }
3692
});
3693
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3694
is_deeply($infos, 
3695
    [
3696
        [$table1, $key1, $key1],
3697
        [$table1, $key2, $key2],
3698
        [$table2, $key1, $key1],
3699
        [$table2, $key3, $key3]
3700
    ]
3701
    
cleanup test
Yuki Kimoto authored on 2011-08-10
3702
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3703

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3704
test 'each_table';
3705
$dbi = DBIx::Custom->connect;
3706
eval { $dbi->execute("drop table $table1") };
3707
eval { $dbi->execute("drop table $table2") };
3708
$dbi->execute($create_table2);
3709
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3710

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3711
$infos = [];
3712
$dbi->each_table(sub {
3713
    my ($self, $table, $table_info) = @_;
3714
    
3715
    if ($table =~ /^table\d/i) {
3716
         my $info = [$table, $table_info->{TABLE_NAME}];
3717
         push @$infos, $info;
3718
    }
3719
});
3720
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3721
is_deeply($infos, 
3722
    [
3723
        [$table1, $table1],
3724
        [$table2, $table2],
3725
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3726
);
3727

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3728
$dbi = DBIx::Custom->connect;
3729
eval { $dbi->execute("drop table $table1") };
3730
eval { $dbi->execute("drop table $table2") };
3731
$dbi->execute($create_table2);
3732
$dbi->execute($create_table1_type);
3733

            
3734
$infos = [];
3735
$dbi->user_table_info($user_table_info);
3736
$dbi->each_table(sub {
3737
    my ($self, $table, $table_info) = @_;
3738
    
3739
    if ($table =~ /^table\d/i) {
3740
         my $info = [$table, $table_info->{TABLE_NAME}];
3741
         push @$infos, $info;
3742
    }
3743
});
3744
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3745
is_deeply($infos, 
3746
    [
3747
        [$table1, $table1],
3748
        [$table2, $table2],
3749
        [$table3, $table3],
3750
    ]
3751
);
3752

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3753
test 'type_rule into';
3754
eval { $dbi->execute("drop table $table1") };
3755
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3756
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3757

            
3758

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3759
$dbi = DBIx::Custom->connect;
3760
eval { $dbi->execute("drop table $table1") };
3761
$dbi->execute($create_table1_type);
3762

            
cleanup
Yuki Kimoto authored on 2011-08-16
3763
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3764
$dbi->type_rule(
3765
    into1 => {
3766
        $date_typename => sub { '2010-' . $_[0] }
3767
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3768
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3769
$dbi->insert({$key1 => '01-01'}, table => $table1);
3770
$result = $dbi->select(table => $table1);
3771
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3772

            
3773
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3774
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3775
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3776
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3777
$dbi->type_rule(
3778
    into1 => [
3779
         [$date_typename, $datetime_typename] => sub {
3780
            my $value = shift;
3781
            $value =~ s/02/03/g;
3782
            return $value;
3783
         }
3784
    ]
3785
);
3786
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3787
$result = $dbi->select(table => $table1);
3788
$row = $result->one;
3789
like($row->{$key1}, qr/^2010-01-03/);
3790
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3791

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3792
$dbi = DBIx::Custom->connect;
3793
eval { $dbi->execute("drop table $table1") };
3794
$dbi->execute($create_table1_type);
3795
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3796
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3797
$dbi->type_rule(
3798
    into1 => [
3799
        [$date_typename, $datetime_typename] => sub {
3800
            my $value = shift;
3801
            $value =~ s/02/03/g;
3802
            return $value;
3803
        }
3804
    ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3805
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3806
$result = $dbi->execute(
3807
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
3808
    {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
3809
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3810
$row = $result->one;
3811
like($row->{$key1}, qr/^2010-01-03/);
3812
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
3813

            
3814
$dbi = DBIx::Custom->connect;
3815
eval { $dbi->execute("drop table $table1") };
3816
$dbi->execute($create_table1_type);
3817
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3818
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3819
$dbi->type_rule(
3820
    into1 => [
3821
        [$date_typename, $datetime_typename] => sub {
3822
            my $value = shift;
3823
            $value =~ s/02/03/g;
3824
            return $value;
3825
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
3826
    ]
3827
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3828
$result = $dbi->execute(
3829
    "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
cleanup
Yuki Kimoto authored on 2011-11-01
3830
    {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
cleanup test
Yuki Kimoto authored on 2011-08-15
3831
    table => $table1
3832
);
3833
$row = $result->one;
3834
like($row->{$key1}, qr/^2010-01-03/);
3835
like($row->{$key2}, qr/2010-01-01 01:01:03/);
3836

            
3837
$dbi = DBIx::Custom->connect;
3838
eval { $dbi->execute("drop table $table1") };
3839
$dbi->execute($create_table1_type);
3840
$dbi->register_filter(convert => sub {
3841
    my $value = shift || '';
3842
    $value =~ s/02/03/;
3843
    return $value;
3844
});
cleanup
Yuki Kimoto authored on 2011-08-16
3845
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3846
$dbi->type_rule(
3847
    from1 => {
3848
        $date_datatype => 'convert',
3849
    },
3850
    into1 => {
3851
        $date_typename => 'convert',
3852
    }
3853
);
3854
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
3855
$result = $dbi->select(table => $table1);
3856
like($result->fetch->[0], qr/^2010-03-03/);
3857

            
3858
test 'type_rule and filter order';
3859
$dbi = DBIx::Custom->connect;
3860
eval { $dbi->execute("drop table $table1") };
3861
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3862
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3863
$dbi->type_rule(
3864
    into1 => {
3865
        $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3866
    },
3867
    into2 => {
3868
        $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
3869
    },
3870
    from1 => {
3871
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
3872
    },
3873
    from2 => {
3874
        $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
3875
    }
3876
);
3877
$dbi->insert({$key1 => '2010-01-03'}, 
3878
  table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
3879
$result = $dbi->select(table => $table1);
3880
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3881
like($result->fetch_first->[0], qr/^2010-01-09/);
3882

            
3883

            
3884
$dbi = DBIx::Custom->connect;
3885
eval { $dbi->execute("drop table $table1") };
3886
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3887
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3888
$dbi->type_rule(
3889
    from1 => {
3890
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3891
    },
3892
    from2 => {
3893
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3894
    },
3895
);
3896
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3897
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3898
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3899
$result->type_rule(
3900
    from1 => {
3901
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
3902
    },
3903
    from2 => {
3904
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
3905
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3906
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3907
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
3908
like($result->fetch_first->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3909

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3910
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
3911
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
3912
eval { $dbi->execute("drop table $table1") };
3913
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3914
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3915
$dbi->type_rule(
3916
    from1 => {
3917
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3918
    },
3919
    into1 => {
3920
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3921
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
3922
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3923
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3924
$result = $dbi->select(table => $table1, type_rule_off => 1);
3925
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3926

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3927
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3928
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3929
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3930
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3931
$dbi->type_rule(
3932
    from1 => {
3933
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3934
    },
3935
    into1 => {
3936
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
3937
    }
3938
);
3939
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
3940
$result = $dbi->select(table => $table1, type_rule_off => 1);
3941
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3942

            
3943
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3944
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3945
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3946
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3947
$dbi->type_rule(
3948
    from1 => {
3949
        $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
3950
    },
3951
    into1 => {
3952
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
3953
    }
3954
);
3955
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
3956
$result = $dbi->select(table => $table1);
3957
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3958

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3989
eval{$dbi->type_rule(
3990
    into1 => {
3991
        $date_typename => 'pp'
3992
    }
3993
)};
3994
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3995

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3996
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3997
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3998
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3999
eval {
cleanup test
Yuki Kimoto authored on 2011-08-15
4000
    $dbi->type_rule(
4001
        from1 => {
4002
            Date => sub { $_[0] * 2 },
4003
        }
cleanup test
Yuki Kimoto authored on 2011-08-10
4004
    );
4005
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4006
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4007

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4008
eval {
4009
    $dbi->type_rule(
4010
        into1 => {
4011
            Date => sub { $_[0] * 2 },
4012
        }
4013
    );
4014
};
4015
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4016

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

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

            
4055
$result = $dbi->select(table => $table1);
4056
$result->type_rule(
4057
    from1 => {
4058
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4059
    }
cleanup test
Yuki Kimoto authored on 2011-08-10
4060
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4061
$row = $result->one;
4062
like($row->{$key1}, qr/2010-01-05/);
4063
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4064

            
4065
$result = $dbi->select(table => $table1);
4066
$result->type_rule(
4067
    from1 => {
4068
        $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4069
    }
4070
);
4071
$row = $result->one;
4072
like($row->{$key1}, qr/2010-01-05/);
4073
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4074

            
4075
$result = $dbi->select(table => $table1);
4076
$result->type_rule(
4077
    from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
4078
);
4079
$row = $result->one;
4080
like($row->{$key1}, qr/2010-01-05/);
4081
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4082

            
4083
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4084
$result = $dbi->select(table => $table1);
4085
$result->type_rule(
4086
    from1 => [$date_datatype => 'five']
4087
);
4088
$row = $result->one;
4089
like($row->{$key1}, qr/^2010-01-05/);
4090
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4091

            
4092
$result = $dbi->select(table => $table1);
4093
$result->type_rule(
4094
    from1 => [$date_datatype => undef]
4095
);
4096
$row = $result->one;
4097
like($row->{$key1}, qr/^2010-01-03/);
4098
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4099

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4152
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4153
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4154
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4155
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4156
$dbi->type_rule(
4157
    into1 => {
4158
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4159
    },
4160
    into2 => {
4161
        $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4162
    },
4163
    from1 => {
4164
        $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
4165
    },
4166
    from2 => {
4167
        $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4168
    }
4169
);
4170
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4171
$result = $dbi->select(table => $table1);
4172
like($result->type_rule1_off->fetch_first->[0], qr/^2010-01-05/);
4173
$result = $dbi->select(table => $table1);
4174
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4175

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4200
test 'join';
4201
$dbi = DBIx::Custom->connect;
4202
eval { $dbi->execute("drop table $table1") };
4203
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4204
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4205
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4206
eval { $dbi->execute("drop table $table2") };
4207
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4208
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4209
eval { $dbi->execute("drop table $table3") };
4210
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4211
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4212
$rows = $dbi->select(
4213
    table => $table1,
4214
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4215
    where   => {"$table1.$key2" => 2},
4216
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4217
)->all;
4218
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4219

            
4220
$dbi = DBIx::Custom->connect;
4221
eval { $dbi->execute("drop table $table1") };
4222
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4223
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4224
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4225
eval { $dbi->execute("drop table $table2") };
4226
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4227
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4228
eval { $dbi->execute("drop table $table3") };
4229
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4230
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4231
$rows = $dbi->select(
4232
    table => $table1,
4233
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4234
    where   => {"$table1.$key2" => 2},
4235
    join  => {
4236
        clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4237
        table => [$table1, $table2]
4238
    }
4239
)->all;
4240
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
4241

            
4242
$rows = $dbi->select(
4243
    table => $table1,
4244
    where   => {$key1 => 1},
4245
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4246
)->all;
4247
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4248

            
4249
$rows = $dbi->select(
4250
    table => $table1,
4251
    where   => {$key1 => 1},
4252
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4253
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4254
)->all;
4255
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4256

            
4257
$rows = $dbi->select(
4258
    column => "$table3.$key4 as ${table3}__$key4",
4259
    table => $table1,
4260
    where   => {"$table1.$key1" => 1},
4261
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4262
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4263
)->all;
4264
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4265

            
4266
$rows = $dbi->select(
4267
    column => "$table1.$key1 as ${table1}__$key1",
4268
    table => $table1,
4269
    where   => {"$table3.$key4" => 4},
4270
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4271
              "left outer join $table3 on $table2.$key3 = $table3.$key3"]
4272
)->all;
4273
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4274

            
4275
$dbi = DBIx::Custom->connect;
4276
eval { $dbi->execute("drop table $table1") };
4277
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4278
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4279
eval { $dbi->execute("drop table $table2") };
4280
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4281
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4282
$rows = $dbi->select(
4283
    table => $table1,
4284
    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",
4285
    where   => {"$table1.$key2" => 2},
4286
    join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
4287
)->all;
4288
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
4289
          'quote');
4290

            
4291

            
4292
$dbi = DBIx::Custom->connect;
4293
eval { $dbi->execute("drop table $table1") };
4294
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4295
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4296
$sql = <<"EOS";
4297
left outer join (
4298
  select * from $table1 t1
4299
  where t1.$key2 = (
4300
    select max(t2.$key2) from $table1 t2
4301
    where t1.$key1 = t2.$key1
4302
  )
4303
) $table3 on $table1.$key1 = $table3.$key1
4304
EOS
4305
$join = [$sql];
4306
$rows = $dbi->select(
4307
    table => $table1,
4308
    column => "$table3.$key1 as ${table3}__$key1",
4309
    join  => $join
4310
)->all;
4311
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4312

            
4313
$dbi = DBIx::Custom->connect;
4314
eval { $dbi->execute("drop table $table1") };
4315
eval { $dbi->execute("drop table $table2") };
4316
$dbi->execute($create_table1);
4317
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4318
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4319
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4320
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4321
$result = $dbi->select(
4322
    table => $table1,
4323
    join => [
4324
        "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4325
    ]
4326
);
4327
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4328
$result = $dbi->select(
4329
    table => $table1,
4330
    column => [{$table2 => [$key3]}],
4331
    join => [
4332
        "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4333
    ]
4334
);
4335
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4336
$result = $dbi->select(
4337
    table => $table1,
4338
    column => [{$table2 => [$key3]}],
4339
    join => [
4340
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4341
    ]
4342
);
4343
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4344

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

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4365
$dbi = DBIx::Custom->connect;
4366
eval { $dbi->execute("drop table $table1") };
4367
eval { $dbi->execute("drop table $table2") };
4368
$dbi->execute($create_table1);
4369
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4370
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4371
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4372
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4373
$result = $dbi->select(
4374
    table => $table1,
4375
    column => [{$table2 => [$key3]}],
4376
    join => [
4377
        "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4378
    ]
4379
);
4380
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4381

            
4382
$dbi = DBIx::Custom->connect;
4383
eval { $dbi->execute("drop table $table1") };
4384
eval { $dbi->execute("drop table $table2") };
4385
$dbi->execute($create_table1);
4386
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4387
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4388
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4389
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4390
$result = $dbi->select(
4391
    table => $table1,
4392
    column => [{$table2 => [$key3]}],
4393
    join => [
4394
        "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4395
    ]
4396
);
4397
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4398

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4399
test 'columns';
4400
$dbi = MyDBI1->connect;
4401
$model = $dbi->model($table1);
4402

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4403
test 'count';
4404
$dbi = DBIx::Custom->connect;
4405
eval { $dbi->execute("drop table $table1") };
4406
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4407
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4408
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4409
is($dbi->count(table => $table1), 2);
4410
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4411
$model = $dbi->create_model(table => $table1);
4412
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4413

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