DBIx-Custom / t / common.t /
Newer Older
4623 lines | 151.534kb
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;
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
84
my $affected;
cleanup test
Yuki Kimoto authored on 2011-08-15
85

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
90
  use strict;
91
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
92

            
cleanup
Yuki Kimoto authored on 2012-01-20
93
  use base 'DBIx::Custom';
test cleanup
Yuki Kimoto authored on 2011-08-10
94

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
106
  package MyModel2::Base1;
test cleanup
Yuki Kimoto authored on 2011-08-10
107

            
cleanup
Yuki Kimoto authored on 2012-01-20
108
  use strict;
109
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
110

            
cleanup
Yuki Kimoto authored on 2012-01-20
111
  use base 'DBIx::Custom::Model';
test cleanup
Yuki Kimoto authored on 2011-08-10
112

            
cleanup
Yuki Kimoto authored on 2012-01-20
113
  package MyModel2::table1;
test cleanup
Yuki Kimoto authored on 2011-08-10
114

            
cleanup
Yuki Kimoto authored on 2012-01-20
115
  use strict;
116
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
117

            
cleanup
Yuki Kimoto authored on 2012-01-20
118
  use base 'MyModel2::Base1';
test cleanup
Yuki Kimoto authored on 2011-08-10
119

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
126
  sub list { shift->select; }
test cleanup
Yuki Kimoto authored on 2011-08-10
127

            
cleanup
Yuki Kimoto authored on 2012-01-20
128
  package MyModel2::table2;
test cleanup
Yuki Kimoto authored on 2011-08-10
129

            
cleanup
Yuki Kimoto authored on 2012-01-20
130
  use strict;
131
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-15
132

            
cleanup
Yuki Kimoto authored on 2012-01-20
133
  use base 'MyModel2::Base1';
test cleanup
Yuki Kimoto authored on 2011-08-15
134

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
141
  sub list { shift->select; }
test cleanup
Yuki Kimoto authored on 2011-08-15
142

            
cleanup
Yuki Kimoto authored on 2012-01-20
143
  package MyModel2::TABLE1;
test cleanup
Yuki Kimoto authored on 2011-08-15
144

            
cleanup
Yuki Kimoto authored on 2012-01-20
145
  use strict;
146
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-15
147

            
cleanup
Yuki Kimoto authored on 2012-01-20
148
  use base 'MyModel2::Base1';
test cleanup
Yuki Kimoto authored on 2011-08-15
149

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
156
  sub list { shift->select; }
test cleanup
Yuki Kimoto authored on 2011-08-15
157

            
cleanup
Yuki Kimoto authored on 2012-01-20
158
  package MyModel2::TABLE2;
test cleanup
Yuki Kimoto authored on 2011-08-15
159

            
cleanup
Yuki Kimoto authored on 2012-01-20
160
  use strict;
161
  use warnings;
162

            
163
  use base 'MyModel2::Base1';
164

            
165
  sub insert {
166
    my ($self, $param) = @_;
167
    
168
    return $self->SUPER::insert($param);
169
  }
170

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
176
  use strict;
177
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
178

            
cleanup
Yuki Kimoto authored on 2012-01-20
179
  use base 'DBIx::Custom';
test cleanup
Yuki Kimoto authored on 2011-08-10
180

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

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

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
242
test 'execute reuse option';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
243
eval { $dbi->execute("drop table $table1") };
244
$dbi->execute($create_table1);
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
245
$reuse = {};
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
246
for my $i (1 .. 2) {
cleanup
Yuki Kimoto authored on 2012-01-20
247
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, reuse => $reuse);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
248
}
249
$rows = $dbi->select(table => $table1)->all;
250
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-11-18
251
ok(keys %$reuse);
252
ok((keys %$reuse)[0] !~ /\?/);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
253

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

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

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
272
eval { $dbi->execute("drop table $table1") };
273
$dbi->execute($create_table1);
274
$model = $dbi->create_model(table => $table1);
275
$model->insert({$key1 => 1, $key2 => 2});
276
is_deeply($model->select($key1)->all, [{$key1 => 1}]);
277

            
cleanup test
Yuki Kimoto authored on 2011-08-15
278
test 'DBIx::Custom::Result test';
279
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
280
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
281
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
282
$source = "select $key1, $key2 from $table1";
283
$query = $dbi->create_query($source);
284
$result = $dbi->execute($query);
cleanup
Yuki Kimoto authored on 2011-08-15
285

            
cleanup test
Yuki Kimoto authored on 2011-08-15
286
@rows = ();
287
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
288
  push @rows, [@$row];
cleanup test
Yuki Kimoto authored on 2011-08-15
289
}
290
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
cleanup
Yuki Kimoto authored on 2011-08-15
291

            
cleanup test
Yuki Kimoto authored on 2011-08-15
292
$result = $dbi->execute($query);
293
@rows = ();
294
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
295
  push @rows, {%$row};
cleanup test
Yuki Kimoto authored on 2011-08-15
296
}
297
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
298

            
cleanup test
Yuki Kimoto authored on 2011-08-15
299
$result = $dbi->execute($query);
300
$rows = $result->fetch_all;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
301
is_deeply($rows, [[1, 2], [3, 4]]);
test cleanup
Yuki Kimoto authored on 2011-08-10
302

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2012-01-14
307
is_deeply($dbi->select($key1, table => $table1)->column, [1, 3]);
308

            
309
is($dbi->select('count(*)', table => $table1)->value, 2);
310
ok(!defined $dbi->select($key1, table => $table1, where => {$key1 => 10})->value);
311

            
cleanup test
Yuki Kimoto authored on 2011-08-15
312
test 'Insert query return value';
313
$source = "insert into $table1 {insert_param $key1 $key2}";
314
$query = $dbi->execute($source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
315
$ret_val = $dbi->execute($query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
316
ok($ret_val);
test cleanup
Yuki Kimoto authored on 2011-08-10
317

            
cleanup test
Yuki Kimoto authored on 2011-08-15
318
test 'Direct query';
319
$dbi->delete_all(table => $table1);
320
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
test cleanup
Yuki Kimoto authored on 2011-11-01
321
$dbi->execute($insert_source, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
322
$result = $dbi->execute("select * from $table1");
323
$rows = $result->all;
324
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
325

            
326
test 'Filter basic';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
327
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2012-01-20
328
$dbi->register_filter(twice => sub { $_[0] * 2}, 
329
  three_times => sub { $_[0] * 3});
cleanup test
Yuki Kimoto authored on 2011-08-08
330

            
cleanup test
Yuki Kimoto authored on 2011-08-15
331
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
332
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
333
$insert_query->filter({$key1 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
334
$dbi->execute($insert_query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
335
$result = $dbi->execute("select * from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
336
$rows = $result->filter({$key2 => 'three_times'})->all;
337
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
338

            
339
test 'Filter in';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
340
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
341
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
342
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
343
$dbi->execute($insert_query, {$key1 => 2, $key2 => 4});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
344
$select_source = "select * from $table1 where {in $table1.$key1 2} and {in $table1.$key2 2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
345
$select_query = $dbi->execute($select_source,{}, query => 1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
346
$select_query->filter({"$table1.$key1" => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
347
$result = $dbi->execute($select_query, {"$table1.$key1" => [1,5], "$table1.$key2" => [2,4]});
cleanup test
Yuki Kimoto authored on 2011-08-08
348
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
349
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
350

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

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

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

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

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
405
$result = $dbi->execute("select * from $table1 order by $key1");
cleanup test
Yuki Kimoto authored on 2011-08-08
406
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
407
is_deeply($rows, [{$key1 => 1, $key2 => 1, $key3 => 1, $key4 => 1, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
408
                {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-08
409

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
421
$source = "select * from $table1 where $key1 = \n:$key1\n and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-11-01
422
$result = $dbi->execute($source, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-08
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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
431
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
432
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
433
  $source,
434
  {"$table1.$key1" => 1, "$table1.$key2" => 1},
435
  filter => {"$table1.$key2" => sub { $_[0] * 2 }}
cleanup test
Yuki Kimoto authored on 2011-08-08
436
);
437
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
438
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
439

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
440
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
441
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
442
$dbi->insert({$key1 => '2011-10-14 12:19:18', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
443
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
444
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
445
  $source,
446
  {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
447
);
448

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
453
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
454
$dbi->insert({$key1 => 'a:b c:d', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
455
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
456
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
457
  $source,
458
  {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
459
);
460
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
461
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
462

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
470
test 'insert';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
471
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
472
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
473
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
474
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
475
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
476
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
477
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
478

            
added tests
Yuki Kimoto authored on 2011-11-01
479
eval { $dbi->execute("drop table $table1") };
480
$dbi->execute($create_table1);
481
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
482
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
483
$result = $dbi->execute("select * from $table1");
484
$rows   = $result->all;
485
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
486

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
487
$dbi->execute("delete from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
488
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
489
  twice       => sub { $_[0] * 2 },
490
  three_times => sub { $_[0] * 3 }
cleanup test
Yuki Kimoto authored on 2011-08-10
491
);
492
$dbi->default_bind_filter('twice');
test cleanup
Yuki Kimoto authored on 2011-11-01
493
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
cleanup test
Yuki Kimoto authored on 2011-08-15
494
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
495
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
496
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
497
$dbi->delete_all(table => $table1);
498
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
499
$result = $dbi->execute("select * from $table1");
500
$rows   = $result->all;
501
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-10
502
$dbi->default_bind_filter(undef);
503

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
504

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
514
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
515
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
516
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
test cleanup
Yuki Kimoto authored on 2011-11-01
517
$dbi->insert({select => 1}, table => 'table');
cleanup test
Yuki Kimoto authored on 2011-08-10
518
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
519
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
520
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
cleanup test
Yuki Kimoto authored on 2011-08-10
521

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
522
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
523
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
524
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
525
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
526
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
527
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
528
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
529

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
530
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
531
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
532
$dbi->insert({$key1 => \"'1'", $key2 => 2}, table => $table1);
533
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
534
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
535
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
536
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
537

            
updated pod
Yuki Kimoto authored on 2011-09-02
538
eval { $dbi->execute("drop table $table1") };
539
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
540
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
541
wrap => {$key1 => sub { "$_[0] - 1" }});
test cleanup
Yuki Kimoto authored on 2011-11-01
542
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
updated pod
Yuki Kimoto authored on 2011-09-02
543
$result = $dbi->execute("select * from $table1");
544
$rows   = $result->all;
545
is_deeply($rows, [{$key1 => 0, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
546

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
547
eval { $dbi->execute("drop table $table1") };
548
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
549
$dbi->insert_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
550
  $key1 => '5'
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
551
);
test cleanup
Yuki Kimoto authored on 2011-11-01
552
$dbi->insert({$key2 => 2}, table => $table1, timestamp => 1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
553
$result = $dbi->execute("select * from $table1");
554
$rows   = $result->all;
555
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
556

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
557
eval { $dbi->execute("drop table $table1") };
558
$dbi->execute($create_table1);
559
$dbi->insert_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
560
  [$key1, $key2] => sub { 5 }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
561
);
562
$dbi->insert(table => $table1, timestamp => 1);
563
$result = $dbi->execute("select * from $table1");
564
$rows   = $result->all;
565
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
566

            
567
eval { $dbi->execute("drop table $table1") };
568
$dbi->execute($create_table1);
569
$dbi->insert_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
570
  [$key1, $key2] => sub { "" . DBIx::Custom->new }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
571
);
572
$dbi->insert(table => $table1, timestamp => 1);
573
$result = $dbi->execute("select * from $table1");
574
$rows   = $result->all;
575
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
576

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

            
587
eval { $dbi->execute("drop table $table1") };
588
$dbi->execute($create_table1_2);
589
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
590
$dbi->insert($param, table => $table1, updated_at => $key3);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
591
$result = $dbi->select(table => $table1);
592
is_deeply($param, {$key1 => 1});
593
$row   = $result->one;
594
is($row->{$key1}, 1);
595
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
596

            
597
eval { $dbi->execute("drop table $table1") };
598
$dbi->execute($create_table1_2);
599
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
600
$dbi->insert($param, table => $table1, created_at => $key2, updated_at => $key3);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
601
$result = $dbi->select(table => $table1);
602
is_deeply($param, {$key1 => 1});
603
$row   = $result->one;
604
is($row->{$key1}, 1);
605
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
606
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
607
is($row->{$key2}, $row->{$key3});
608

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
609
eval { $dbi->execute("drop table $table1") };
610
$dbi->execute($create_table1_2);
611
$model = $dbi->create_model(table => $table1, created_at => $key2);
612
$param = {$key1 => 1};
613
$model->insert($param);
614
$result = $dbi->select(table => $table1);
615
is_deeply($param, {$key1 => 1});
616
$row   = $result->one;
617
is($row->{$key1}, 1);
618
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
619

            
620
eval { $dbi->execute("drop table $table1") };
621
$dbi->execute($create_table1_2);
622
$param = {$key1 => 1};
623
$model = $dbi->create_model(table => $table1, updated_at => $key3);
624
$model->insert($param);
625
$result = $dbi->select(table => $table1);
626
is_deeply($param, {$key1 => 1});
627
$row   = $result->one;
628
is($row->{$key1}, 1);
629
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
630

            
631
eval { $dbi->execute("drop table $table1") };
632
$dbi->execute($create_table1_2);
633
$param = {$key1 => 1};
634
$model = $dbi->create_model(table => $table1, created_at => $key2, updated_at => $key3);
635
$model->insert($param);
636
$result = $dbi->select(table => $table1);
637
is_deeply($param, {$key1 => 1});
638
$row   = $result->one;
639
is($row->{$key1}, 1);
640
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
641
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
642
is($row->{$key2}, $row->{$key3});
643

            
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
644
eval { $dbi->execute("drop table $table1") };
645
$dbi->execute($create_table1);
646
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] , table => $table1);
647
$result = $dbi->execute("select * from $table1");
648
$rows   = $result->all;
649
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
650

            
651
eval { $dbi->execute("drop table $table1") };
652
$dbi->execute($create_table1_2);
653
$dbi->insert([{$key1 => 1}, {$key1 => 3}] ,
cleanup
Yuki Kimoto authored on 2012-01-20
654
table => $table1,
655
updated_at => $key2,
656
created_at => $key3
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
657
);
658
$result = $dbi->execute("select * from $table1");
659
$rows   = $result->all;
660
is($rows->[0]->{$key1}, 1);
661
is($rows->[1]->{$key1}, 3);
662
like($rows->[0]->{$key2}, qr/\d{2}:/);
663
like($rows->[1]->{$key2}, qr/\d{2}:/);
664
like($rows->[0]->{$key3}, qr/\d{2}:/);
665
like($rows->[1]->{$key3}, qr/\d{2}:/);
666

            
667
eval { $dbi->execute("drop table $table1") };
668
$dbi->execute($create_table1);
669
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] ,
cleanup
Yuki Kimoto authored on 2012-01-20
670
table => $table1, filter => {$key1 => sub { $_[0] * 2 }});
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
671
$result = $dbi->execute("select * from $table1");
672
$rows   = $result->all;
673
is_deeply($rows, [{$key1 => 2, $key2 => 2}, {$key1 => 6, $key2 => 4}], "basic");
674

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
675
test 'update_or_insert';
676
eval { $dbi->execute("drop table $table1") };
677
$dbi->execute($create_table1);
678
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
679
  {$key2 => 2},
680
  table => $table1,
681
  primary_key => $key1,
682
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
683
);
684
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
685
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
686

            
687
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
688
  {$key2 => 3},
689
  table => $table1,
690
  primary_key => $key1,
691
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
692
);
693
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
694
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
695

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
696
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
697
  $dbi->update_or_insert(
698
    {$key2 => 3},
699
    table => $table1,
700
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
701
};
702

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
705
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
706
  $dbi->insert({$key1 => 1}, table => $table1);
707
  $dbi->update_or_insert(
708
    {$key2 => 3},
709
    table => $table1,
710
    primary_key => $key1,
711
    id => 1
712
  );
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
713
};
714
like($@, qr/one/);
715

            
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
716
eval { $dbi->execute("drop table $table1") };
717
$dbi->execute($create_table1);
718
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
719
  {},
720
  table => $table1,
721
  primary_key => $key1,
722
  id => 1
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
723
);
724
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
725
is($row->{$key1}, 1);
726

            
727
eval { 
cleanup
Yuki Kimoto authored on 2012-01-20
728
  $affected = $dbi->update_or_insert(
729
    {},
730
    table => $table1,
731
    primary_key => $key1,
732
    id => 1
733
  );
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
734
};
735
is($affected, 0);
736

            
micro optimization
Yuki Kimoto authored on 2011-10-31
737
test 'model update_or_insert';
738
eval { $dbi->execute("drop table $table1") };
739
$dbi->execute($create_table1);
740
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
741
  table => $table1,
742
  primary_key => $key1
micro optimization
Yuki Kimoto authored on 2011-10-31
743
);
744
$model->update_or_insert({$key2 => 2}, id => 1);
745
$row = $model->select(id => 1)->one;
746
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
747

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
748
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
749
  $model->insert({$key1 => 1});
750
  $model->update_or_insert(
751
    {$key2 => 3},
752
    id => 1
753
  );
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
754
};
755
like($@, qr/one/);
756

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
757
test 'default_bind_filter';
758
$dbi->execute("delete from $table1");
759
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
760
  twice       => sub { $_[0] * 2 },
761
  three_times => sub { $_[0] * 3 }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
762
);
763
$dbi->default_bind_filter('twice');
cleanup
Yuki Kimoto authored on 2011-11-01
764
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
765
$result = $dbi->execute("select * from $table1");
766
$rows   = $result->all;
767
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
768
$dbi->default_bind_filter(undef);
769

            
test cleanup
Yuki Kimoto authored on 2011-08-10
770
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
771
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
772
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
773
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
774
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
775
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
776
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
777
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
778
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
779
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
780
  "basic");
added tests
Yuki Kimoto authored on 2011-11-01
781

            
782
eval { $dbi->execute("drop table $table1") };
783
$dbi->execute($create_table1_2);
784
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
785
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
786
$dbi->update(param => {$key2 => 11}, table => $table1, where => {$key1 => 1});
787
$result = $dbi->execute("select * from $table1 order by $key1");
788
$rows   = $result->all;
789
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
790
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
791
  "basic");
792
                
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
793
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
794
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
795
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
796
$dbi->update({$key2 => 12}, table => $table1, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
797
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
798
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
799
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
800
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
801
  "update key same as search key");
test cleanup
Yuki Kimoto authored on 2011-08-10
802

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
810
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
811
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
812
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
813
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
814
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
815
            filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
816
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
817
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
818
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
819
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
820
  "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
821

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
827
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
828
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
829
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
830
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
831
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
832
$where->param({$key1 => 1, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
833
$dbi->update({$key1 => 3}, table => $table1, where => $where);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
834
$result = $dbi->select(table => $table1);
835
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
836

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
837
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
838
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
839
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
840
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
841
  {$key1 => 3},
842
  table => $table1,
843
  where => [
844
    ['and', "$key1 = :$key1", "$key2 = :$key2"],
845
    {$key1 => 1, $key2 => 2}
846
  ]
test cleanup
Yuki Kimoto authored on 2011-08-10
847
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
848
$result = $dbi->select(table => $table1);
849
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
850

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
851
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
852
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
853
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
854
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
855
$where->clause(['and', "$key2 = :$key2"]);
856
$where->param({$key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
857
$dbi->update({$key1 => 3}, table => $table1, where => $where);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
858
$result = $dbi->select(table => $table1);
859
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
860

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
867
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
868
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
869
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
870
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
871
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
872
$dbi->insert({select => 1}, table => 'table');
873
$dbi->update({update => 2}, table => 'table', where => {select => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
874
$result = $dbi->execute("select * from ${q}table$p");
875
$rows   = $result->all;
876
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
877

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

            
881
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
882
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
883
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
884
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
885
$dbi->insert({select => 1}, table => 'table');
886
$dbi->update({update => 2}, table => 'table', where => {'table.select' => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
887
$result = $dbi->execute("select * from ${q}table$p");
888
$rows   = $result->all;
889
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
890

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
891
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
892
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
893
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
894
$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
895
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
896
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
897
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
898
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
899
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
900
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
901

            
updated pod
Yuki Kimoto authored on 2011-09-02
902
eval { $dbi->execute("drop table $table1") };
903
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
904
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
905
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
906
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
updated pod
Yuki Kimoto authored on 2011-09-02
907
wrap => {$key2 => sub { "$_[0] - 1" }});
908
$result = $dbi->execute("select * from $table1 order by $key1");
909
$rows   = $result->all;
910
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
911
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
912
  "basic");
updated pod
Yuki Kimoto authored on 2011-09-02
913

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
914
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
915
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
916
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
917
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
918
$dbi->update({$key2 => \"'11'"}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
919
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
920
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
921
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
922
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
923
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
924

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
925
eval { $dbi->execute("drop table $table1") };
926
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
927
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
928
  $key1 => '5'
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
929
);
test cleanup
Yuki Kimoto authored on 2011-11-01
930
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
931
$dbi->update(table => $table1, timestamp => 1, where => {$key2 => 2});
932
$result = $dbi->execute("select * from $table1");
933
$rows   = $result->all;
934
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
935

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
936
eval { $dbi->execute("drop table $table1") };
937
$dbi->execute($create_table1);
938
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
939
  [$key1, $key2] => sub { '5' }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
940
);
test cleanup
Yuki Kimoto authored on 2011-11-01
941
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
942
$dbi->update_all(table => $table1, timestamp => 1);
943
$result = $dbi->execute("select * from $table1");
944
$rows   = $result->all;
945
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
946

            
947
eval { $dbi->execute("drop table $table1") };
948
$dbi->execute($create_table1);
949
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
950
  [$key1, $key2] => sub { "" . DBIx::Custom->new }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
951
);
test cleanup
Yuki Kimoto authored on 2011-11-01
952
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
953
$dbi->update_all(table => $table1, timestamp => 1);
954
$result = $dbi->execute("select * from $table1");
955
$rows   = $result->all;
956
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
957

            
micro optimization and
Yuki Kimoto authored on 2011-10-25
958
eval { $dbi->execute("drop table $table1") };
959
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
960
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
961
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
962
$param = {$key2 => 11};
963
$dbi->update($param, table => $table1, where => {$key1 => 1});
964
is_deeply($param, {$key2 => 11});
965
$result = $dbi->execute("select * from $table1 order by $key1");
966
$rows   = $result->all;
967
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
968
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
969
  "basic");
micro optimization and
Yuki Kimoto authored on 2011-10-25
970

            
971
eval { $dbi->execute("drop table $table1") };
972
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
973
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
974
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
975
$param = {$key2 => 11};
976
$dbi->update($param, table => $table1, where => {$key2 => 2});
977
is_deeply($param, {$key2 => 11});
978
$result = $dbi->execute("select * from $table1 order by $key1");
979
$rows   = $result->all;
980
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
981
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
982
  "basic");
micro optimization and
Yuki Kimoto authored on 2011-10-25
983

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
984
eval { $dbi->execute("drop table $table1") };
985
$dbi->execute($create_table1_2);
986
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
987
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
988
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key1 => 1});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
989
$result = $dbi->select(table => $table1);
990
is_deeply($param, {$key3 => 4});
991
$row   = $result->one;
992
is($row->{$key3}, 4);
993
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
994

            
995
eval { $dbi->execute("drop table $table1") };
996
$dbi->execute($create_table1_2);
997
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
998
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
999
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key3 => 3});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1000
$result = $dbi->select(table => $table1);
1001
is_deeply($param, {$key3 => 4});
1002
$row   = $result->one;
1003
is($row->{$key3}, 4);
1004
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1005

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
1006
eval { $dbi->execute("drop table $table1") };
1007
$dbi->execute($create_table1_2);
1008
$model = $dbi->create_model(table => $table1, updated_at => $key2);
1009
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1010
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
1011
$model->update($param, where => {$key1 => 1});
1012
$result = $dbi->select(table => $table1);
1013
is_deeply($param, {$key3 => 4});
1014
$row   = $result->one;
1015
is($row->{$key3}, 4);
1016
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1017

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1018
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1019
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1020
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1021
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1022
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1023
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
1024
$dbi->update_all({$key2 => 10}, table => $table1, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1025
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1026
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1027
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1028
  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
1029
  "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1030

            
1031
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1032
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1033
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1034
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1035
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1036
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1037
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1038
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1039
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1040

            
cleanup test
Yuki Kimoto authored on 2011-08-15
1041
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
1042
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1043
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1044
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1045
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1046
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1047
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1048
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1049

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1052
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1053
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1054
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1055
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
1056
$rows = $dbi->select(table => $table1)->all;
1057
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1058

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1059
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1060
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1061
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1062
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1063
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1064
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1065
$where->param({ke1 => 1, $key2 => 2});
1066
$dbi->delete(table => $table1, where => $where);
1067
$result = $dbi->select(table => $table1);
1068
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1069

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1070
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1071
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1072
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1073
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1074
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
1075
  table => $table1,
1076
  where => [
1077
    ['and', "$key1 = :$key1", "$key2 = :$key2"],
1078
    {ke1 => 1, $key2 => 2}
1079
  ]
test cleanup
Yuki Kimoto authored on 2011-08-10
1080
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1081
$result = $dbi->select(table => $table1);
1082
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1083

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1084
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1085
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1086
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1087
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
1088
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1089
$rows   = $result->all;
1090
is_deeply($rows, [], "basic");
1091

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1101
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
1102
$dbi = DBIx::Custom->connect;
1103
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1104
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1105
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1106
$dbi->insert({select => 1}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1107
$dbi->delete(table => 'table', where => {select => 1});
1108
$result = $dbi->execute("select * from ${q}table$p");
1109
$rows   = $result->all;
1110
is_deeply($rows, [], "reserved word");
1111

            
1112
test 'delete_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1113
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1114
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1115
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1116
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1117
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1118
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1119
$rows   = $result->all;
1120
is_deeply($rows, [], "basic");
1121

            
1122
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1123
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1124
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1125
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1126
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1127
$rows = $dbi->select(table => $table1)->all;
1128
is_deeply($rows, [{$key1 => 1, $key2 => 2},
cleanup
Yuki Kimoto authored on 2012-01-20
1129
  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
1130

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

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

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

            
1140
$dbi->register_filter(decrement => sub { $_[0] - 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1141
$rows = $dbi->select(table => $table1, where => {$key1 => 2}, filter => {$key1 => 'decrement'})
cleanup
Yuki Kimoto authored on 2012-01-20
1142
          ->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1143
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1144

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1145
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1146
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
1147
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1148
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1149
  table => [$table1, $table2],
1150
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
1151
  where   => {"$table1.$key2" => 2},
1152
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1153
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1154
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
1155

            
1156
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1157
  table => [$table1, $table2],
1158
  column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
1159
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1160
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1161
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
1162

            
1163
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
1164
eval { $dbi->execute("drop table ${q}table$p") };
1165
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1166
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1167
$dbi->insert({select => 1, update => 2}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1168
$result = $dbi->select(table => 'table', where => {select => 1});
1169
$rows   = $result->all;
1170
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
1171

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
1172
eval { $dbi->execute("drop table $table1") };
1173
$dbi->execute($create_table1);
1174
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1175
$row = $dbi->select($key1, table => $table1)->one;
1176
is_deeply($row, {$key1 => 1});
1177

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1178
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1179
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1180
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1181
  twice       => sub { $_[0] * 2 },
1182
  three_times => sub { $_[0] * 3 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1183
);
1184
$dbi->default_fetch_filter('twice');
1185
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1186
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1187
$result = $dbi->select(table => $table1);
1188
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1189
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1190
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1191

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1192
$dbi->default_fetch_filter('twice');
1193
eval { $dbi->execute("drop table $table1") };
1194
$dbi->execute($create_table1);
1195
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1196
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1197
$result->filter({$key1 => 'three_times'});
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1198
$row = $result->fetch_one;
1199
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter");
1200

            
1201
test 'fetch_first DEPRECATED!';
1202
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1203
$result->filter({$key1 => 'three_times'});
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1204
$row = $result->fetch_first;
1205
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter");
1206

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1207
test 'filters';
1208
$dbi = DBIx::Custom->new;
1209

            
1210
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
cleanup
Yuki Kimoto authored on 2012-01-20
1211
  'あ', "decode_utf8");
test cleanup
Yuki Kimoto authored on 2011-08-10
1212

            
1213
is($dbi->filters->{encode_utf8}->('あ'),
cleanup
Yuki Kimoto authored on 2012-01-20
1214
  encode_utf8('あ'), "encode_utf8");
test cleanup
Yuki Kimoto authored on 2011-08-10
1215

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1216
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1217
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1218
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1219
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1220
$dbi->begin_work;
1221
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1222
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1223
$dbi->rollback;
1224
$dbi->dbh->{AutoCommit} = 1;
1225

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1226
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1227
ok(! $result->fetch_one, "rollback");
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1228

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

            
1230
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1231
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1232
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1233
$dbi->begin_work;
1234
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1235
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1236
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1237
$dbi->commit;
1238
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1239
$result = $dbi->select(table => $table1);
1240
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
cleanup
Yuki Kimoto authored on 2012-01-20
1241
  "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1242

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

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

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

            
1274

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1275
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1276
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1277
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1278
$dbi->execute($create_table1);
1279

            
1280
$dbi->begin_work;
1281

            
1282
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1283
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1284
  die "Error";
1285
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1286
};
1287

            
1288
$dbi->rollback if $@;
1289

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

            
1294
$dbi->begin_work;
1295

            
1296
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1297
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1298
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1299
};
1300

            
1301
$dbi->commit unless $@;
1302

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

            
1307
$dbi->dbh->{AutoCommit} = 0;
1308
eval{ $dbi->begin_work };
1309
ok($@, "exception");
1310
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1311

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1312
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1313
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1314
$dbi->cache(1);
1315
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1316
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1317
$dbi->execute($source, {}, query => 1);
1318
is_deeply($dbi->{_cached}->{$source}, 
cleanup
Yuki Kimoto authored on 2012-01-20
1319
  {sql => " select * from $table1 where $key1 = ?  and $key2 = ? ", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1320

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1321
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1322
$dbi->execute($create_table1);
1323
$dbi->{_cached} = {};
1324
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1325
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1326
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1327

            
1328
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1329
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1330
$dbi->execute($create_table1);
1331
{
cleanup
Yuki Kimoto authored on 2012-01-20
1332
  local $Carp::Verbose = 0;
1333
  eval{$dbi->execute("select * frm $table1")};
1334
  like($@, qr/\Qselect * frm $table1/, "fail prepare");
1335
  like($@, qr/\.t /, "fail : not verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1336
}
1337
{
cleanup
Yuki Kimoto authored on 2012-01-20
1338
  local $Carp::Verbose = 1;
1339
  eval{$dbi->execute("select * frm $table1")};
1340
  like($@, qr/Custom.*\.t /s, "fail : verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1341
}
1342

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

            
1348
{
cleanup
Yuki Kimoto authored on 2012-01-20
1349
  local $Carp::Verbose = 0;
1350
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1351
  like($@, qr/\Q.t /, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1352
}
1353
{
cleanup
Yuki Kimoto authored on 2012-01-20
1354
  local $Carp::Verbose = 1;
1355
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1356
  like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1357
}
1358

            
1359
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1360
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1361
  one => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1362
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1363
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1364
  two => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1365
);
1366
$dbi->method({
cleanup
Yuki Kimoto authored on 2012-01-20
1367
  twice => sub {
1368
    my $self = shift;
1369
    return $_[0] * 2;
1370
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
1371
});
1372

            
1373
is($dbi->one, 1, "first");
1374
is($dbi->two, 2, "second");
1375
is($dbi->twice(5), 10 , "second");
1376

            
1377
eval {$dbi->XXXXXX};
1378
ok($@, "not exists");
1379

            
1380
test 'out filter';
1381
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1382
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1383
$dbi->execute($create_table1);
1384
$dbi->register_filter(twice => sub { $_[0] * 2 });
1385
$dbi->register_filter(three_times => sub { $_[0] * 3});
1386
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1387
  $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1388
            $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
1389
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1390
$result = $dbi->execute("select * from $table1");
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1391
$row   = $result->fetch_hash_one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1392
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1393
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1394
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1395
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1396

            
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1397
test 'fetch_hash_first DEPRECATED!';
1398
$result = $dbi->execute("select * from $table1");
1399
$row   = $result->fetch_hash_first;
1400
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1401

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1402
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1403
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1404
$dbi->execute($create_table1);
1405
$dbi->register_filter(twice => sub { $_[0] * 2 });
1406
$dbi->register_filter(three_times => sub { $_[0] * 3});
1407
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1408
  $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1409
            $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1410
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1411
  $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1412
); 
test cleanup
Yuki Kimoto authored on 2011-11-01
1413
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1414
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1415
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1416
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1417

            
1418
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1419
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1420
$dbi->execute($create_table1);
1421
$dbi->register_filter(twice => sub { $_[0] * 2 });
1422
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1423
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1424
);
cleanup
Yuki Kimoto authored on 2011-11-01
1425
$dbi->insert({$key1 => 1, $key2 => 2},table => $table1, filter => {$key1 => undef});
1426
$dbi->update({$key1 => 2}, table => $table1, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1427
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1428
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1429
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
test cleanup
Yuki Kimoto authored on 2011-08-10
1430

            
1431
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1432
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1433
$dbi->execute($create_table1);
1434
$dbi->register_filter(twice => sub { $_[0] * 2 });
1435
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1436
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1437
);
cleanup
Yuki Kimoto authored on 2011-11-01
1438
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1=> undef});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1439
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1440
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1441
$rows   = $result->all;
1442
is_deeply($rows, [], "delete");
1443

            
1444
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1445
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1446
$dbi->execute($create_table1);
1447
$dbi->register_filter(twice => sub { $_[0] * 2 });
1448
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1449
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1450
);
cleanup
Yuki Kimoto authored on 2011-11-01
1451
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1452
$result = $dbi->select(table => $table1, where => {$key1 => 1});
1453
$result->filter({$key2 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1454
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1455
is_deeply($rows, [{$key1 => 4, $key2 => 4}], "select");
test cleanup
Yuki Kimoto authored on 2011-08-10
1456

            
1457
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1458
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1459
$dbi->execute($create_table1);
1460
$dbi->register_filter(twice => sub { $_[0] * 2 });
1461
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1462
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1463
);
cleanup
Yuki Kimoto authored on 2011-11-01
1464
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1465
$result = $dbi->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2",
cleanup
Yuki Kimoto authored on 2012-01-20
1466
  {$key1 => 1, $key2 => 2},
1467
  table => [$table1]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1468
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1469
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute");
test cleanup
Yuki Kimoto authored on 2011-08-10
1470

            
1471
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1472
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1473
$dbi->execute($create_table1);
1474
$dbi->register_filter(twice => sub { $_[0] * 2 });
1475
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1476
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1477
);
cleanup
Yuki Kimoto authored on 2011-11-01
1478
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1479
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
cleanup
Yuki Kimoto authored on 2012-01-20
1480
  {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1481
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1482
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1483

            
1484
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1485
eval { $dbi->execute("drop table $table1") };
1486
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1487
$dbi->execute($create_table1);
1488
$dbi->execute($create_table2);
1489
$dbi->register_filter(twice => sub { $_[0] * 2 });
1490
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1491
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1492
  $table1, $key2 => {out => 'twice', in => 'twice'}
cleanup test
Yuki Kimoto authored on 2011-08-15
1493
);
1494
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1495
  $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1496
);
cleanup
Yuki Kimoto authored on 2011-11-01
1497
$dbi->insert({$key1 => 5, $key2 => 2}, table => $table1, filter => {$key2 => undef});
1498
$dbi->insert({$key1 => 5, $key3 => 6}, table => $table2, filter => {$key3 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1499
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1500
  table => [$table1, $table2],
1501
  column => [$key2, $key3],
1502
  where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
cleanup test
Yuki Kimoto authored on 2011-08-15
1503

            
1504
$result->filter({$key2 => 'twice'});
1505
$rows   = $result->all;
1506
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1507

            
1508
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1509
  table => [$table1, $table2],
1510
  column => [$key2, $key3],
1511
  where => {$key2 => 1, $key3 => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
cleanup test
Yuki Kimoto authored on 2011-08-15
1512

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1524
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1525
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1526
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1527
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1528
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1529
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1530

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

            
1537
test 'end_filter';
1538
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1539
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1540
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1541
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1542
$result = $dbi->select(table => $table1);
1543
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1544
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1545
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1546
is_deeply($row, [6, 40]);
1547

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1548
$dbi = DBIx::Custom->connect;
1549
eval { $dbi->execute("drop table $table1") };
1550
$dbi->execute($create_table1);
1551
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1552
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1553
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1554
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1555
$row = $result->fetch_one;
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1556
is_deeply($row, [6, 6, 40]);
1557

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1558
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1559
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1560
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1561
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1562
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1563
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1564
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1565
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1566
is_deeply($row, [6, 12]);
1567

            
1568
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1569
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1570
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1571
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1572
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1573
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1574
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1575
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1576
is_deeply($row, [6, 12]);
1577

            
1578
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1579
$result = $dbi->select(table => $table1);
1580
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1581
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1582
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1583
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1584

            
1585
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1586
$dbi->apply_filter($table1,
cleanup
Yuki Kimoto authored on 2012-01-20
1587
  $key1 => {end => sub { $_[0] * 3 } },
1588
  $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1589
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1590
$result = $dbi->select(table => $table1);
1591
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1592
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1593
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1594

            
1595
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1596
$dbi->apply_filter($table1,
cleanup
Yuki Kimoto authored on 2012-01-20
1597
  $key1 => {end => sub { $_[0] * 3 } },
1598
  $key2 => {end => 'five_times'}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1599
);
1600
$result = $dbi->select(table => $table1);
1601
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1602
$result->filter($key1 => undef);
1603
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1604
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1605
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1606

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1607
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1608
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1609
$result->filter($key1 => undef);
1610
$result->end_filter($key1 => undef);
1611
$row = $result->fetch;
1612
is_deeply($row, [1, 1, 40], 'apply_filter overwrite');
1613

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1614
test 'remove_end_filter and remove_filter';
1615
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1616
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1617
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1618
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1619
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1620
$row = $result
cleanup
Yuki Kimoto authored on 2012-01-20
1621
  ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
1622
  ->remove_filter
1623
  ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
1624
  ->remove_end_filter
1625
  ->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1626
is_deeply($row, [1, 2]);
1627

            
1628
test 'empty where select';
1629
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1630
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1631
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1632
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1633
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1634
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1635
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1636

            
1637
test 'select query option';
1638
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1639
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1640
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1641
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1642
ok(ref $query);
cleanup
Yuki Kimoto authored on 2011-11-01
1643
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1644
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1645
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1646
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1647
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1648
ok(ref $query);
test cleanup
Yuki Kimoto authored on 2011-08-10
1649

            
1650
test 'where';
1651
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1652
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1653
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1654
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1655
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1656
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1657
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1658

            
1659
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1660
  ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1661
  ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1662

            
1663
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1664
  table => $table1,
1665
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1666
);
1667
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1668
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1669

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

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

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

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

            
1710
$where = $dbi->where;
1711
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1712
  table => $table1,
1713
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1714
);
1715
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1716
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1717

            
1718
eval {
1719
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1720
           ->clause(['uuu']);
test cleanup
Yuki Kimoto authored on 2011-08-10
1721
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1722
  table => $table1,
1723
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1724
);
1725
};
1726
ok($@);
1727

            
1728
$where = $dbi->where;
1729
is("$where", '');
1730

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

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

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

            
1761
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1762
  ->clause("$key1 = :$key1")
1763
  ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1764
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1765
  table => $table1,
1766
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1767
);
1768
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1769
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1770

            
1771
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1772
  ->clause(['or', ("$key1 = :$key1") x 3])
1773
  ->param({$key1 => [$dbi->not_exists, 1, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1774
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1775
  table => $table1,
1776
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1777
);
1778
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1779
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1780

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

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

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

            
1811
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1812
  ->clause(['or', ("$key1 = :$key1") x 3])
1813
  ->param({$key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1814
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1815
  table => $table1,
1816
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1817
);
1818
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1819
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1820

            
1821
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1822
  ->clause(['or', ("$key1 = :$key1") x 3])
1823
  ->param({$key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1824
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1825
  table => $table1,
1826
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1827
);
1828
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1829
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1830

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

            
1841
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1842
  ->clause(['or', ("$key1 = :$key1") x 3])
1843
  ->param({$key1 => []});
test cleanup
Yuki Kimoto authored on 2011-08-10
1844
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1845
  table => $table1,
1846
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1847
);
1848
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1849
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1850

            
1851
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1852
  ->clause(['and', "{> $key1}", "{< $key1}" ])
1853
  ->param({$key1 => [2, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1854
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1855
  table => $table1,
1856
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1857
);
1858
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1859
is_deeply($row, [{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1860

            
1861
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1862
  ->clause(['and', "{> $key1}", "{< $key1}" ])
1863
  ->param({$key1 => [$dbi->not_exists, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1864
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1865
  table => $table1,
1866
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1867
);
1868
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1869
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1870

            
1871
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1872
  ->clause(['and', "{> $key1}", "{< $key1}" ])
1873
  ->param({$key1 => [$dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1874
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1875
  table => $table1,
1876
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1877
);
1878
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1879
is_deeply($row, [{$key1 => 1, $key2 => 2},{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1880

            
1881
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1882
  ->clause(['and', "{> $key1}", "{< $key1}" ])
1883
  ->param({$key1 => [0, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1884
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1885
  table => $table1,
1886
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1887
);
1888
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1889
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1890

            
1891
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1892
  ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1893
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1894
  table => $table1,
1895
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1896
);
1897
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1898
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1899

            
1900
eval {$dbi->where(ppp => 1) };
1901
like($@, qr/invalid/);
1902

            
1903
$where = $dbi->where(
cleanup
Yuki Kimoto authored on 2012-01-20
1904
  clause => ['and', ['or'], ['and', "$key1 = :$key1", "$key2 = :$key2"]],
1905
  param => {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
1906
);
1907
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1908
  table => $table1,
1909
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1910
);
1911
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1912
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1913

            
1914

            
1915
$where = $dbi->where(
cleanup
Yuki Kimoto authored on 2012-01-20
1916
  clause => ['and', ['or'], ['or', ":$key1", ":$key2"]],
1917
  param => {}
test cleanup
Yuki Kimoto authored on 2011-08-10
1918
);
1919
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1920
  table => $table1,
1921
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1922
);
1923
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1924
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1925

            
1926
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1927
$where->clause(['and', ":${key1}{=}"]);
1928
$where->param({$key1 => undef});
1929
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1930
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1931
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1932

            
1933
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1934
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1935
$where->param({$key1 => [undef, undef]});
1936
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1937
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1938
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1939
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1940
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1941
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1942

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

            
1944
$dbi = DBIx::Custom->connect;
1945
eval { $dbi->execute("drop table $table1") };
1946
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1947
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
1948
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1949
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1950
  ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
1951
  ->param({$key1 => 1});
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1952

            
1953
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1954
  table => $table1,
1955
  where => $where
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1956
);
1957
$row = $result->all;
1958
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
1959

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1960
test 'register_tag_processor';
1961
$dbi = DBIx::Custom->connect;
1962
$dbi->register_tag_processor(
cleanup
Yuki Kimoto authored on 2012-01-20
1963
  a => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1964
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1965
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1966

            
1967
test 'register_tag';
1968
$dbi = DBIx::Custom->connect;
1969
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
1970
  b => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1971
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1972
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1973

            
1974
test 'table not specify exception';
1975
$dbi = DBIx::Custom->connect;
1976
eval {$dbi->select};
1977
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1978

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1979
test 'more tests';
1980
$dbi = DBIx::Custom->connect;
1981
eval{$dbi->apply_filter('table', 'column', [])};
1982
like($@, qr/apply_filter/);
1983

            
1984
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1985
like($@, qr/apply_filter/);
1986

            
1987
$dbi->apply_filter(
1988

            
1989
);
1990
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1991
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1992
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1993
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1994
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1995
$dbi->apply_filter($table1, $key2, 
cleanup
Yuki Kimoto authored on 2012-01-20
1996
                 {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1997
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
1998
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1999

            
2000
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2001
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2002
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2003
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2004
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2005
$dbi->apply_filter($table1, $key2, {});
2006
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
2007
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2008

            
2009
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2010
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2011
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2012
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2013
like($@, qr/not registered/);
2014
$dbi->method({one => sub { 1 }});
2015
is($dbi->one, 1);
2016

            
2017
eval{DBIx::Custom->connect(dsn => undef)};
2018
like($@, qr/_connect/);
2019

            
2020
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2021
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2022
$dbi->execute($create_table1);
2023
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
2024
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
2025
           filter => {$key1 => 'twice'});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2026
$row = $dbi->select(table => $table1)->one;
2027
is_deeply($row, {$key1 => 2, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
2028
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
2029
           filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
2030
like($@, qr//);
2031

            
2032
$dbi->register_filter(one => sub { });
2033
$dbi->default_fetch_filter('one');
2034
ok($dbi->default_fetch_filter);
2035
$dbi->default_bind_filter('one');
2036
ok($dbi->default_bind_filter);
2037
eval{$dbi->default_fetch_filter('no')};
2038
like($@, qr/not registered/);
2039
eval{$dbi->default_bind_filter('no')};
2040
like($@, qr/not registered/);
2041
$dbi->default_bind_filter(undef);
2042
ok(!defined $dbi->default_bind_filter);
2043
$dbi->default_fetch_filter(undef);
2044
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2045
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2046
like($@, qr/Tag not finished/);
2047

            
2048
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2049
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2050
$dbi->execute($create_table1);
2051
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2052
$result = $dbi->select(table => $table1);
2053
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2054
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2055
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2056
like($@, qr/not registered/);
2057
$result->default_filter(undef);
2058
ok(!defined $result->default_filter);
2059
$result->default_filter('one');
2060
is($result->default_filter->(), 1);
2061

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2062
test 'option';
2063
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
2064
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
2065
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2066
ok($dbi->dbh->{PrintError});
2067
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2068
ok($dbi->dbh->{PrintError});
2069

            
2070
test 'DBIx::Custom::Result stash()';
2071
$result = DBIx::Custom::Result->new;
2072
is_deeply($result->stash, {}, 'default');
2073
$result->stash->{foo} = 1;
2074
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2075

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

            
cleanup
Yuki Kimoto authored on 2011-11-01
2088
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2089
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2090
  table => $table1,
2091
  primary_key => $key1,
2092
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2093
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2094
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2095

            
2096
test 'insert_at';
2097
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2098
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2099
$dbi->execute($create_table1_2);
2100
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2101
  {$key3 => 3},
2102
  primary_key => [$key1, $key2], 
2103
  table => $table1,
2104
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2105
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2106
is($dbi->select(table => $table1)->one->{$key1}, 1);
2107
is($dbi->select(table => $table1)->one->{$key2}, 2);
2108
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2109

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2110
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2111
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2112
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2113
  {$key2 => 2, $key3 => 3},
2114
  primary_key => $key1, 
2115
  table => $table1,
2116
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2117
);
2118

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2151
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2152
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2153
$dbi->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2154
  {$key3 => 4},
2155
  table => $table1,
2156
  primary_key => $key1,
2157
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2158
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2159
is($dbi->select(table => $table1)->one->{$key1}, 1);
2160
is($dbi->select(table => $table1)->one->{$key2}, 2);
2161
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2162

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2192
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2193
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2194
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2195
  table => $table1,
2196
  primary_key => $key1,
2197
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2198
);
2199
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2200
is($row->{$key1}, 1);
2201
is($row->{$key2}, 2);
2202
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2203

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2204
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2205
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2206
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2207
  table => $table1,
2208
  primary_key => [$key1, $key2],
2209
  where => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2210
);
2211
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2212
is($row->{$key1}, 1);
2213
is($row->{$key2}, 2);
2214
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2215

            
2216
test 'model delete_at';
2217
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2218
eval { $dbi->execute("drop table $table1") };
2219
eval { $dbi->execute("drop table $table2") };
2220
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2221
$dbi->execute($create_table1_2);
2222
$dbi->execute($create_table2_2);
2223
$dbi->execute($create_table3);
test cleanup
Yuki Kimoto authored on 2011-11-01
2224
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2225
$dbi->model($table1)->delete_at(where => [1, 2]);
2226
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2227
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2228
$dbi->model($table1)->delete_at(where => [1, 2]);
2229
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2230
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2231
$dbi->model($table3)->delete_at(where => [1, 2]);
2232
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2233

            
2234
test 'model insert_at';
2235
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2236
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2237
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2238
$dbi->model($table1)->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2239
  {$key3 => 3},
2240
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2241
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2242
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2243
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2244
is($row->{$key1}, 1);
2245
is($row->{$key2}, 2);
2246
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2247

            
2248
test 'model update_at';
2249
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2250
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2251
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2252
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2253
$dbi->model($table1)->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2254
  {$key3 => 4},
2255
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2256
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2257
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2258
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2259
is($row->{$key1}, 1);
2260
is($row->{$key2}, 2);
2261
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2262

            
2263
test 'model select_at';
2264
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2265
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2266
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2267
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2268
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2269
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2270
is($row->{$key1}, 1);
2271
is($row->{$key2}, 2);
2272
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2273

            
2274

            
2275
test 'mycolumn and column';
2276
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2277
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2278
eval { $dbi->execute("drop table $table1") };
2279
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2280
$dbi->execute($create_table1);
2281
$dbi->execute($create_table2);
2282
$dbi->separator('__');
2283
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2284
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2285
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2286
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2287
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2288
  column => [$model->mycolumn, $model->column($table2)],
2289
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2290
);
2291
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2292
        {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2293

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2294
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2295
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2296
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2297
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2298
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2299
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2300
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2301
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2302
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2303
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2304
is($dbi->select(table => $table1)->one->{$key1}, 1);
2305
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2306

            
2307
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2308
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2309
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2310
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2311
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2312
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2313
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2314
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2315
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2316
is($dbi->select(table => $table1)->one->{$key1}, 1);
2317
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2318

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2319
test 'mycolumn';
2320
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2321
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2322
eval { $dbi->execute("drop table $table1") };
2323
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2324
$dbi->execute($create_table1);
2325
$dbi->execute($create_table2);
2326
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2327
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2328
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2329
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2330
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2331
  column => [
2332
    $model->mycolumn,
2333
    $model->column($table2)
2334
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2335
);
2336
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2337
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2338

            
2339
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2340
  column => [
2341
    $model->mycolumn([$key1]),
2342
    $model->column($table2 => [$key1])
2343
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2344
);
2345
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2346
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2347
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2348
  column => [
2349
    $model->mycolumn([$key1]),
2350
    {$table2 => [$key1]}
2351
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2352
);
2353
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2354
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2355

            
2356
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2357
  column => [
2358
    $model->mycolumn([$key1]),
2359
    ["$table2.$key1", as => "$table2.$key1"]
2360
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2361
);
2362
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2363
  {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2364

            
2365
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2366
  column => [
2367
    $model->mycolumn([$key1]),
2368
    ["$table2.$key1" => "$table2.$key1"]
2369
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2370
);
2371
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2372
  {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2373

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2374
test 'merge_param';
2375
$dbi = DBIx::Custom->new;
2376
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2377
  {$key1 => 1, $key2 => 2, $key3 => 3},
2378
  {$key1 => 1, $key2 => 2},
2379
  {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2380
];
2381
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2382
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2383

            
2384
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2385
  {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2386
  {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2387
];
2388
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2389
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
2390

            
2391
test 'select() param option';
2392
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2393
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2394
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2395
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2396
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2397
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2398
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2399
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
2400
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
2401
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2402
  table => $table1,
2403
  column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2404
  where   => {"$table1.$key2" => 3},
2405
  join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
2406
            " $table2 on $table1.$key1 = $table2.$key1"],
2407
  param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2408
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2409
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2410

            
cleanup
Yuki Kimoto authored on 2011-10-21
2411
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2412
  table => $table1,
2413
  column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2414
  where   => {"$table1.$key2" => 3},
2415
  join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2416
           " $table2 on $table1.$key1 = $table2.$key1",
2417
  param => {"$table2.$key3" => 5}
cleanup
Yuki Kimoto authored on 2011-10-21
2418
)->all;
2419
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2420

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
2448
$dbi = DBIx::Custom->connect;
2449
eval { $dbi->execute("drop table $table1") };
2450
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2451
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2452
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
2453
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2454
  table => $table1,
2455
  where => [
2456
    "$key1 = :$key1 and $key2 = :$key2",
2457
    {$key1 => 1, $key2 => 2}
2458
  ]
cleanup
Yuki Kimoto authored on 2011-10-21
2459
)->all;
2460
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2461

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2462
test 'delete() string where';
2463
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2464
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2465
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2466
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2467
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2468
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2469
  table => $table1,
2470
  where => "$key1 = :$key1 and $key2 = :$key2",
2471
  where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2472
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2473
$rows = $dbi->select(table => $table1)->all;
2474
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2475

            
2476
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2477
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2478
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2479
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2480
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2481
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2482
  table => $table1,
2483
  where => [
2484
    "$key1 = :$key1 and $key2 = :$key2",
2485
     {$key1 => 1, $key2 => 2}
2486
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2487
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2488
$rows = $dbi->select(table => $table1)->all;
2489
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2490

            
2491

            
2492
test 'update() string where';
2493
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2494
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2495
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2496
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2497
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2498
  {$key1 => 5},
2499
  table => $table1,
2500
  where => "$key1 = :$key1 and $key2 = :$key2",
2501
  where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2502
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2503
$rows = $dbi->select(table => $table1)->all;
2504
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2505

            
2506
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2507
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2508
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2509
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2510
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2511
  {$key1 => 5},
2512
  table => $table1,
2513
  where => [
2514
    "$key1 = :$key1 and $key2 = :$key2",
2515
    {$key1 => 1, $key2 => 2}
2516
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2517
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2518
$rows = $dbi->select(table => $table1)->all;
2519
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2520

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2535
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2536
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2537
  {$key2 => 2, $key3 => 3},
2538
  primary_key => $key1, 
2539
  table => $table1,
2540
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2541
);
2542

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2547
$dbi = DBIx::Custom->connect;
2548
eval { $dbi->execute("drop table $table1") };
2549
$dbi->execute($create_table1_2);
2550
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2551
  {$key3 => 3},
2552
  primary_key => [$key1, $key2], 
2553
  table => $table1,
2554
  id => 1,
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2555
);
2556
is($dbi->select(table => $table1)->one->{$key1}, 1);
2557
ok(!$dbi->select(table => $table1)->one->{$key2});
2558
is($dbi->select(table => $table1)->one->{$key3}, 3);
2559

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2560
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2561
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2562
$dbi->execute($create_table1_2);
2563
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2564
  {$key3 => 3},
2565
  primary_key => [$key1, $key2], 
2566
  table => $table1,
2567
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2568
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2569
is($dbi->select(table => $table1)->one->{$key1}, 1);
2570
is($dbi->select(table => $table1)->one->{$key2}, 2);
2571
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2572

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2573
$dbi = DBIx::Custom->connect;
2574
eval { $dbi->execute("drop table $table1") };
2575
$dbi->execute($create_table1_2);
2576
$param = {$key3 => 3, $key2 => 4};
2577
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2578
  $param,
2579
  primary_key => [$key1, $key2], 
2580
  table => $table1,
2581
  id => [1, 2],
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2582
);
2583
is($dbi->select(table => $table1)->one->{$key1}, 1);
2584
is($dbi->select(table => $table1)->one->{$key2}, 4);
2585
is($dbi->select(table => $table1)->one->{$key3}, 3);
2586
is_deeply($param, {$key3 => 3, $key2 => 4});
2587

            
added test
Yuki Kimoto authored on 2011-10-25
2588
$dbi = DBIx::Custom->connect;
2589
eval { $dbi->execute("drop table $table1") };
2590
$dbi->execute($create_table1_2);
2591
$param = {$key3 => 3, $key2 => 4};
2592
$query = $dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2593
  $param,
2594
  primary_key => [$key1, $key2], 
2595
  table => $table1,
2596
  id => [1, 2],
2597
  query => 1
added test
Yuki Kimoto authored on 2011-10-25
2598
);
micro optimization
Yuki Kimoto authored on 2011-11-16
2599
ok(ref $query);
added test
Yuki Kimoto authored on 2011-10-25
2600
is_deeply($param, {$key3 => 3, $key2 => 4});
2601

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2602
test 'model insert id and primary_key option';
2603
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2604
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2605
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2606
$dbi->model($table1)->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2607
  {$key3 => 3},
2608
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2609
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2610
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2611
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2612
is($row->{$key1}, 1);
2613
is($row->{$key2}, 2);
2614
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2615

            
2616
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2617
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2618
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2619
$dbi->model($table1)->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2620
  {$key3 => 3},
2621
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2622
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2623
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2624
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2625
is($row->{$key1}, 1);
2626
is($row->{$key2}, 2);
2627
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2628

            
2629
test 'update and id option';
2630
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2631
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2632
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2633
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2634
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2635
  {$key3 => 4},
2636
  table => $table1,
2637
  primary_key => [$key1, $key2],
2638
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2639
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2640
is($dbi->select(table => $table1)->one->{$key1}, 1);
2641
is($dbi->select(table => $table1)->one->{$key2}, 2);
2642
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2643

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

            
2656
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2657
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2658
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2659
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2660
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2661
  {$key3 => 4},
2662
  table => $table1,
2663
  primary_key => [$key1, $key2],
2664
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2665
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2666
is($dbi->select(table => $table1)->one->{$key1}, 1);
2667
is($dbi->select(table => $table1)->one->{$key2}, 2);
2668
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2669

            
2670

            
2671
test 'model update and id option';
2672
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2673
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2674
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2675
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2676
$dbi->model($table1)->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2677
  {$key3 => 4},
2678
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2679
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2680
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2681
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2682
is($row->{$key1}, 1);
2683
is($row->{$key2}, 2);
2684
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2685

            
2686

            
2687
test 'delete and id option';
2688
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2689
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2690
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2691
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2692
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2693
  table => $table1,
2694
  primary_key => [$key1, $key2],
2695
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2696
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2697
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2698

            
cleanup
Yuki Kimoto authored on 2011-11-01
2699
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2700
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2701
  table => $table1,
2702
  primary_key => $key1,
2703
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2704
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2705
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2706

            
2707

            
2708
test 'model delete and id option';
2709
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2710
eval { $dbi->execute("drop table $table1") };
2711
eval { $dbi->execute("drop table $table2") };
2712
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2713
$dbi->execute($create_table1_2);
2714
$dbi->execute($create_table2_2);
2715
$dbi->execute($create_table3);
cleanup
Yuki Kimoto authored on 2011-11-01
2716
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2717
$dbi->model($table1)->delete(id => [1, 2]);
2718
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2719
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2720
$dbi->model($table1)->delete(id => [1, 2]);
2721
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2722
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2723
$dbi->model($table3)->delete(id => [1, 2]);
2724
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2725

            
2726

            
2727
test 'select and id option';
2728
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2729
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2730
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2731
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2732
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2733
  table => $table1,
2734
  primary_key => [$key1, $key2],
2735
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2736
);
2737
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2738
is($row->{$key1}, 1);
2739
is($row->{$key2}, 2);
2740
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2741

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2742
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2743
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2744
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2745
  table => $table1,
2746
  primary_key => $key1,
2747
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2748
);
2749
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2750
is($row->{$key1}, 0);
2751
is($row->{$key2}, 2);
2752
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2753

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2754
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2755
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2756
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2757
  table => $table1,
2758
  primary_key => [$key1, $key2],
2759
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2760
);
2761
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2762
is($row->{$key1}, 1);
2763
is($row->{$key2}, 2);
2764
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2765

            
2766

            
2767
test 'model select_at';
2768
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2769
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2770
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2771
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2772
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2773
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2774
is($row->{$key1}, 1);
2775
is($row->{$key2}, 2);
2776
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2777

            
2778
test 'column separator is default .';
2779
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2780
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2781
eval { $dbi->execute("drop table $table1") };
2782
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2783
$dbi->execute($create_table1);
2784
$dbi->execute($create_table2);
2785
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2786
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2787
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2788
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2789
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2790
  column => [$model->column($table2)],
2791
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2792
);
2793
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2794
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2795

            
2796
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2797
  column => [$model->column($table2 => [$key1, $key3])],
2798
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2799
);
2800
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2801
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2802

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2803
test 'separator';
2804
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2805
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2806
eval { $dbi->execute("drop table $table1") };
2807
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2808
$dbi->execute($create_table1);
2809
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2810

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2811
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
2812
  table => $table1,
2813
  join => [
2814
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
2815
  ],
2816
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2817
);
2818
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
2819
  table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2820
);
2821
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2822
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2823
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2824
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2825
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2826
  column => [
2827
    $model->mycolumn,
2828
    {$table2 => [$key1, $key3]}
2829
  ],
2830
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2831
);
2832
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2833
        {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2834
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2835

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2836
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2837
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2838
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2839
  column => [
2840
    $model->mycolumn,
2841
    {$table2 => [$key1, $key3]}
2842
  ],
2843
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2844
);
2845
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2846
        {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2847
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2848

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2849
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2850
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2851
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2852
  column => [
2853
    $model->mycolumn,
2854
    {$table2 => [$key1, $key3]}
2855
  ],
2856
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2857
);
2858
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2859
  {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2860
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2861

            
2862

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2863
test 'filter_off';
2864
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2865
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2866
eval { $dbi->execute("drop table $table1") };
2867
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2868
$dbi->execute($create_table1);
2869
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2870

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2871
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
2872
  table => $table1,
2873
  join => [
2874
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
2875
  ],
2876
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2877
);
2878
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2879
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2880
$model = $dbi->model($table1);
2881
$result = $model->select(column => $key1);
2882
$result->filter($key1 => sub { $_[0] * 2 });
2883
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2884

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2885
test 'available_datetype';
2886
$dbi = DBIx::Custom->connect;
2887
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2888

            
2889

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2890
test 'select prefix option';
2891
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2892
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2893
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2894
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2895
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2896
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2897

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

            
added tests
Yuki Kimoto authored on 2011-08-26
2899
test 'mapper';
2900
$dbi = DBIx::Custom->connect;
2901
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2902
  id => {key => "$table1.id"},
2903
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2904
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
2905
);
2906
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
2907
"$table1.price" => 1900});
added tests
Yuki Kimoto authored on 2011-08-26
2908

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2909
$dbi = DBIx::Custom->connect;
2910
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2911
  id => {key => "$table1.id"},
2912
  author => ["$table1.author" => $dbi->like_value],
2913
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2914
);
2915
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
2916
"$table1.price" => 1900});
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2917

            
added tests
Yuki Kimoto authored on 2011-08-26
2918
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2919
  id => {key => "$table1.id"},
2920
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2921
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
2922
);
2923
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2924

            
2925
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2926
  id => {key => "$table1.id"},
2927
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2928
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
added tests
Yuki Kimoto authored on 2011-08-26
2929
);
2930
is_deeply($param, {});
2931

            
2932
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2933
  id => {key => "$table1.id"},
2934
  price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2935
);
2936
is_deeply($param, {"$table1.price" => undef});
2937

            
2938
$param = $dbi->mapper(param => {price => 'a'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2939
  id => {key => "$table1.id", condition => 'exists'},
2940
  price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
2941
);
2942
is_deeply($param, {"$table1.price" => '%a'});
2943

            
2944
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2945
  id => {key => "$table1.id"},
2946
  price => ["$table1.price", sub { '%' . $_[0] }]
added tests
Yuki Kimoto authored on 2011-08-26
2947
);
2948
is_deeply($param, {"$table1.price" => '%a'});
2949

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2950
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2951
  price => sub { '%' . $_[0] },
2952
  author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2953
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2954
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2955

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

            
2961
$where = $dbi->where;
2962
$where->clause(['and', ":${key1}{=}"]);
2963
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
2964
$where->param($param);
2965
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2966
$row = $result->all;
2967
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2968

            
2969
$where = $dbi->where;
2970
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2971
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
2972
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2973
$row = $result->all;
2974
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2975
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2976
$row = $result->all;
2977
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2978

            
2979
$where = $dbi->where;
2980
$where->clause(['and', ":${key1}{=}"]);
2981
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
2982
$where->param($param);
2983
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2984
$row = $result->all;
2985
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2986
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2987
$row = $result->all;
2988
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2989

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2991
$where = $dbi->where;
2992
$where->clause(['and', ":${key1}{=}"]);
2993
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
cleanup
Yuki Kimoto authored on 2012-01-20
2994
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2995
$where->param($param);
2996
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2997
$row = $result->all;
2998
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2999

            
3000
$where = $dbi->where;
3001
$where->clause(['and', ":${key1}{=}"]);
3002
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
3003
$where->param($param);
3004
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3005
$row = $result->all;
3006
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3007

            
3008
$where = $dbi->where;
3009
$where->clause(['and', ":${key1}{=}"]);
3010
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
cleanup
Yuki Kimoto authored on 2012-01-20
3011
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3012
$where->param($param);
3013
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3014
$row = $result->all;
3015
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3016

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3018
$where = $dbi->where;
3019
$where->clause(['and', ":${key1}{=}"]);
3020
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
3021
$where->param($param);
3022
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3023
$row = $result->all;
3024
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3025

            
3026
$where = $dbi->where;
3027
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3028
  id => {key => "$table1.id"},
3029
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3030
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3031
);
3032
$where->param($param);
3033
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3034
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3035

            
3036
$where = $dbi->where;
3037
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3038
  id => {key => "$table1.id"},
3039
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3040
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3041
);
3042
$where->param($param);
3043
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
3044

            
3045
$where = $dbi->where;
3046
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3047
  id => {key => "$table1.id"},
3048
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3049
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3050
);
3051
$where->param($param);
3052
is_deeply($where->param, {});
3053

            
3054
$where = $dbi->where;
3055
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3056
  id => {key => "$table1.id"},
3057
  price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3058
);
3059
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
3060

            
3061
$where = $dbi->where;
3062
$param = $dbi->mapper(param => {price => 'a'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3063
  id => {key => "$table1.id", condition => 'exists'},
3064
  price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3065
);
3066
is_deeply($param, {"$table1.price" => '%a'});
3067

            
3068
$where = $dbi->where;
3069
$param = $dbi->mapper(param => {id => [1, 2], author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3070
  id => {key => "$table1.id"},
3071
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3072
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3073
);
3074
is_deeply($param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3075
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3076

            
3077
$where = $dbi->where;
3078
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900}, condition => 'length')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3079
  id => {key => "$table1.id"},
3080
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3081
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3082
);
3083
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3084
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3085

            
3086
$where = $dbi->where;
3087
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3088
  id => {key => "$table1.id", condition => 'length'},
3089
  author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
3090
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3091
);
3092
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3093
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3094

            
3095
$where = $dbi->where;
3096
$param = $dbi->mapper(param => {id => 'a', author => 'b', price => 'c'}, pass => [qw/id author/])
cleanup
Yuki Kimoto authored on 2012-01-20
3097
->map(price => {key => 'book.price'});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3098
is_deeply($param, {id => 'a', author => 'b', 'book.price' => 'c'});
3099

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3100
test 'order';
3101
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3102
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3103
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3104
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3105
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3106
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3107
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3108
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3109
$order->prepend($key1, "$key2 desc");
3110
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3111
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
3112
{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3113
$order->prepend("$key1 desc");
3114
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3115
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
cleanup
Yuki Kimoto authored on 2012-01-20
3116
{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3117

            
3118
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3119
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3120
$result = $dbi->select(table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
3121
column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
3122
append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3123
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
cleanup
Yuki Kimoto authored on 2012-01-20
3124
{"$table1-$key1" => 1, "$table1-$key2" => 1},
3125
{"$table1-$key1" => 2, "$table1-$key2" => 4},
3126
{"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3127

            
3128
test 'tag_parse';
3129
$dbi = DBIx::Custom->connect;
3130
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3131
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3132
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3133
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3134
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3135
ok($@);
3136

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3137
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3138
{
cleanup
Yuki Kimoto authored on 2012-01-20
3139
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3140
  $dbi = DBIx::Custom->connect;
3141
  eval { $dbi->execute("drop table $table1") };
3142
  $dbi->execute($create_table1);
3143
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3144
  eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3145
  ok($@);
3146
  eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) };
3147
  ok($@);
3148
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3149
}
3150

            
3151
{
cleanup
Yuki Kimoto authored on 2012-01-20
3152
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3153
  $dbi = DBIx::Custom->connect;
3154
  eval { $dbi->execute("drop table $table1") };
3155
  $dbi->execute($create_table1);
3156
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3157
  is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1);
3158
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3159
}
3160

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3161
test 'last_sql';
3162
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3163
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3164
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3165
$dbi->execute("select * from $table1");
micro optimization
Yuki Kimoto authored on 2011-11-18
3166
is($dbi->last_sql, " select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3167

            
3168
eval{$dbi->execute("aaa")};
micro optimization
Yuki Kimoto authored on 2011-11-18
3169
is($dbi->last_sql, ' aaa');
test cleanup
Yuki Kimoto authored on 2011-08-10
3170

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3199
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3200
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
3201
  $source,
3202
  {"$table1.$key1" => 1, "$table1.$key2" => 1},
3203
  filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3204
);
3205
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3206
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3207

            
3208
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3209
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3210
$dbi->execute($create_table1_highperformance);
3211
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3212
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3213
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3214
];
3215
{
cleanup
Yuki Kimoto authored on 2012-01-20
3216
  my $query;
3217
  for my $row (@$rows) {
3218
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3219
    $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3220
  }
3221
  is_deeply($dbi->select(table => $table1)->all,
3222
    [
3223
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3224
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3225
    ]
3226
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3227
}
3228

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3229
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3230
$dbi->execute($create_table1_highperformance);
3231
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3232
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3233
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3234
];
3235
{
cleanup
Yuki Kimoto authored on 2012-01-20
3236
  my $query;
3237
  my $sth;
3238
  for my $row (@$rows) {
3239
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3240
    $sth ||= $query->{sth};
3241
    $sth->execute(map { $row->{$_} } sort keys %$row);
3242
  }
3243
  is_deeply($dbi->select(table => $table1)->all,
3244
    [
3245
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3246
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3247
    ]
3248
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3249
}
3250

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3251
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3252
$dbi->execute($create_table1_highperformance);
3253
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3254
  {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
3255
  {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3256
];
3257
{
cleanup
Yuki Kimoto authored on 2012-01-20
3258
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3259
  my $query;
3260
  for my $row (@$rows) {
3261
    $query ||= $model->insert($row, query => 1);
3262
    $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3263
  }
3264
  is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3265
    [
3266
      {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3267
      {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
3268
    ]
3269
  );
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3270
}
3271

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3272
eval { $dbi->execute("drop table $table1") };
3273
$dbi->execute($create_table1);
3274
{
cleanup
Yuki Kimoto authored on 2012-01-20
3275
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3276
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3277
  eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3278
  like($@, qr/primary_key/);
3279
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3280
}
3281

            
3282
{
cleanup
Yuki Kimoto authored on 2012-01-20
3283
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3284
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3285
  $model->insert({$key1 => 1});
3286
  $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3287
    table => $table1, primary_key => $key1);
3288
  is($result->one->{$key1}, 1);
3289
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3290
}
3291

            
3292
eval { $dbi->execute("drop table $table1") };
3293
$dbi->execute($create_table1);
3294
{
cleanup
Yuki Kimoto authored on 2012-01-20
3295
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3296
  $model->insert({$key1 => 1});
3297
  eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3298
  is($result->one->{$key1}, 1);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3299
}
3300

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3301
test 'id option more';
3302
eval { $dbi->execute("drop table $table1") };
3303
$dbi->execute($create_table1_highperformance);
3304
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3305
  $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3306
};
3307
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3308
$model->insert($row);
3309
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3310
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3311
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3312
  {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3313
);
3314

            
3315
eval { $dbi->execute("drop table $table1") };
3316
eval { $dbi->execute("drop table $table2") };
3317
$dbi->execute($create_table1);
3318
$dbi->execute($create_table2);
3319
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3320
$model->insert({$key1 => 1, $key2 => 2});
3321
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
3322
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3323
$model->insert({$key1 => 1, $key3 => 3});
3324
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3325
  column => {$table1 => ["$key2"]},
3326
  id => 1
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3327
);
3328
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3329

            
3330
eval { $dbi->execute("drop table $table1") };
3331
$dbi->execute($create_table1_highperformance);
3332
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3333
  $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3334
};
3335
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3336
$model->insert($row);
3337
$query = $model->delete(id => 1, query => 1);
3338
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3339
is_deeply($dbi->select(table => $table1)->all, []);
3340

            
3341
eval { $dbi->execute("drop table $table1") };
3342
eval { $dbi->execute($create_table1_highperformance) };
3343
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3344
  $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3345
};
3346
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3347
$model->insert($row);
3348
$query = $model->select(id => 1, query => 1);
3349
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3350
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3351
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3352
  {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2},
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3353
);
3354

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3355
test 'result';
3356
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3357
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3358
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3359
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3360
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3361

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3362
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3363
@rows = ();
3364
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
3365
  push @rows, [@$row];
test cleanup
Yuki Kimoto authored on 2011-08-10
3366
}
3367
is_deeply(\@rows, [[1, 2], [3, 4]]);
3368

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3369
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3370
@rows = ();
3371
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
3372
  push @rows, {%$row};
test cleanup
Yuki Kimoto authored on 2011-08-10
3373
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3374
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3375

            
3376
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3377
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3378
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3379
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3380
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3381

            
3382
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3383
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3384
$rows = $result->fetch_all;
3385
is_deeply($rows, [[1, 2], [3, 4]]);
3386

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3391
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3392
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3393
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3394
$rows = $result->fetch_all;
3395
is_deeply($rows, [[3, 2], [9, 4]], "array");
3396

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

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3409
test 'DBIx::Custom::Result fetch_multi';
3410
eval { $dbi->execute("drop table $table1") };
3411
$dbi->execute($create_table1);
3412
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3413
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3414
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3415
$result = $dbi->select(table => $table1);
3416
$rows = $result->fetch_multi(2);
3417
is_deeply($rows, [[1, 2], [3, 4]]);
3418
$rows = $result->fetch_multi(2);
3419
is_deeply($rows, [[5, 6]]);
3420
$rows = $result->fetch_multi(2);
3421
ok(!$rows);
3422

            
3423
test 'DBIx::Custom::Result fetch_hash_multi';
3424
eval { $dbi->execute("drop table $table1") };
3425
$dbi->execute($create_table1);
3426
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3427
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3428
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3429
$result = $dbi->select(table => $table1);
3430
$rows = $result->fetch_hash_multi(2);
3431
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3432
$rows = $result->fetch_hash_multi(2);
3433
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3434
$rows = $result->fetch_hash_multi(2);
3435
ok(!$rows);
3436

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3437
test "query_builder";
3438
$datas = [
cleanup
Yuki Kimoto authored on 2012-01-20
3439
  # Basic tests
3440
  {   name            => 'placeholder basic',
3441
    source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
3442
    sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
3443
    columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3444
  },
3445
  {
3446
    name            => 'placeholder in',
3447
    source            => "{in k1 3}",
3448
    sql_expected    => "k1 in (?, ?, ?)",
3449
    columns_expected   => [qw/k1 k1 k1/]
3450
  },
3451
  
3452
  # Table name
3453
  {
3454
    name            => 'placeholder with table name',
3455
    source            => "{= a.k1} {= a.k2}",
3456
    sql_expected    => "a.k1 = ? a.k2 = ?",
3457
    columns_expected  => [qw/a.k1 a.k2/]
3458
  },
3459
  {   
3460
    name            => 'placeholder in with table name',
3461
    source            => "{in a.k1 2} {in b.k2 2}",
3462
    sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
3463
    columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3464
  },
3465
  {
3466
    name            => 'not contain tag',
3467
    source            => "aaa",
3468
    sql_expected    => "aaa",
3469
    columns_expected  => [],
3470
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3471
];
3472

            
3473
for (my $i = 0; $i < @$datas; $i++) {
cleanup
Yuki Kimoto authored on 2012-01-20
3474
  my $data = $datas->[$i];
3475
  my $dbi = DBIx::Custom->new;
3476
  my $builder = $dbi->query_builder;
3477
  my $query = $builder->build_query($data->{source});
3478
  is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3479
  is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3480
}
3481

            
cleanup
Yuki Kimoto authored on 2011-08-13
3482
$dbi = DBIx::Custom->new;
3483
$builder = $dbi->query_builder;
3484
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
3485
  p => sub {
3486
    my @args = @_;
3487
    
3488
    my $expand    = "? $args[0] $args[1]";
3489
    my $columns = [2];
3490
    return [$expand, $columns];
3491
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3492
);
3493

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3504
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3505
  q => 'string'
test cleanup
Yuki Kimoto authored on 2011-08-10
3506
});
3507

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3511
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3512
  r => sub {} 
test cleanup
Yuki Kimoto authored on 2011-08-10
3513
});
3514

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3518
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3519
  s => sub { return ["a", ""]} 
test cleanup
Yuki Kimoto authored on 2011-08-10
3520
});
3521

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3525
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
3526
  t => sub {return ["a", []]}
test cleanup
Yuki Kimoto authored on 2011-08-10
3527
);
3528

            
3529

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

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

            
3537
eval{$builder->build_query("{in a}")};
3538
like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/,
cleanup
Yuki Kimoto authored on 2012-01-20
3539
  "in : key not exist");
cleanup test
Yuki Kimoto authored on 2011-08-15
3540

            
3541
eval{$builder->build_query("{in a r}")};
3542
like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/,
cleanup
Yuki Kimoto authored on 2012-01-20
3543
  "in : key not exist");
cleanup test
Yuki Kimoto authored on 2011-08-15
3544

            
3545
test 'variouse source';
3546
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3547
$query = $builder->build_query($source);
3548
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3549

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

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

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

            
3562
$source = "a {= b} }";
3563
eval{$builder->build_query($source)};
3564
like($@, qr/unexpected "}"/, "error : 1");
3565

            
3566
$source = "a {= {}";
3567
eval{$builder->build_query($source)};
3568
like($@, qr/unexpected "{"/, "error : 2");
3569

            
3570
test 'select() sqlfilter option';
3571
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3572
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3573
eval { $dbi->execute("drop table $table1") };
3574
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3575
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3576
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3577
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3578
  table => $table1,
3579
  column => $key1,
3580
  sqlfilter => sub {
3581
    my $sql = shift;
3582
    $sql = "select * from ( $sql ) t where $key1 = 1";
3583
    return $sql;
3584
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3585
)->all;
3586
is_deeply($rows, [{$key1 => 1}]);
3587

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3588
test 'select() after_build_sql option';
3589
$dbi = DBIx::Custom->connect;
3590
$dbi->user_table_info($user_table_info);
3591
eval { $dbi->execute("drop table $table1") };
3592
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3593
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3594
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3595
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3596
  table => $table1,
3597
  column => $key1,
3598
  after_build_sql => sub {
3599
    my $sql = shift;
3600
    $sql = "select * from ( $sql ) t where $key1 = 1";
3601
    return $sql;
3602
  }
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3603
)->all;
3604
is_deeply($rows, [{$key1 => 1}]);
3605

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3606
test 'dbi method from model';
3607
$dbi = MyDBI9->connect;
3608
eval { $dbi->execute("drop table $table1") };
3609
$dbi->execute($create_table1);
3610
$dbi->setup_model;
3611
$model = $dbi->model($table1);
3612
eval{$model->execute("select * from $table1")};
3613
ok(!$@);
3614

            
3615
test 'column table option';
3616
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3617
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3618
eval { $dbi->execute("drop table $table1") };
3619
$dbi->execute($create_table1);
3620
eval { $dbi->execute("drop table $table2") };
3621
$dbi->execute($create_table2);
3622
$dbi->setup_model;
3623
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3624
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3625
$model = $dbi->model($table1);
3626
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3627
  column => [
3628
    $model->column($table2, {alias => $table2_alias})
3629
  ],
3630
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3631
);
3632
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3633
        {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3634

            
3635
$dbi->separator('__');
3636
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3637
  column => [
3638
    $model->column($table2, {alias => $table2_alias})
3639
  ],
3640
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3641
);
3642
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3643
  {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3644

            
3645
$dbi->separator('-');
3646
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3647
  column => [
3648
      $model->column($table2, {alias => $table2_alias})
3649
  ],
3650
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3651
);
3652
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3653
  {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3654

            
3655
test 'create_model';
3656
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3657
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3658
eval { $dbi->execute("drop table $table1") };
3659
eval { $dbi->execute("drop table $table2") };
3660
$dbi->execute($create_table1);
3661
$dbi->execute($create_table2);
3662

            
3663
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3664
  table => $table1,
3665
  join => [
3666
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3667
  ],
3668
  primary_key => [$key1]
cleanup test
Yuki Kimoto authored on 2011-08-15
3669
);
3670
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3671
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3672
);
3673
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3674
  table => $table3,
3675
  filter => [
3676
    $key1 => {in => sub { uc $_[0] }}
3677
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
3678
);
3679
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3680
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3681
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3682
$model = $dbi->model($table1);
3683
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3684
  column => [$model->mycolumn, $model->column($table2)],
3685
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-15
3686
);
3687
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3688
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3689
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3690

            
3691
test 'model method';
3692
$dbi = DBIx::Custom->connect;
3693
eval { $dbi->execute("drop table $table2") };
3694
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3695
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3696
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3697
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3698
);
3699
$model->method(foo => sub { shift->select(@_) });
3700
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3701

            
3702
test 'model helper';
3703
$dbi = DBIx::Custom->connect;
3704
eval { $dbi->execute("drop table $table2") };
3705
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3706
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3707
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3708
  table => $table2
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3709
);
3710
$model->helper(foo => sub { shift->select(@_) });
3711
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3712

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

            
3720
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3721
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3722
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3723
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3724
where $key1 = 1
3725
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3726
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3727
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3728
$rows   = $result->all;
3729
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3730
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3731
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
3732

            
3733

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

            
3740
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3741
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3742
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3743
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3744
where $key1 = 1
3745
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3746
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3747
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3748
$rows   = $result->all;
3749
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3750
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3751
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
3752

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

            
3759
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3760
$assign_clause = $dbi->update_param($param, {no_set => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
3761
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3762
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3763
where $key1 = 1
3764
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3765
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3766
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3767
$rows   = $result->all;
3768
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3769
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3770
  "update param no_set");
cleanup test
Yuki Kimoto authored on 2011-08-15
3771

            
cleanup
Yuki Kimoto authored on 2012-01-20
3772
          
cleanup test
Yuki Kimoto authored on 2011-08-15
3773
$dbi = DBIx::Custom->connect;
3774
eval { $dbi->execute("drop table $table1") };
3775
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
3776
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
3777
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3778

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3779
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3780
$assign_clause = $dbi->assign_param($param);
3781
$sql = <<"EOS";
3782
update $table1 set $assign_clause
3783
where $key1 = 1
3784
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3785
$dbi->execute($sql, $param, table => $table1);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3786
$result = $dbi->execute("select * from $table1 order by $key1");
3787
$rows   = $result->all;
3788
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3789
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3790
  "basic");
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3791

            
3792
$param = {$key2 => 11};
3793
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3794
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3795
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3796
where $key1 = 1
3797
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3798
$dbi->execute($sql, $param, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3799
$result = $dbi->execute("select * from $table1 order by $key1");
3800
$rows   = $result->all;
3801
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3802
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3803
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3804

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3805
test 'Model class';
3806
$dbi = MyDBI1->connect;
3807
eval { $dbi->execute("drop table $table1") };
3808
$dbi->execute($create_table1);
3809
$model = $dbi->model($table1);
3810
$model->insert({$key1 => 'a', $key2 => 'b'});
3811
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3812
eval { $dbi->execute("drop table $table2") };
3813
$dbi->execute($create_table2);
3814
$model = $dbi->model($table2);
3815
$model->insert({$key1 => 'a'});
3816
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3817
is($dbi->models->{$table1}, $dbi->model($table1));
3818
is($dbi->models->{$table2}, $dbi->model($table2));
3819

            
3820
$dbi = MyDBI4->connect;
3821
eval { $dbi->execute("drop table $table1") };
3822
$dbi->execute($create_table1);
3823
$model = $dbi->model($table1);
3824
$model->insert({$key1 => 'a', $key2 => 'b'});
3825
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3826
eval { $dbi->execute("drop table $table2") };
3827
$dbi->execute($create_table2);
3828
$model = $dbi->model($table2);
3829
$model->insert({$key1 => 'a'});
3830
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3831

            
3832
$dbi = MyDBI5->connect;
3833
eval { $dbi->execute("drop table $table1") };
3834
eval { $dbi->execute("drop table $table2") };
3835
$dbi->execute($create_table1);
3836
$dbi->execute($create_table2);
3837
$model = $dbi->model($table2);
3838
$model->insert({$key1 => 'a'});
3839
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
3840
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3841
$model = $dbi->model($table1);
3842
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3843

            
3844
test 'primary_key';
3845
$dbi = MyDBI1->connect;
3846
$model = $dbi->model($table1);
3847
$model->primary_key([$key1, $key2]);
3848
is_deeply($model->primary_key, [$key1, $key2]);
3849

            
3850
test 'columns';
3851
$dbi = MyDBI1->connect;
3852
$model = $dbi->model($table1);
3853
$model->columns([$key1, $key2]);
3854
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3855

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3856
test 'setup_model';
3857
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3858
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3859
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3860
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3861

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3862
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3863
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3864
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3865
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3866
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3867

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3868
test 'each_column';
3869
$dbi = DBIx::Custom->connect;
3870
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3871
eval { $dbi->execute("drop table $table1") };
3872
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3873
eval { $dbi->execute("drop table $table3") };
3874
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3875
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3876

            
3877
$infos = [];
3878
$dbi->each_column(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
3879
  my ($self, $table, $column, $cinfo) = @_;
3880
  
3881
  if ($table =~ /^table\d/i) {
3882
     my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3883
     push @$infos, $info;
3884
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3885
});
3886
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3887
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
3888
  [
3889
    [$table1, $key1, $key1],
3890
    [$table1, $key2, $key2],
3891
    [$table2, $key1, $key1],
3892
    [$table2, $key3, $key3]
3893
  ]
3894
  
cleanup test
Yuki Kimoto authored on 2011-08-10
3895
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3896

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3897
test 'each_table';
3898
$dbi = DBIx::Custom->connect;
3899
eval { $dbi->execute("drop table $table1") };
3900
eval { $dbi->execute("drop table $table2") };
3901
$dbi->execute($create_table2);
3902
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3903

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3904
$infos = [];
3905
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
3906
  my ($self, $table, $table_info) = @_;
3907
  
3908
  if ($table =~ /^table\d/i) {
3909
    my $info = [$table, $table_info->{TABLE_NAME}];
3910
    push @$infos, $info;
3911
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3912
});
3913
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3914
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
3915
  [
3916
    [$table1, $table1],
3917
    [$table2, $table2],
3918
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3919
);
3920

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3921
$dbi = DBIx::Custom->connect;
3922
eval { $dbi->execute("drop table $table1") };
3923
eval { $dbi->execute("drop table $table2") };
3924
$dbi->execute($create_table2);
3925
$dbi->execute($create_table1_type);
3926

            
3927
$infos = [];
3928
$dbi->user_table_info($user_table_info);
3929
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
3930
  my ($self, $table, $table_info) = @_;
3931
  
3932
  if ($table =~ /^table\d/i) {
3933
     my $info = [$table, $table_info->{TABLE_NAME}];
3934
     push @$infos, $info;
3935
  }
cleanup test
Yuki Kimoto authored on 2011-08-16
3936
});
3937
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3938
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
3939
  [
3940
    [$table1, $table1],
3941
    [$table2, $table2],
3942
    [$table3, $table3],
3943
  ]
cleanup test
Yuki Kimoto authored on 2011-08-16
3944
);
3945

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3946
test 'type_rule into';
3947
eval { $dbi->execute("drop table $table1") };
3948
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3949
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3950

            
3951

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3952
$dbi = DBIx::Custom->connect;
3953
eval { $dbi->execute("drop table $table1") };
3954
$dbi->execute($create_table1_type);
3955

            
cleanup
Yuki Kimoto authored on 2011-08-16
3956
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3957
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
3958
  into1 => {
3959
    $date_typename => sub { '2010-' . $_[0] }
3960
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
3961
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3962
$dbi->insert({$key1 => '01-01'}, table => $table1);
3963
$result = $dbi->select(table => $table1);
3964
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3965

            
3966
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3967
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3968
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3969
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3970
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
3971
  into1 => [
3972
     [$date_typename, $datetime_typename] => sub {
3973
        my $value = shift;
3974
        $value =~ s/02/03/g;
3975
        return $value;
3976
     }
3977
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
3978
);
3979
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3980
$result = $dbi->select(table => $table1);
3981
$row = $result->one;
3982
like($row->{$key1}, qr/^2010-01-03/);
3983
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3984

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3985
$dbi = DBIx::Custom->connect;
3986
eval { $dbi->execute("drop table $table1") };
3987
$dbi->execute($create_table1_type);
3988
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3989
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3990
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
3991
  into1 => [
3992
    [$date_typename, $datetime_typename] => sub {
3993
      my $value = shift;
3994
      $value =~ s/02/03/g;
3995
      return $value;
3996
    }
3997
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3998
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3999
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
4000
  "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
4001
  {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
4002
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4003
$row = $result->one;
4004
like($row->{$key1}, qr/^2010-01-03/);
4005
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4006

            
4007
$dbi = DBIx::Custom->connect;
4008
eval { $dbi->execute("drop table $table1") };
4009
$dbi->execute($create_table1_type);
4010
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4011
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4012
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4013
  into1 => [
4014
    [$date_typename, $datetime_typename] => sub {
4015
      my $value = shift;
4016
      $value =~ s/02/03/g;
4017
      return $value;
4018
    }
4019
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4020
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4021
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
4022
  "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
4023
  {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
4024
  table => $table1
cleanup test
Yuki Kimoto authored on 2011-08-15
4025
);
4026
$row = $result->one;
4027
like($row->{$key1}, qr/^2010-01-03/);
4028
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4029

            
4030
$dbi = DBIx::Custom->connect;
4031
eval { $dbi->execute("drop table $table1") };
4032
$dbi->execute($create_table1_type);
4033
$dbi->register_filter(convert => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4034
  my $value = shift || '';
4035
  $value =~ s/02/03/;
4036
  return $value;
cleanup test
Yuki Kimoto authored on 2011-08-15
4037
});
cleanup
Yuki Kimoto authored on 2011-08-16
4038
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4039
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4040
  from1 => {
4041
    $date_datatype => 'convert',
4042
  },
4043
  into1 => {
4044
      $date_typename => 'convert',
4045
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4046
);
4047
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
4048
$result = $dbi->select(table => $table1);
4049
like($result->fetch->[0], qr/^2010-03-03/);
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
4050
$result = $dbi->select(column => [$key1, $key1], table => $table1);
4051
$row = $result->fetch;
4052
like($row->[0], qr/^2010-03-03/);
4053
like($row->[1], qr/^2010-03-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4054

            
4055
test 'type_rule and filter order';
4056
$dbi = DBIx::Custom->connect;
4057
eval { $dbi->execute("drop table $table1") };
4058
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4059
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4060
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4061
  into1 => {
4062
    $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4063
  },
4064
  into2 => {
4065
    $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4066
  },
4067
  from1 => {
4068
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4069
  },
4070
  from2 => {
4071
    $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
4072
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4073
);
4074
$dbi->insert({$key1 => '2010-01-03'}, 
cleanup
Yuki Kimoto authored on 2012-01-20
4075
table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
cleanup test
Yuki Kimoto authored on 2011-08-15
4076
$result = $dbi->select(table => $table1);
4077
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4078
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4079

            
4080

            
4081
$dbi = DBIx::Custom->connect;
4082
eval { $dbi->execute("drop table $table1") };
4083
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4084
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4085
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4086
  from1 => {
4087
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4088
  },
4089
  from2 => {
4090
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4091
  },
cleanup test
Yuki Kimoto authored on 2011-08-15
4092
);
4093
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4094
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4095
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4096
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4097
  from1 => {
4098
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4099
  },
4100
  from2 => {
4101
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
4102
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4103
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4104
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4105
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4106

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

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

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

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

            
4172
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4173
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4174
$dbi->execute($create_table1_type);
4175
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
4176
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4177
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4178
  into1 => {
4179
    $date_typename => 'ppp'
4180
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4181
);
4182
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4183
$result = $dbi->select(table => $table1);
4184
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4185

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4186
eval{$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4187
  into1 => {
4188
    $date_typename => 'pp'
4189
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4190
)};
4191
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4192

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4193
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4194
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4195
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4196
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4197
  $dbi->type_rule(
4198
    from1 => {
4199
      Date => sub { $_[0] * 2 },
4200
    }
4201
  );
cleanup test
Yuki Kimoto authored on 2011-08-10
4202
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4203
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4204

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4205
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4206
  $dbi->type_rule(
4207
    into1 => {
4208
      Date => sub { $_[0] * 2 },
4209
    }
4210
  );
cleanup test
Yuki Kimoto authored on 2011-08-15
4211
};
4212
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4213

            
4214
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4215
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4216
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4217
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4218
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4219
  from1 => {
4220
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4221
  },
4222
  into1 => {
4223
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4224
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4225
);
4226
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4227
$result = $dbi->select(table => $table1);
4228
$result->type_rule_off;
4229
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4230

            
4231
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4232
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4233
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4234
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4235
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4236
  from1 => {
4237
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4238
    $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4239
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4240
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4241
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
4242
$result = $dbi->select(table => $table1);
4243
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4244
  from1 => {
4245
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4246
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4247
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4248
$row = $result->one;
4249
like($row->{$key1}, qr/^2010-01-05/);
4250
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4251

            
4252
$result = $dbi->select(table => $table1);
4253
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4254
  from1 => {
4255
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4256
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4257
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4258
$row = $result->one;
4259
like($row->{$key1}, qr/2010-01-05/);
4260
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4261

            
4262
$result = $dbi->select(table => $table1);
4263
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4264
  from1 => {
4265
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4266
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4267
);
4268
$row = $result->one;
4269
like($row->{$key1}, qr/2010-01-05/);
4270
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4271

            
4272
$result = $dbi->select(table => $table1);
4273
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4274
  from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
cleanup test
Yuki Kimoto authored on 2011-08-15
4275
);
4276
$row = $result->one;
4277
like($row->{$key1}, qr/2010-01-05/);
4278
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4279

            
4280
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4281
$result = $dbi->select(table => $table1);
4282
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4283
  from1 => [$date_datatype => 'five']
cleanup test
Yuki Kimoto authored on 2011-08-15
4284
);
4285
$row = $result->one;
4286
like($row->{$key1}, qr/^2010-01-05/);
4287
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4288

            
4289
$result = $dbi->select(table => $table1);
4290
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4291
  from1 => [$date_datatype => undef]
cleanup test
Yuki Kimoto authored on 2011-08-15
4292
);
4293
$row = $result->one;
4294
like($row->{$key1}, qr/^2010-01-03/);
4295
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4296

            
4297
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4298
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4299
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4300
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4301
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4302
  from1 => {
4303
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4304
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4305
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4306
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4307
$result = $dbi->select(table => $table1);
4308
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4309
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4310

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4311
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4312
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4313
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4314
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4315
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4316
  from1 => {
4317
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4318
  },
cleanup test
Yuki Kimoto authored on 2011-08-15
4319
);
4320
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4321
$result = $dbi->select(table => $table1);
4322
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4323
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4324

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4325
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4326
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4327
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4328
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4329
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4330
  into1 => {
4331
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4332
  },
4333
  into2 => {
4334
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4335
  },
4336
  from1 => {
4337
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4338
  },
4339
  from2 => {
4340
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4341
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4342
);
4343
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4344
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4345
like($result->type_rule_off->fetch_one->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4346
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4347
like($result->type_rule_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4348

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4349
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4350
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4351
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4352
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4353
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4354
  into1 => {
4355
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4356
  },
4357
  into2 => {
4358
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4359
  },
4360
  from1 => {
4361
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
4362
  },
4363
  from2 => {
4364
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4365
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4366
);
4367
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4368
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4369
like($result->type_rule1_off->fetch_one->[0], qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4370
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4371
like($result->type_rule1_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4372

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4373
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4374
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4375
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4376
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4377
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4378
  into1 => {
4379
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4380
  },
4381
  into2 => {
4382
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4383
  },
4384
  from1 => {
4385
    $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4386
  },
4387
  from2 => {
4388
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4389
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4390
);
4391
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4392
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4393
like($result->type_rule2_off->fetch_one->[0], qr/^2010-01-06/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4394
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4395
like($result->type_rule2_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4396

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

            
4417
$dbi = DBIx::Custom->connect;
4418
eval { $dbi->execute("drop table $table1") };
4419
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4420
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4421
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4422
eval { $dbi->execute("drop table $table2") };
4423
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4424
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4425
eval { $dbi->execute("drop table $table3") };
4426
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4427
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4428
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4429
  table => $table1,
4430
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4431
  where   => {"$table1.$key2" => 2},
4432
  join  => {
4433
    clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4434
    table => [$table1, $table2]
4435
  }
added test
Yuki Kimoto authored on 2011-10-27
4436
)->all;
4437
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
4438

            
4439
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4440
  table => $table1,
4441
  where   => {$key1 => 1},
4442
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4443
)->all;
4444
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4445

            
4446
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4447
  table => $table1,
4448
  where   => {$key1 => 1},
4449
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4450
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4451
)->all;
4452
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4453

            
4454
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4455
  column => "$table3.$key4 as ${table3}__$key4",
4456
  table => $table1,
4457
  where   => {"$table1.$key1" => 1},
4458
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4459
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4460
)->all;
4461
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4462

            
4463
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4464
  column => "$table1.$key1 as ${table1}__$key1",
4465
  table => $table1,
4466
  where   => {"$table3.$key4" => 4},
4467
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4468
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4469
)->all;
4470
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4471

            
4472
$dbi = DBIx::Custom->connect;
4473
eval { $dbi->execute("drop table $table1") };
4474
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4475
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4476
eval { $dbi->execute("drop table $table2") };
4477
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4478
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4479
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4480
  table => $table1,
4481
  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",
4482
  where   => {"$table1.$key2" => 2},
4483
  join  => ["left outer join ${q}$table2$p on ${q}$table1$p.${q}$key1$p = ${q}$table2$p.${q}$key1$p"],
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4484
)->all;
4485
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
cleanup
Yuki Kimoto authored on 2012-01-20
4486
  'quote');
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4487

            
4488

            
4489
$dbi = DBIx::Custom->connect;
4490
eval { $dbi->execute("drop table $table1") };
4491
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4492
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4493
$sql = <<"EOS";
4494
left outer join (
cleanup
Yuki Kimoto authored on 2012-01-20
4495
select * from $table1 t1
4496
where t1.$key2 = (
4497
  select max(t2.$key2) from $table1 t2
4498
  where t1.$key1 = t2.$key1
4499
)
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4500
) $table3 on $table1.$key1 = $table3.$key1
4501
EOS
4502
$join = [$sql];
4503
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4504
  table => $table1,
4505
  column => "$table3.$key1 as ${table3}__$key1",
4506
  join  => $join
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4507
)->all;
4508
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4509

            
4510
$dbi = DBIx::Custom->connect;
4511
eval { $dbi->execute("drop table $table1") };
4512
eval { $dbi->execute("drop table $table2") };
4513
$dbi->execute($create_table1);
4514
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4515
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4516
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4517
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4518
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4519
  table => $table1,
4520
  join => [
4521
    "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4522
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4523
);
4524
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4525
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4526
  table => $table1,
4527
  column => [{$table2 => [$key3]}],
4528
  join => [
4529
    "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4530
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4531
);
4532
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4533
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4534
  table => $table1,
4535
  column => [{$table2 => [$key3]}],
4536
  join => [
4537
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4538
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4539
);
4540
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4541

            
4542
$dbi = DBIx::Custom->connect;
4543
eval { $dbi->execute("drop table $table1") };
4544
eval { $dbi->execute("drop table $table2") };
4545
$dbi->execute($create_table1);
4546
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4547
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4548
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4549
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4550
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4551
  table => $table1,
4552
  column => [{$table2 => [$key3]}],
4553
  join => [
4554
    {
4555
      clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4556
      table => [$table1, $table2]
4557
    }
4558
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4559
);
4560
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4561

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4562
$dbi = DBIx::Custom->connect;
4563
eval { $dbi->execute("drop table $table1") };
4564
eval { $dbi->execute("drop table $table2") };
4565
$dbi->execute($create_table1);
4566
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4567
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4568
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4569
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4570
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4571
  table => $table1,
4572
  column => [{$table2 => [$key3]}],
4573
  join => [
4574
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4575
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4576
);
4577
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4578

            
4579
$dbi = DBIx::Custom->connect;
4580
eval { $dbi->execute("drop table $table1") };
4581
eval { $dbi->execute("drop table $table2") };
4582
$dbi->execute($create_table1);
4583
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4584
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4585
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4586
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4587
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4588
  table => $table1,
4589
  column => [{$table2 => [$key3]}],
4590
  join => [
4591
    "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4592
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4593
);
4594
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4595

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4596
test 'columns';
4597
$dbi = MyDBI1->connect;
4598
$model = $dbi->model($table1);
4599

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4600
test 'count';
4601
$dbi = DBIx::Custom->connect;
4602
eval { $dbi->execute("drop table $table1") };
4603
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4604
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4605
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4606
is($dbi->count(table => $table1), 2);
4607
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4608
$model = $dbi->create_model(table => $table1);
4609
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4610

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4611
eval { $dbi->execute("drop table $table1") };
4612
eval { $dbi->execute("drop table $table2") };
4613
$dbi->execute($create_table1);
4614
$dbi->execute($create_table2);
4615
$model = $dbi->create_model(table => $table1, primary_key => $key1);
4616
$model->insert({$key1 => 1, $key2 => 2});
4617
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
4618
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4619
$model->insert({$key1 => 1, $key3 => 3});
4620
is($model->count(id => 1), 1);
4621
is($model->count(where => {"$table2.$key3" => 3}), 1);
4622

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