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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
486
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
487
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
488
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
test cleanup
Yuki Kimoto authored on 2011-11-01
489
$dbi->insert({select => 1}, table => 'table');
cleanup test
Yuki Kimoto authored on 2011-08-10
490
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
491
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
492
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
cleanup test
Yuki Kimoto authored on 2011-08-10
493

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
494
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
495
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
496
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
497
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
498
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
499
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
500
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
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
Yuki Kimoto authored on 2011-11-01
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

            
updated pod
Yuki Kimoto authored on 2011-09-02
510
eval { $dbi->execute("drop table $table1") };
511
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
512
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
updated pod
Yuki Kimoto authored on 2011-09-02
513
  wrap => {$key1 => sub { "$_[0] - 1" }});
test cleanup
Yuki Kimoto authored on 2011-11-01
514
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
updated pod
Yuki Kimoto authored on 2011-09-02
515
$result = $dbi->execute("select * from $table1");
516
$rows   = $result->all;
517
is_deeply($rows, [{$key1 => 0, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
518

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
519
eval { $dbi->execute("drop table $table1") };
520
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
521
$dbi->insert_timestamp(
522
    $key1 => '5'
523
);
test cleanup
Yuki Kimoto authored on 2011-11-01
524
$dbi->insert({$key2 => 2}, table => $table1, timestamp => 1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
525
$result = $dbi->execute("select * from $table1");
526
$rows   = $result->all;
527
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
528

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

            
539
eval { $dbi->execute("drop table $table1") };
540
$dbi->execute($create_table1);
541
$dbi->insert_timestamp(
542
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
543
);
544
$dbi->insert(table => $table1, timestamp => 1);
545
$result = $dbi->execute("select * from $table1");
546
$rows   = $result->all;
547
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
548

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
549
eval { $dbi->execute("drop table $table1") };
550
$dbi->execute($create_table1_2);
551
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
552
$dbi->insert($param, table => $table1, created_at => $key2);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
553
$result = $dbi->select(table => $table1);
554
is_deeply($param, {$key1 => 1});
555
$row   = $result->one;
556
is($row->{$key1}, 1);
557
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
558

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
581
eval { $dbi->execute("drop table $table1") };
582
$dbi->execute($create_table1_2);
583
$model = $dbi->create_model(table => $table1, created_at => $key2);
584
$param = {$key1 => 1};
585
$model->insert($param);
586
$result = $dbi->select(table => $table1);
587
is_deeply($param, {$key1 => 1});
588
$row   = $result->one;
589
is($row->{$key1}, 1);
590
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
591

            
592
eval { $dbi->execute("drop table $table1") };
593
$dbi->execute($create_table1_2);
594
$param = {$key1 => 1};
595
$model = $dbi->create_model(table => $table1, updated_at => $key3);
596
$model->insert($param);
597
$result = $dbi->select(table => $table1);
598
is_deeply($param, {$key1 => 1});
599
$row   = $result->one;
600
is($row->{$key1}, 1);
601
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
602

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
616
test 'update_or_insert';
617
eval { $dbi->execute("drop table $table1") };
618
$dbi->execute($create_table1);
619
$dbi->update_or_insert(
620
    {$key2 => 2},
621
    table => $table1,
622
    primary_key => $key1,
623
    id => 1
624
);
625
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
626
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
627

            
628
$dbi->update_or_insert(
629
    {$key2 => 3},
630
    table => $table1,
631
    primary_key => $key1,
632
    id => 1
633
);
634
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
635
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
636

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
637
eval {
638
    $dbi->update_or_insert(
639
        {$key2 => 3},
640
        table => $table1,
641
    );
642
};
643

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

            
micro optimization
Yuki Kimoto authored on 2011-10-31
646
test 'model update_or_insert';
647
eval { $dbi->execute("drop table $table1") };
648
$dbi->execute($create_table1);
649
$model = $dbi->create_model(
650
    table => $table1,
651
    primary_key => $key1
652
);
653
$model->update_or_insert({$key2 => 2}, id => 1);
654
$row = $model->select(id => 1)->one;
655
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
656

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
657
test 'default_bind_filter';
658
$dbi->execute("delete from $table1");
659
$dbi->register_filter(
660
    twice       => sub { $_[0] * 2 },
661
    three_times => sub { $_[0] * 3 }
662
);
663
$dbi->default_bind_filter('twice');
cleanup
Yuki Kimoto authored on 2011-11-01
664
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
665
$result = $dbi->execute("select * from $table1");
666
$rows   = $result->all;
667
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
668
$dbi->default_bind_filter(undef);
669

            
test cleanup
Yuki Kimoto authored on 2011-08-10
670
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
671
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
672
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
673
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
674
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
675
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
676
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
677
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
678
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
679
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
680
                  "basic");
681
                  
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
682
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
683
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
684
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
685
$dbi->update({$key2 => 12}, table => $table1, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
686
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
687
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
688
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
689
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
690
                  "update key same as search key");
691

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
699
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
700
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
701
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
702
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
703
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
704
              filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
705
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
706
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
707
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
708
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
709
                  "filter");
710

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
716
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
717
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
718
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
719
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
720
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
721
$where->param({$key1 => 1, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
722
$dbi->update({$key1 => 3}, table => $table1, where => $where);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
723
$result = $dbi->select(table => $table1);
724
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
725

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
726
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
727
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
728
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
729
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
730
    {$key1 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
731
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
732
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
733
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
734
        {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
735
    ]
736
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
737
$result = $dbi->select(table => $table1);
738
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
739

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
740
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
741
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
742
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
743
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
744
$where->clause(['and', "$key2 = :$key2"]);
745
$where->param({$key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
746
$dbi->update({$key1 => 3}, table => $table1, where => $where);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
747
$result = $dbi->select(table => $table1);
748
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
749

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
756
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
757
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
758
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
759
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
760
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
761
$dbi->insert({select => 1}, table => 'table');
762
$dbi->update({update => 2}, table => 'table', where => {select => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
763
$result = $dbi->execute("select * from ${q}table$p");
764
$rows   = $result->all;
765
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
766

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

            
770
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
771
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
772
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
773
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
774
$dbi->insert({select => 1}, table => 'table');
775
$dbi->update({update => 2}, table => 'table', where => {'table.select' => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
776
$result = $dbi->execute("select * from ${q}table$p");
777
$rows   = $result->all;
778
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
779

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
780
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
781
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
782
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
783
$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
784
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
785
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
786
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
787
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
788
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
789
                  "basic");
790

            
updated pod
Yuki Kimoto authored on 2011-09-02
791
eval { $dbi->execute("drop table $table1") };
792
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
793
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
794
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
795
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
updated pod
Yuki Kimoto authored on 2011-09-02
796
wrap => {$key2 => sub { "$_[0] - 1" }});
797
$result = $dbi->execute("select * from $table1 order by $key1");
798
$rows   = $result->all;
799
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5},
800
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
801
                  "basic");
802

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
803
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
804
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
805
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
806
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
807
$dbi->update({$key2 => \"'11'"}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
808
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
809
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
810
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
811
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
812
                  "basic");
813

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
814
eval { $dbi->execute("drop table $table1") };
815
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
816
$dbi->update_timestamp(
817
    $key1 => '5'
818
);
test cleanup
Yuki Kimoto authored on 2011-11-01
819
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
820
$dbi->update(table => $table1, timestamp => 1, where => {$key2 => 2});
821
$result = $dbi->execute("select * from $table1");
822
$rows   = $result->all;
823
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
824

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
825
eval { $dbi->execute("drop table $table1") };
826
$dbi->execute($create_table1);
827
$dbi->update_timestamp(
828
    [$key1, $key2] => sub { '5' }
829
);
test cleanup
Yuki Kimoto authored on 2011-11-01
830
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
831
$dbi->update_all(table => $table1, timestamp => 1);
832
$result = $dbi->execute("select * from $table1");
833
$rows   = $result->all;
834
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
835

            
836
eval { $dbi->execute("drop table $table1") };
837
$dbi->execute($create_table1);
838
$dbi->update_timestamp(
839
    [$key1, $key2] => sub { "" . DBIx::Custom->new }
840
);
test cleanup
Yuki Kimoto authored on 2011-11-01
841
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
842
$dbi->update_all(table => $table1, timestamp => 1);
843
$result = $dbi->execute("select * from $table1");
844
$rows   = $result->all;
845
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
846

            
micro optimization and
Yuki Kimoto authored on 2011-10-25
847
eval { $dbi->execute("drop table $table1") };
848
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
849
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
850
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
851
$param = {$key2 => 11};
852
$dbi->update($param, table => $table1, where => {$key1 => 1});
853
is_deeply($param, {$key2 => 11});
854
$result = $dbi->execute("select * from $table1 order by $key1");
855
$rows   = $result->all;
856
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
857
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
858
                  "basic");
859

            
860
eval { $dbi->execute("drop table $table1") };
861
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
862
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
863
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
864
$param = {$key2 => 11};
865
$dbi->update($param, table => $table1, where => {$key2 => 2});
866
is_deeply($param, {$key2 => 11});
867
$result = $dbi->execute("select * from $table1 order by $key1");
868
$rows   = $result->all;
869
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
870
                  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
871
                  "basic");
872

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
873
eval { $dbi->execute("drop table $table1") };
874
$dbi->execute($create_table1_2);
875
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
876
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
877
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key1 => 1});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
878
$result = $dbi->select(table => $table1);
879
is_deeply($param, {$key3 => 4});
880
$row   = $result->one;
881
is($row->{$key3}, 4);
882
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
883

            
884
eval { $dbi->execute("drop table $table1") };
885
$dbi->execute($create_table1_2);
886
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
887
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
888
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key3 => 3});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
889
$result = $dbi->select(table => $table1);
890
is_deeply($param, {$key3 => 4});
891
$row   = $result->one;
892
is($row->{$key3}, 4);
893
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
894

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
895
eval { $dbi->execute("drop table $table1") };
896
$dbi->execute($create_table1_2);
897
$model = $dbi->create_model(table => $table1, updated_at => $key2);
898
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
899
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
900
$model->update($param, where => {$key1 => 1});
901
$result = $dbi->select(table => $table1);
902
is_deeply($param, {$key3 => 4});
903
$row   = $result->one;
904
is($row->{$key3}, 4);
905
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
906

            
test cleanup
Yuki Kimoto authored on 2011-08-10
907
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
908
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
909
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
910
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
911
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
912
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
913
$dbi->update_all({$key2 => 10}, table => $table1, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
914
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
915
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
916
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
917
                  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
test cleanup
Yuki Kimoto authored on 2011-08-10
918
                  "filter");
919

            
920

            
921
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
922
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
923
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
924
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
925
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
926
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
927
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
928
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
929
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
930

            
cleanup test
Yuki Kimoto authored on 2011-08-15
931
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
932
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
933
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
934
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
935
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
936
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
937
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
938
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
939

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
942
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
943
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
944
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
945
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
946
$rows = $dbi->select(table => $table1)->all;
947
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
948

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
949
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
950
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
951
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
952
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
953
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
954
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
955
$where->param({ke1 => 1, $key2 => 2});
956
$dbi->delete(table => $table1, where => $where);
957
$result = $dbi->select(table => $table1);
958
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
959

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
974
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
975
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
976
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
977
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
978
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
979
$rows   = $result->all;
980
is_deeply($rows, [], "basic");
981

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
991
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
992
$dbi = DBIx::Custom->connect;
993
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
994
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
995
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
996
$dbi->insert({select => 1}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
997
$dbi->delete(table => 'table', where => {select => 1});
998
$result = $dbi->execute("select * from ${q}table$p");
999
$rows   = $result->all;
1000
is_deeply($rows, [], "reserved word");
1001

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

            
1012

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1036
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1037
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
1038
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1039
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1040
    table => [$table1, $table2],
1041
    column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
1042
    where   => {"$table1.$key2" => 2},
1043
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1044
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1045
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
1046

            
1047
$rows = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1048
    table => [$table1, $table2],
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1049
    column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1050
    relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1051
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1052
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
1053

            
1054
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
1055
eval { $dbi->execute("drop table ${q}table$p") };
1056
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1057
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1058
$dbi->insert({select => 1, update => 2}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1059
$result = $dbi->select(table => 'table', where => {select => 1});
1060
$rows   = $result->all;
1061
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
1062

            
1063
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1064
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1065
$dbi->register_filter(
1066
    twice       => sub { $_[0] * 2 },
1067
    three_times => sub { $_[0] * 3 }
1068
);
1069
$dbi->default_fetch_filter('twice');
1070
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1071
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1072
$result = $dbi->select(table => $table1);
1073
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1074
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1075
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1076

            
1077
test 'filters';
1078
$dbi = DBIx::Custom->new;
1079

            
1080
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
1081
   'あ', "decode_utf8");
1082

            
1083
is($dbi->filters->{encode_utf8}->('あ'),
1084
   encode_utf8('あ'), "encode_utf8");
1085

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1086
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1087
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1088
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1089
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1090
$dbi->begin_work;
1091
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1092
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1093
$dbi->rollback;
1094
$dbi->dbh->{AutoCommit} = 1;
1095

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

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

            
1100
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1101
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1102
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1103
$dbi->begin_work;
1104
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1105
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1106
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1107
$dbi->commit;
1108
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1109
$result = $dbi->select(table => $table1);
1110
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1111
          "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1112

            
1113
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1114
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1115
$dbi->execute($create_table1);
1116
{
1117
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1118
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1119
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1120
    like($@, qr/\.t /, "fail : not verbose");
1121
}
1122
{
1123
    local $Carp::Verbose = 1;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1124
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1125
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1126
}
1127

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

            
1133
{
1134
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1135
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1136
    like($@, qr/\Q.t /, "caller spec : not vebose");
1137
}
1138
{
1139
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1140
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1141
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1142
}
1143

            
1144

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1145
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1146
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1147
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1148
$dbi->execute($create_table1);
1149

            
1150
$dbi->begin_work;
1151

            
1152
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1153
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1154
    die "Error";
test cleanup
Yuki Kimoto authored on 2011-11-01
1155
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1156
};
1157

            
1158
$dbi->rollback if $@;
1159

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

            
1164
$dbi->begin_work;
1165

            
1166
eval {
test cleanup
Yuki Kimoto authored on 2011-11-01
1167
    $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1168
    $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1169
};
1170

            
1171
$dbi->commit unless $@;
1172

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

            
1177
$dbi->dbh->{AutoCommit} = 0;
1178
eval{ $dbi->begin_work };
1179
ok($@, "exception");
1180
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1181

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1182
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1183
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1184
$dbi->cache(1);
1185
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1186
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1187
$dbi->execute($source, {}, query => 1);
1188
is_deeply($dbi->{_cached}->{$source}, 
cleanup test
Yuki Kimoto authored on 2011-08-15
1189
          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1190

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1191
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1192
$dbi->execute($create_table1);
1193
$dbi->{_cached} = {};
1194
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1195
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1196
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1197

            
1198
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1199
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1200
$dbi->execute($create_table1);
1201
{
1202
    local $Carp::Verbose = 0;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1203
    eval{$dbi->execute("select * frm $table1")};
cleanup test
Yuki Kimoto authored on 2011-08-15
1204
    like($@, qr/\Qselect * frm $table1/, "fail prepare");
test cleanup
Yuki Kimoto authored on 2011-08-10
1205
    like($@, qr/\.t /, "fail : not verbose");
1206
}
1207
{
1208
    local $Carp::Verbose = 1;
- removed argument checking ...
Yuki Kimoto authored on 2011-10-21
1209
    eval{$dbi->execute("select * frm $table1")};
test cleanup
Yuki Kimoto authored on 2011-08-10
1210
    like($@, qr/Custom.*\.t /s, "fail : verbose");
1211
}
1212

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

            
1218
{
1219
    local $Carp::Verbose = 0;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1220
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1221
    like($@, qr/\Q.t /, "caller spec : not vebose");
1222
}
1223
{
1224
    local $Carp::Verbose = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1225
    eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1226
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
1227
}
1228

            
1229
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1230
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1231
    one => sub { 1 }
1232
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1233
$dbi->helper(
test cleanup
Yuki Kimoto authored on 2011-08-10
1234
    two => sub { 2 }
1235
);
1236
$dbi->method({
1237
    twice => sub {
1238
        my $self = shift;
1239
        return $_[0] * 2;
1240
    }
1241
});
1242

            
1243
is($dbi->one, 1, "first");
1244
is($dbi->two, 2, "second");
1245
is($dbi->twice(5), 10 , "second");
1246

            
1247
eval {$dbi->XXXXXX};
1248
ok($@, "not exists");
1249

            
1250
test 'out filter';
1251
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1252
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1253
$dbi->execute($create_table1);
1254
$dbi->register_filter(twice => sub { $_[0] * 2 });
1255
$dbi->register_filter(three_times => sub { $_[0] * 3});
1256
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1257
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1258
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
1259
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1260
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1261
$row   = $result->fetch_hash_first;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1262
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1263
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1264
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1265
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1266

            
1267
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1268
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1269
$dbi->execute($create_table1);
1270
$dbi->register_filter(twice => sub { $_[0] * 2 });
1271
$dbi->register_filter(three_times => sub { $_[0] * 3});
1272
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1273
    $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1274
              $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1275
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1276
    $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1277
); 
test cleanup
Yuki Kimoto authored on 2011-11-01
1278
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1279
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1280
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1281
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1282

            
1283
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1284
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1285
$dbi->execute($create_table1);
1286
$dbi->register_filter(twice => sub { $_[0] * 2 });
1287
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1288
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1289
);
cleanup
Yuki Kimoto authored on 2011-11-01
1290
$dbi->insert({$key1 => 1, $key2 => 2},table => $table1, filter => {$key1 => undef});
1291
$dbi->update({$key1 => 2}, table => $table1, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1292
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1293
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1294
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
test cleanup
Yuki Kimoto authored on 2011-08-10
1295

            
1296
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1297
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1298
$dbi->execute($create_table1);
1299
$dbi->register_filter(twice => sub { $_[0] * 2 });
1300
$dbi->apply_filter(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1301
    $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1302
);
cleanup
Yuki Kimoto authored on 2011-11-01
1303
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1=> undef});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1304
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1305
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1306
$rows   = $result->all;
1307
is_deeply($rows, [], "delete");
1308

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

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

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

            
1349
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1350
eval { $dbi->execute("drop table $table1") };
1351
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1352
$dbi->execute($create_table1);
1353
$dbi->execute($create_table2);
1354
$dbi->register_filter(twice => sub { $_[0] * 2 });
1355
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1356
$dbi->apply_filter(
cleanup test
Yuki Kimoto authored on 2011-08-15
1357
    $table1, $key2 => {out => 'twice', in => 'twice'}
1358
);
1359
$dbi->apply_filter(
1360
    $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1361
);
cleanup
Yuki Kimoto authored on 2011-11-01
1362
$dbi->insert({$key1 => 5, $key2 => 2}, table => $table1, filter => {$key2 => undef});
1363
$dbi->insert({$key1 => 5, $key3 => 6}, table => $table2, filter => {$key3 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1364
$result = $dbi->select(
1365
     table => [$table1, $table2],
1366
     column => [$key2, $key3],
1367
     where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1368

            
1369
$result->filter({$key2 => 'twice'});
1370
$rows   = $result->all;
1371
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1372

            
1373
$result = $dbi->select(
1374
     table => [$table1, $table2],
1375
     column => [$key2, $key3],
1376
     where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
1377

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

            
1382
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1383
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1384
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1385
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1386
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1387
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1388

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1389
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1390
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1391
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1392
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1393
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1394
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1395

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

            
1402
test 'end_filter';
1403
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1404
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1405
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1406
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1407
$result = $dbi->select(table => $table1);
1408
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1409
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1410
$row = $result->fetch_first;
1411
is_deeply($row, [6, 40]);
1412

            
1413
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1414
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1415
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1416
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1417
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1418
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1419
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1420
$row = $result->fetch_first;
1421
is_deeply($row, [6, 12]);
1422

            
1423
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1424
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1425
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1426
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1427
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1428
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1429
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1430
$row = $result->fetch_first;
1431
is_deeply($row, [6, 12]);
1432

            
1433
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1434
$result = $dbi->select(table => $table1);
1435
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1436
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1437
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1438
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1439

            
1440
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1441
$dbi->apply_filter($table1,
1442
    $key1 => {end => sub { $_[0] * 3 } },
1443
    $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1444
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1445
$result = $dbi->select(table => $table1);
1446
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1447
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1448
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1449

            
1450
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1451
$dbi->apply_filter($table1,
1452
    $key1 => {end => sub { $_[0] * 3 } },
1453
    $key2 => {end => 'five_times'}
1454
);
1455
$result = $dbi->select(table => $table1);
1456
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1457
$result->filter($key1 => undef);
1458
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1459
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1460
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1461

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

            
1476
test 'empty where select';
1477
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1478
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1479
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1480
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1481
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1482
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1483
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1484

            
1485
test 'select query option';
1486
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1487
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1488
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1489
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1490
is(ref $query, 'DBIx::Custom::Query');
cleanup
Yuki Kimoto authored on 2011-11-01
1491
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1492
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1493
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1494
is(ref $query, 'DBIx::Custom::Query');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1495
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1496
is(ref $query, 'DBIx::Custom::Query');
1497

            
1498
test 'where';
1499
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1500
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1501
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1502
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1503
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1504
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1505
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1506

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

            
1511
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1512
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1513
    where => $where
1514
);
1515
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1516
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1517

            
1518
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1519
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1520
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1521
        ['and', "$key1 = :$key1", "$key2 = :$key2"],
1522
        {$key1 => 1}
test cleanup
Yuki Kimoto authored on 2011-08-10
1523
    ]
1524
);
1525
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1526
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1527

            
1528
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1529
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1530
             ->param({$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1531
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1532
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1533
    where => $where
1534
);
1535
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1536
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1537

            
1538
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1539
             ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
test cleanup
Yuki Kimoto authored on 2011-08-10
1540
             ->param({});
1541
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1542
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1543
    where => $where,
1544
);
1545
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1546
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1547

            
1548
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1549
             ->clause(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"])
1550
             ->param({$key1 => [0, 3], $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1551
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1552
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1553
    where => $where,
1554
); 
1555
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1556
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1557

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

            
1566
eval {
1567
$where = $dbi->where
1568
             ->clause(['uuu']);
1569
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1570
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1571
    where => $where
1572
);
1573
};
1574
ok($@);
1575

            
1576
$where = $dbi->where;
1577
is("$where", '');
1578

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

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

            
1599
$where = $dbi->where
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1600
             ->clause(['or', ("$key1 = :$key1") x 2])
1601
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1602
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1603
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1604
    where => $where,
1605
);
1606
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1607
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1608

            
1609
$where = $dbi->where
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1610
             ->clause("$key1 = :$key1")
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1611
             ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1612
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1613
    table => $table1,
test cleanup
Yuki Kimoto authored on 2011-08-10
1614
    where => $where,
1615
);
1616
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1617
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1618

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1748
eval {$dbi->where(ppp => 1) };
1749
like($@, qr/invalid/);
1750

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

            
1762

            
1763
$where = $dbi->where(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1764
    clause => ['and', ['or'], ['or', ":$key1", ":$key2"]],
test cleanup
Yuki Kimoto authored on 2011-08-10
1765
    param => {}
1766
);
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 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
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
$where->clause(['and', ":${key1}{=}"]);
1776
$where->param({$key1 => undef});
1777
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1778
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1779
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1780

            
1781
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1782
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1783
$where->param({$key1 => [undef, undef]});
1784
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1785
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1786
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1787
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1788
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1789
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1790

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

            
1792
$dbi = DBIx::Custom->connect;
1793
eval { $dbi->execute("drop table $table1") };
1794
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1795
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
1796
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1797
$where = $dbi->where
1798
             ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
1799
             ->param({$key1 => 1});
1800

            
1801
$result = $dbi->select(
1802
    table => $table1,
1803
    where => $where
1804
);
1805
$row = $result->all;
1806
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
1807

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1808
test 'register_tag_processor';
1809
$dbi = DBIx::Custom->connect;
1810
$dbi->register_tag_processor(
1811
    a => sub { 1 }
1812
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1813
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1814

            
1815
test 'register_tag';
1816
$dbi = DBIx::Custom->connect;
1817
$dbi->register_tag(
1818
    b => sub { 2 }
1819
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1820
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1821

            
1822
test 'table not specify exception';
1823
$dbi = DBIx::Custom->connect;
1824
eval {$dbi->select};
1825
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1826

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1827
test 'more tests';
1828
$dbi = DBIx::Custom->connect;
1829
eval{$dbi->apply_filter('table', 'column', [])};
1830
like($@, qr/apply_filter/);
1831

            
1832
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1833
like($@, qr/apply_filter/);
1834

            
1835
$dbi->apply_filter(
1836

            
1837
);
1838
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1839
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1840
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1841
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1842
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1843
$dbi->apply_filter($table1, $key2, 
test cleanup
Yuki Kimoto authored on 2011-08-10
1844
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1845
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
1846
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1847

            
1848
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1849
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1850
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1851
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1852
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1853
$dbi->apply_filter($table1, $key2, {});
1854
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
1855
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1856

            
1857
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1858
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1859
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1860
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
1861
like($@, qr/not registered/);
1862
$dbi->method({one => sub { 1 }});
1863
is($dbi->one, 1);
1864

            
1865
eval{DBIx::Custom->connect(dsn => undef)};
1866
like($@, qr/_connect/);
1867

            
1868
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1869
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1870
$dbi->execute($create_table1);
1871
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
1872
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1873
             filter => {$key1 => 'twice'});
1874
$row = $dbi->select(table => $table1)->one;
1875
is_deeply($row, {$key1 => 2, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
1876
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1877
             filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
1878
like($@, qr//);
1879

            
1880
$dbi->register_filter(one => sub { });
1881
$dbi->default_fetch_filter('one');
1882
ok($dbi->default_fetch_filter);
1883
$dbi->default_bind_filter('one');
1884
ok($dbi->default_bind_filter);
1885
eval{$dbi->default_fetch_filter('no')};
1886
like($@, qr/not registered/);
1887
eval{$dbi->default_bind_filter('no')};
1888
like($@, qr/not registered/);
1889
$dbi->default_bind_filter(undef);
1890
ok(!defined $dbi->default_bind_filter);
1891
$dbi->default_fetch_filter(undef);
1892
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1893
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1894
like($@, qr/Tag not finished/);
1895

            
1896
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1897
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1898
$dbi->execute($create_table1);
1899
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1900
$result = $dbi->select(table => $table1);
1901
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1902
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1903
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
1904
like($@, qr/not registered/);
1905
$result->default_filter(undef);
1906
ok(!defined $result->default_filter);
1907
$result->default_filter('one');
1908
is($result->default_filter->(), 1);
1909

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1910
test 'option';
1911
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
1912
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
1913
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
1914
ok($dbi->dbh->{PrintError});
1915
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
1916
ok($dbi->dbh->{PrintError});
1917

            
1918
test 'DBIx::Custom::Result stash()';
1919
$result = DBIx::Custom::Result->new;
1920
is_deeply($result->stash, {}, 'default');
1921
$result->stash->{foo} = 1;
1922
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
1923

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1924
test 'delete_at';
1925
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1926
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1927
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
1928
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
1929
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1930
    table => $table1,
1931
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1932
    where => [1, 2],
1933
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1934
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1935

            
cleanup
Yuki Kimoto authored on 2011-11-01
1936
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
1937
$dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1938
    table => $table1,
1939
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1940
    where => 1,
1941
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1942
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
1943

            
1944
test 'insert_at';
1945
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1946
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1947
$dbi->execute($create_table1_2);
1948
$dbi->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
1949
    {$key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1950
    primary_key => [$key1, $key2], 
1951
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1952
    where => [1, 2],
1953
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1954
is($dbi->select(table => $table1)->one->{$key1}, 1);
1955
is($dbi->select(table => $table1)->one->{$key2}, 2);
1956
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
1957

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1958
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1959
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
1960
$dbi->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
1961
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1962
    primary_key => $key1, 
1963
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
1964
    where => 1,
1965
);
1966

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

            
1971
eval {
1972
    $dbi->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
1973
        {$key1 => 1, $key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1974
        table => $table1,
1975
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
1976
        where => {},
1977
    );
1978
};
1979
like($@, qr/must be/);
1980

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

            
1994
test 'update_at';
1995
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1996
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
1997
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1998
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
1999
$dbi->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2000
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2001
    table => $table1,
2002
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2003
    where => [1, 2],
2004
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2005
is($dbi->select(table => $table1)->one->{$key1}, 1);
2006
is($dbi->select(table => $table1)->one->{$key2}, 2);
2007
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2008

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2009
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2010
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2011
$dbi->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2012
    {$key3 => 4},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2013
    table => $table1,
2014
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2015
    where => 1,
2016
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2017
is($dbi->select(table => $table1)->one->{$key1}, 1);
2018
is($dbi->select(table => $table1)->one->{$key2}, 2);
2019
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2020

            
2021
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2022
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2023
$dbi->execute($create_table1_2);
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->update_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2026
    {$key3 => 4},
2027
    table => $table1,
2028
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2029
    where => [1, 2]
2030
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2031
is($dbi->select(table => $table1)->one->{$key1}, 1);
2032
is($dbi->select(table => $table1)->one->{$key2}, 2);
2033
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2034

            
2035
test 'select_at';
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);
test cleanup
Yuki Kimoto authored on 2011-11-01
2039
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2040
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2041
    table => $table1,
2042
    primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2043
    where => [1, 2]
2044
);
2045
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2046
is($row->{$key1}, 1);
2047
is($row->{$key2}, 2);
2048
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2049

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2050
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2051
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2052
$result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2053
    table => $table1,
2054
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2055
    where => 1,
2056
);
2057
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2058
is($row->{$key1}, 1);
2059
is($row->{$key2}, 2);
2060
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2061

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

            
2074
eval {
2075
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2076
        table => $table1,
2077
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2078
        where => {},
2079
    );
2080
};
2081
like($@, qr/must be/);
2082

            
2083
eval {
2084
    $result = $dbi->select_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2085
        table => $table1,
2086
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2087
        where => [1],
2088
    );
2089
};
2090
like($@, qr/same/);
2091

            
2092
eval {
2093
    $result = $dbi->update_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2094
        {$key1 => 1, $key2 => 2},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2095
        table => $table1,
2096
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2097
        where => {},
2098
    );
2099
};
2100
like($@, qr/must be/);
2101

            
2102
eval {
2103
    $result = $dbi->delete_at(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2104
        table => $table1,
2105
        primary_key => [$key1, $key2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2106
        where => {},
2107
    );
2108
};
2109
like($@, qr/must be/);
2110

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

            
2129
test 'model insert_at';
2130
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2131
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2132
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2133
$dbi->model($table1)->insert_at(
test cleanup
Yuki Kimoto authored on 2011-11-01
2134
    {$key3 => 3},
cleanup test
Yuki Kimoto authored on 2011-08-10
2135
    where => [1, 2],
2136
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2137
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2138
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2139
is($row->{$key1}, 1);
2140
is($row->{$key2}, 2);
2141
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2142

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

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

            
2169

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

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

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

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

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

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

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

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

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

            
2282
$params = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2283
    {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2284
    {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2285
];
2286
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2287
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
2288

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
2309
$rows = $dbi->select(
2310
    table => $table1,
2311
    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2312
    where   => {"$table1.$key2" => 3},
2313
    join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2314
             " $table2 on $table1.$key1 = $table2.$key1",
2315
    param => {"$table2.$key3" => 5}
2316
)->all;
2317
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2318

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

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

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

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

            
2374
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2375
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2376
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2377
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2378
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2379
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2380
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2381
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2382
        "$key1 = :$key1 and $key2 = :$key2",
2383
         {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2384
    ]
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

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

            
2404
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2405
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2406
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2407
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2408
$dbi->update(
cleanup
Yuki Kimoto authored on 2011-11-01
2409
    {$key1 => 5},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2410
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2411
    where => [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2412
        "$key1 = :$key1 and $key2 = :$key2",
2413
        {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2414
    ]
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
test 'insert id and primary_key option';
2420
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2421
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2422
$dbi->execute($create_table1_2);
2423
$dbi->insert(
cleanup
Yuki Kimoto authored on 2011-11-01
2424
    {$key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2425
    primary_key => [$key1, $key2], 
2426
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2427
    id => [1, 2],
2428
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2429
is($dbi->select(table => $table1)->one->{$key1}, 1);
2430
is($dbi->select(table => $table1)->one->{$key2}, 2);
2431
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2432

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2433
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2434
$dbi->insert(
cleanup
Yuki Kimoto authored on 2011-11-01
2435
    {$key2 => 2, $key3 => 3},
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2436
    primary_key => $key1, 
2437
    table => $table1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2438
    id => 0,
2439
);
2440

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2529
$dbi->delete_all(table => $table1);
2530
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2531
$dbi->update(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2532
    table => $table1,
2533
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2534
    id => 0,
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2535
    param => {$key3 => 4}
cleanup test
Yuki Kimoto authored on 2011-08-10
2536
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2537
is($dbi->select(table => $table1)->one->{$key1}, 0);
2538
is($dbi->select(table => $table1)->one->{$key2}, 2);
2539
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2540

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

            
2555

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

            
2571

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2584
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2585
$dbi->delete(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2586
    table => $table1,
2587
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2588
    id => 0,
2589
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2590
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2591

            
2592

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

            
2611

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2627
$dbi->delete_all(table => $table1);
2628
$dbi->insert(table => $table1, param => {$key1 => 0, $key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2629
$result = $dbi->select(
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2630
    table => $table1,
2631
    primary_key => $key1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2632
    id => 0,
2633
);
2634
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2635
is($row->{$key1}, 0);
2636
is($row->{$key2}, 2);
2637
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2638

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

            
2651

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

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

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

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

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

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

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

            
2747

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2770
test 'available_datetype';
2771
$dbi = DBIx::Custom->connect;
2772
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2773

            
2774

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

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

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

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

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

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

            
2817
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2818
    id => {key => "$table1.id"},
2819
    price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2820
);
2821
is_deeply($param, {"$table1.price" => undef});
2822

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3045
$source = "select * from $table1 where :${key1}{=} and :${key2}{=}";
3046
$result = $dbi->execute($source, param => {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
3047
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3048
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3049

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

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

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

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

            
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_highperformance);
3092
$rows = [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3093
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3094
    {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3095
];
3096
{
3097
    my $query;
3098
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
3099
    for my $row (@$rows) {
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3100
      $query ||= $dbi->insert($row, table => $table1, query => 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3101
      $sth ||= $query->sth;
3102
      $sth->execute(map { $row->{$_} } sort keys %$row);
3103
    }
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3104
    is_deeply($dbi->select(table => $table1)->all,
test cleanup
Yuki Kimoto authored on 2011-08-10
3105
      [
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3106
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3107
          {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3108
      ]
3109
    );
3110
}
3111

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

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

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

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

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

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

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

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

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

            
3214
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3215
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3216
$rows = $result->fetch_all;
3217
is_deeply($rows, [[1, 2], [3, 4]]);
3218

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

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

            
3227
$rows = $result->fetch_all;
3228
is_deeply($rows, [[3, 2], [9, 4]], "array");
3229

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3303
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3304
    q => 'string'
3305
});
3306

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3310
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3311
   r => sub {} 
3312
});
3313

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3317
$dbi->register_tag({
test cleanup
Yuki Kimoto authored on 2011-08-10
3318
   s => sub { return ["a", ""]} 
3319
});
3320

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

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

            
3328

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

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

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

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

            
3344
test 'variouse source';
3345
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3346
$query = $builder->build_query($source);
3347
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3348

            
3349
$source = "abc";
3350
$query = $builder->build_query($source);
3351
is($query->sql, 'abc', "basic : 2");
3352

            
3353
$source = "{= a}";
3354
$query = $builder->build_query($source);
3355
is($query->sql, 'a = ?', "only tag");
3356

            
3357
$source = "000";
3358
$query = $builder->build_query($source);
3359
is($query->sql, '000', "contain 0 value");
3360

            
3361
$source = "a {= b} }";
3362
eval{$builder->build_query($source)};
3363
like($@, qr/unexpected "}"/, "error : 1");
3364

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

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

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

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

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

            
3434
$dbi->separator('__');
3435
$result = $model->select(
3436
    column => [
3437
        $model->column($table2, {alias => $table2_alias})
3438
    ],
3439
    where => {"$table2_alias.$key3" => 4}
3440
);
3441
is_deeply($result->one, 
3442
          {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
3443

            
3444
$dbi->separator('-');
3445
$result = $model->select(
3446
    column => [
3447
        $model->column($table2, {alias => $table2_alias})
3448
    ],
3449
    where => {"$table2_alias.$key3" => 4}
3450
);
3451
is_deeply($result->one, 
3452
          {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
3453

            
3454
test 'create_model';
3455
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3456
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3457
eval { $dbi->execute("drop table $table1") };
3458
eval { $dbi->execute("drop table $table2") };
3459
$dbi->execute($create_table1);
3460
$dbi->execute($create_table2);
3461

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

            
3490
test 'model method';
3491
$dbi = DBIx::Custom->connect;
3492
eval { $dbi->execute("drop table $table2") };
3493
$dbi->execute($create_table2);
3494
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3495
$model = $dbi->create_model(
3496
    table => $table2
3497
);
3498
$model->method(foo => sub { shift->select(@_) });
3499
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3500

            
3501
test 'model helper';
3502
$dbi = DBIx::Custom->connect;
3503
eval { $dbi->execute("drop table $table2") };
3504
$dbi->execute($create_table2);
3505
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3506
$model = $dbi->create_model(
3507
    table => $table2
3508
);
3509
$model->helper(foo => sub { shift->select(@_) });
3510
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3511

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

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

            
3532

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

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

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

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

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

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

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

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

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

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

            
3634
$dbi = MyDBI5->connect;
3635
eval { $dbi->execute("drop table $table1") };
3636
eval { $dbi->execute("drop table $table2") };
3637
$dbi->execute($create_table1);
3638
$dbi->execute($create_table2);
3639
$model = $dbi->model($table2);
3640
$model->insert({$key1 => 'a'});
3641
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
3642
$dbi->insert(table => $table1, param => {$key1 => 1});
3643
$model = $dbi->model($table1);
3644
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3645

            
3646
test 'primary_key';
3647
$dbi = MyDBI1->connect;
3648
$model = $dbi->model($table1);
3649
$model->primary_key([$key1, $key2]);
3650
is_deeply($model->primary_key, [$key1, $key2]);
3651

            
3652
test 'columns';
3653
$dbi = MyDBI1->connect;
3654
$model = $dbi->model($table1);
3655
$model->columns([$key1, $key2]);
3656
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3657

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3664
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3665
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3666
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3667
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3668
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3669

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3699
test 'each_table';
3700
$dbi = DBIx::Custom->connect;
3701
eval { $dbi->execute("drop table $table1") };
3702
eval { $dbi->execute("drop table $table2") };
3703
$dbi->execute($create_table2);
3704
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3705

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

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3723
$dbi = DBIx::Custom->connect;
3724
eval { $dbi->execute("drop table $table1") };
3725
eval { $dbi->execute("drop table $table2") };
3726
$dbi->execute($create_table2);
3727
$dbi->execute($create_table1_type);
3728

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3748
test 'type_rule into';
3749
eval { $dbi->execute("drop table $table1") };
3750
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3751
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3752

            
3753

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3754
$dbi = DBIx::Custom->connect;
3755
eval { $dbi->execute("drop table $table1") };
3756
$dbi->execute($create_table1_type);
3757

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

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

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

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

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

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

            
3878

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3984
eval{$dbi->type_rule(
3985
    into1 => {
3986
        $date_typename => 'pp'
3987
    }
3988
)};
3989
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3990

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4237
$rows = $dbi->select(
4238
    table => $table1,
4239
    where   => {$key1 => 1},
4240
    join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
4241
)->all;
4242
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4243

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

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

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

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

            
4286

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

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

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4394
test 'columns';
4395
$dbi = MyDBI1->connect;
4396
$model = $dbi->model($table1);
4397

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

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