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

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

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

            
14
plan 'no_plan';
15

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

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

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

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

            
89
    use strict;
90
    use warnings;
91

            
92
    use base 'DBIx::Custom';
93

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

            
105
    package MyModel2::Base1;
106

            
107
    use strict;
108
    use warnings;
109

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

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

            
114
    use strict;
115
    use warnings;
116

            
117
    use base 'MyModel2::Base1';
118

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

            
125
    sub list { shift->select; }
126

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

            
129
    use strict;
130
    use warnings;
131

            
132
    use base 'MyModel2::Base1';
133

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

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

            
142
    package MyModel2::TABLE1;
143

            
144
    use strict;
145
    use warnings;
146

            
147
    use base 'MyModel2::Base1';
148

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

            
155
    sub list { shift->select; }
156

            
157
    package MyModel2::TABLE2;
158

            
159
    use strict;
160
    use warnings;
161

            
162
    use base 'MyModel2::Base1';
163

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

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

            
175
    use strict;
176
    use warnings;
177

            
178
    use base 'DBIx::Custom';
179

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
959

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

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

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

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

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

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

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

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

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

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

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

            
1051

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1192

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

            
1198
$dbi->begin_work;
1199

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

            
1206
$dbi->rollback if $@;
1207

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

            
1212
$dbi->begin_work;
1213

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

            
1219
$dbi->commit unless $@;
1220

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1827

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

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

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

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

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

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

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

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

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

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

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

            
1900
$dbi->apply_filter(
1901

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2187

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2404

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2583

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

            
2599

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

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

            
2620

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

            
2639

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

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

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

            
2679

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

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

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

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

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

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

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

            
2775

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

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

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

            
2802

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3440

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3644

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3862

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

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

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

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

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

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

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

            
3991

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

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

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

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

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

            
4083
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4084
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4085
$dbi->execute($create_table1_type);
4086
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
4087
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4088
$dbi->type_rule(
4089
    into1 => {
4090
        $date_typename => 'ppp'
4091
    }
4092
);
4093
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4094
$result = $dbi->select(table => $table1);
4095
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4096

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4399

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

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

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

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

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

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

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

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