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

            
fixed test
Yuki Kimoto authored on 2012-03-01
19
# Dot to under score
20
sub u($) {
21
  my $value = shift;
22
  $value =~ s/\./_/g;
23
  return $value;
24
}
25

            
improved test
Yuki Kimoto authored on 2012-03-01
26
sub u2($) {
27
  my $value = shift;
28
  $value =~ s/\./__/g;
29
  return $value;
30
}
31

            
32
sub hy($) {
33
  my $value = shift;
34
  $value =~ s/\./-/g;
35
  return $value;
36
}
37

            
improved test
Yuki Kimoto authored on 2012-03-01
38
sub colon2 {
39
  my $value = shift;
40
  $value =~ s/\./::/g;
41
  return $value;
42
}
43

            
improved tests
Yuki Kimoto authored on 2012-03-01
44
sub table_only {
45
  my $value = shift;
46
  $value =~ s/^.+\.//;
47
  return $value;
48
}
49

            
cleanup test
Yuki Kimoto authored on 2011-08-15
50
# Constant
51
my $table1 = $dbi->table1;
52
my $table2 = $dbi->table2;
53
my $table2_alias = $dbi->table2_alias;
54
my $table3 = $dbi->table3;
55
my $key1 = $dbi->key1;
56
my $key2 = $dbi->key2;
57
my $key3 = $dbi->key3;
58
my $key4 = $dbi->key4;
59
my $key5 = $dbi->key5;
60
my $key6 = $dbi->key6;
61
my $key7 = $dbi->key7;
62
my $key8 = $dbi->key8;
63
my $key9 = $dbi->key9;
64
my $key10 = $dbi->key10;
65
my $create_table1 = $dbi->create_table1;
66
my $create_table1_2 = $dbi->create_table1_2;
67
my $create_table1_type = $dbi->create_table1_type;
68
my $create_table1_highperformance = $dbi->create_table1_highperformance;
69
my $create_table2 = $dbi->create_table2;
70
my $create_table2_2 = $dbi->create_table2_2;
71
my $create_table3 = $dbi->create_table3;
72
my $create_table_reserved = $dbi->create_table_reserved;
improved test
Yuki Kimoto authored on 2012-03-01
73
my ($q, $p) = $dbi->_qp;
cleanup test
Yuki Kimoto authored on 2011-08-15
74
my $date_typename = $dbi->date_typename;
75
my $datetime_typename = $dbi->datetime_typename;
76
my $date_datatype = $dbi->date_datatype;
77
my $datetime_datatype = $dbi->datetime_datatype;
improved test
Yuki Kimoto authored on 2012-03-01
78
my $setup_model_args = $dbi->can('setup_model_args') ? $dbi->setup_model_args : [];
cleanup test
Yuki Kimoto authored on 2011-08-15
79

            
80
# Variables
81
my $builder;
82
my $datas;
83
my $sth;
84
my $source;
85
my @sources;
86
my $select_source;
87
my $insert_source;
88
my $update_source;
89
my $param;
90
my $params;
91
my $sql;
92
my $result;
93
my $row;
94
my @rows;
95
my $rows;
96
my $query;
97
my @queries;
98
my $select_query;
99
my $insert_query;
100
my $update_query;
101
my $ret_val;
102
my $infos;
103
my $model;
104
my $model2;
105
my $where;
106
my $update_param;
107
my $insert_param;
108
my $join;
109
my $binary;
added test
Yuki Kimoto authored on 2011-08-16
110
my $user_table_info;
cleanup
Yuki Kimoto authored on 2011-08-16
111
my $user_column_info;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
112
my $values_clause;
113
my $assign_clause;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
114
my $reuse;
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
115
my $affected;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2012-01-25
116
my $dbi1;
117
my $dbi2;
118
my $dbi3;
119
my $dbi4;
120
my $dbi5;
121
my $pool;
cleanup test
Yuki Kimoto authored on 2011-08-15
122

            
test cleanup
Yuki Kimoto authored on 2011-08-15
123
require MyDBI1;
test cleanup
Yuki Kimoto authored on 2011-08-10
124
{
cleanup
Yuki Kimoto authored on 2012-01-20
125
  package MyDBI4;
test cleanup
Yuki Kimoto authored on 2011-08-10
126

            
cleanup
Yuki Kimoto authored on 2012-01-20
127
  use strict;
128
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
129

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
132
  sub connect {
133
    my $self = shift->SUPER::connect(@_);
134
    
135
    $self->include_model(
136
      MyModel2 => [
137
          $table1,
138
          {class => $table2, name => $table2}
139
      ]
140
    );
141
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
142

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
152
  use strict;
153
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
154

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
157
  sub insert {
158
    my ($self, $param) = @_;
159
    
160
    return $self->SUPER::insert($param);
161
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
162

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
167
  use strict;
168
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-15
169

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
172
  sub insert {
173
    my ($self, $param) = @_;
174
    
175
    return $self->SUPER::insert($param);
176
  }
test cleanup
Yuki Kimoto authored on 2011-08-15
177

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
182
  use strict;
183
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-15
184

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
187
  sub insert {
188
    my ($self, $param) = @_;
189
    
190
    return $self->SUPER::insert($param);
191
  }
test cleanup
Yuki Kimoto authored on 2011-08-15
192

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
197
  use strict;
198
  use warnings;
199

            
200
  use base 'MyModel2::Base1';
201

            
202
  sub insert {
203
    my ($self, $param) = @_;
204
    
205
    return $self->SUPER::insert($param);
206
  }
207

            
208
  sub list { shift->select; }
improved test
Yuki Kimoto authored on 2012-03-01
209

            
210

            
211
  package MyModel2::main::table1;
212

            
213
  use strict;
214
  use warnings;
215

            
216
  use base 'MyModel2::Base1';
217

            
218
  sub insert {
219
    my ($self, $param) = @_;
220
    
221
    return $self->SUPER::insert($param);
222
  }
223

            
224
  sub list { shift->select; }
225

            
226
  package MyModel2::main::table2;
227

            
228
  use strict;
229
  use warnings;
230

            
231
  use base 'MyModel2::Base1';
232

            
233
  sub insert {
234
    my ($self, $param) = @_;
235
    
236
    return $self->SUPER::insert($param);
237
  }
238

            
239
  sub list { shift->select; }
added t/common-mysql-qualifi...
Yuki Kimoto authored on 2012-03-02
240

            
241
  package MyModel2::dbix_custom::table1;
242

            
243
  use strict;
244
  use warnings;
245

            
246
  use base 'MyModel2::Base1';
247

            
248
  sub insert {
249
    my ($self, $param) = @_;
250
    
251
    return $self->SUPER::insert($param);
252
  }
253

            
254
  sub list { shift->select; }
255

            
256
  package MyModel2::dbix_custom::table2;
257

            
258
  use strict;
259
  use warnings;
260

            
261
  use base 'MyModel2::Base1';
262

            
263
  sub insert {
264
    my ($self, $param) = @_;
265
    
266
    return $self->SUPER::insert($param);
267
  }
268

            
269
  sub list { shift->select; }
test cleanup
Yuki Kimoto authored on 2011-08-10
270
}
added t/common-mysql-qualifi...
Yuki Kimoto authored on 2012-03-02
271

            
test cleanup
Yuki Kimoto authored on 2011-08-10
272
{
cleanup
Yuki Kimoto authored on 2012-01-20
273
   package MyDBI5;
test cleanup
Yuki Kimoto authored on 2011-08-10
274

            
cleanup
Yuki Kimoto authored on 2012-01-20
275
  use strict;
276
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
277

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
280
  sub connect {
281
    my $self = shift->SUPER::connect(@_);
282
    
283
    $self->include_model('MyModel4');
284
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
285
}
286
{
cleanup
Yuki Kimoto authored on 2012-01-20
287
  package MyDBI6;
288
  
289
  use base 'DBIx::Custom';
290
  
291
  sub connect {
292
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
293
    
cleanup
Yuki Kimoto authored on 2012-01-20
294
    $self->include_model('MyModel5');
test cleanup
Yuki Kimoto authored on 2011-08-10
295
    
cleanup
Yuki Kimoto authored on 2012-01-20
296
    return $self;
297
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
298
}
299
{
cleanup
Yuki Kimoto authored on 2012-01-20
300
  package MyDBI7;
301
  
302
  use base 'DBIx::Custom';
303
  
304
  sub connect {
305
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
306
    
cleanup
Yuki Kimoto authored on 2012-01-20
307
    $self->include_model('MyModel6');
test cleanup
Yuki Kimoto authored on 2011-08-10
308
    
cleanup
Yuki Kimoto authored on 2012-01-20
309
    
310
    return $self;
311
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
312
}
313
{
cleanup
Yuki Kimoto authored on 2012-01-20
314
  package MyDBI8;
315
  
316
  use base 'DBIx::Custom';
317
  
318
  sub connect {
319
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
320
    
cleanup
Yuki Kimoto authored on 2012-01-20
321
    $self->include_model('MyModel7');
test cleanup
Yuki Kimoto authored on 2011-08-10
322
    
cleanup
Yuki Kimoto authored on 2012-01-20
323
    return $self;
324
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
325
}
326

            
327
{
cleanup
Yuki Kimoto authored on 2012-01-20
328
  package MyDBI9;
329
  
330
  use base 'DBIx::Custom';
331
  
332
  sub connect {
333
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
334
    
cleanup
Yuki Kimoto authored on 2012-01-20
335
    $self->include_model('MyModel8');
test cleanup
Yuki Kimoto authored on 2011-08-10
336
    
cleanup
Yuki Kimoto authored on 2012-01-20
337
    return $self;
338
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
339
}
340

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
341
test 'execute reuse option';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
342
eval { $dbi->execute("drop table $table1") };
343
$dbi->execute($create_table1);
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
344
$reuse = {};
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
345
for my $i (1 .. 2) {
cleanup
Yuki Kimoto authored on 2012-01-20
346
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, reuse => $reuse);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
347
}
348
$rows = $dbi->select(table => $table1)->all;
349
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-11-18
350
ok(keys %$reuse);
351
ok((keys %$reuse)[0] !~ /\?/);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
352

            
added test
Yuki Kimoto authored on 2011-08-16
353
# Get user table info
354
$dbi = DBIx::Custom->connect;
355
eval { $dbi->execute("drop table $table1") };
356
eval { $dbi->execute("drop table $table2") };
357
eval { $dbi->execute("drop table $table3") };
358
$dbi->execute($create_table1);
359
$dbi->execute($create_table2);
360
$dbi->execute($create_table3);
361
$user_table_info = $dbi->get_table_info(exclude => $dbi->exclude_table);
362

            
cleanup test
Yuki Kimoto authored on 2011-08-15
363
# Create table
test cleanup
Yuki Kimoto authored on 2011-08-10
364
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
365
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
366
$dbi->execute($create_table1);
367
$model = $dbi->create_model(table => $table1);
368
$model->insert({$key1 => 1, $key2 => 2});
369
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-08-15
370

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
371
eval { $dbi->execute("drop table $table1") };
372
$dbi->execute($create_table1);
373
$model = $dbi->create_model(table => $table1);
374
$model->insert({$key1 => 1, $key2 => 2});
375
is_deeply($model->select($key1)->all, [{$key1 => 1}]);
376

            
cleanup test
Yuki Kimoto authored on 2011-08-15
377
test 'DBIx::Custom::Result test';
378
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
379
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
380
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
381
$source = "select $key1, $key2 from $table1";
382
$query = $dbi->create_query($source);
383
$result = $dbi->execute($query);
cleanup
Yuki Kimoto authored on 2011-08-15
384

            
cleanup test
Yuki Kimoto authored on 2011-08-15
385
@rows = ();
386
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
387
  push @rows, [@$row];
cleanup test
Yuki Kimoto authored on 2011-08-15
388
}
389
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
cleanup
Yuki Kimoto authored on 2011-08-15
390

            
cleanup test
Yuki Kimoto authored on 2011-08-15
391
$result = $dbi->execute($query);
392
@rows = ();
393
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
394
  push @rows, {%$row};
cleanup test
Yuki Kimoto authored on 2011-08-15
395
}
396
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
397

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
411
test 'Insert query return value';
412
$source = "insert into $table1 {insert_param $key1 $key2}";
413
$query = $dbi->execute($source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
414
$ret_val = $dbi->execute($query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
415
ok($ret_val);
test cleanup
Yuki Kimoto authored on 2011-08-10
416

            
cleanup test
Yuki Kimoto authored on 2011-08-15
417
test 'Direct query';
418
$dbi->delete_all(table => $table1);
419
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
test cleanup
Yuki Kimoto authored on 2011-11-01
420
$dbi->execute($insert_source, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
421
$result = $dbi->execute("select * from $table1");
422
$rows = $result->all;
423
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
424

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
430
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
431
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
432
$insert_query->filter({$key1 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
433
$dbi->execute($insert_query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
434
$result = $dbi->execute("select * from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
435
$rows = $result->filter({$key2 => 'three_times'})->all;
436
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
437

            
438
test 'Filter in';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
439
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
440
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
441
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
442
$dbi->execute($insert_query, {$key1 => 2, $key2 => 4});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
443
$select_source = "select * from $table1 where {in $table1.$key1 2} and {in $table1.$key2 2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
444
$select_query = $dbi->execute($select_source,{}, query => 1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
445
$select_query->filter({"$table1.$key1" => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
446
$result = $dbi->execute($select_query, {"$table1.$key1" => [1,5], "$table1.$key2" => [2,4]});
cleanup test
Yuki Kimoto authored on 2011-08-08
447
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
448
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
449

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
530
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
531
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
532
  $source,
533
  {"$table1.$key1" => 1, "$table1.$key2" => 1},
534
  filter => {"$table1.$key2" => sub { $_[0] * 2 }}
cleanup test
Yuki Kimoto authored on 2011-08-08
535
);
536
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
537
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
538

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
539
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
540
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
541
$dbi->insert({$key1 => '2011-10-14 12:19:18', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
542
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
543
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
544
  $source,
545
  {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
546
);
547

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
552
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
553
$dbi->insert({$key1 => 'a:b c:d', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
554
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
555
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
556
  $source,
557
  {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
558
);
559
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
560
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
561

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
569
test 'insert';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
570
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
571
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
572
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
573
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
574
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
575
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
576
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
577

            
added tests
Yuki Kimoto authored on 2011-11-01
578
eval { $dbi->execute("drop table $table1") };
579
$dbi->execute($create_table1);
580
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
581
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
582
$result = $dbi->execute("select * from $table1");
583
$rows   = $result->all;
584
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
585

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
586
$dbi->execute("delete from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
587
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
588
  twice       => sub { $_[0] * 2 },
589
  three_times => sub { $_[0] * 3 }
cleanup test
Yuki Kimoto authored on 2011-08-10
590
);
591
$dbi->default_bind_filter('twice');
test cleanup
Yuki Kimoto authored on 2011-11-01
592
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
cleanup test
Yuki Kimoto authored on 2011-08-15
593
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
594
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
595
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
596
$dbi->delete_all(table => $table1);
597
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
598
$result = $dbi->execute("select * from $table1");
599
$rows   = $result->all;
600
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-10
601
$dbi->default_bind_filter(undef);
602

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
613
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
614
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
615
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
test cleanup
Yuki Kimoto authored on 2011-11-01
616
$dbi->insert({select => 1}, table => 'table');
cleanup test
Yuki Kimoto authored on 2011-08-10
617
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
618
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
619
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
cleanup test
Yuki Kimoto authored on 2011-08-10
620

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
621
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
622
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
623
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
624
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
625
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
626
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
627
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
628

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
629
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
630
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
631
$dbi->insert({$key1 => \"'1'", $key2 => 2}, table => $table1);
632
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
633
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
634
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
635
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
636

            
updated pod
Yuki Kimoto authored on 2011-09-02
637
eval { $dbi->execute("drop table $table1") };
638
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
639
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
640
wrap => {$key1 => sub { "$_[0] - 1" }});
test cleanup
Yuki Kimoto authored on 2011-11-01
641
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
updated pod
Yuki Kimoto authored on 2011-09-02
642
$result = $dbi->execute("select * from $table1");
643
$rows   = $result->all;
644
is_deeply($rows, [{$key1 => 0, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
645

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
646
eval { $dbi->execute("drop table $table1") };
647
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
648
$dbi->insert_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
649
  $key1 => '5'
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
650
);
test cleanup
Yuki Kimoto authored on 2011-11-01
651
$dbi->insert({$key2 => 2}, table => $table1, timestamp => 1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
652
$result = $dbi->execute("select * from $table1");
653
$rows   = $result->all;
654
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
655

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
656
eval { $dbi->execute("drop table $table1") };
657
$dbi->execute($create_table1);
658
$dbi->insert_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
659
  [$key1, $key2] => sub { 5 }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
660
);
661
$dbi->insert(table => $table1, timestamp => 1);
662
$result = $dbi->execute("select * from $table1");
663
$rows   = $result->all;
664
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
665

            
666
eval { $dbi->execute("drop table $table1") };
667
$dbi->execute($create_table1);
668
$dbi->insert_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
669
  [$key1, $key2] => sub { "" . DBIx::Custom->new }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
670
);
671
$dbi->insert(table => $table1, timestamp => 1);
672
$result = $dbi->execute("select * from $table1");
673
$rows   = $result->all;
674
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
675

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
676
eval { $dbi->execute("drop table $table1") };
677
$dbi->execute($create_table1_2);
678
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
679
$dbi->insert($param, table => $table1, created_at => $key2);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
680
$result = $dbi->select(table => $table1);
681
is_deeply($param, {$key1 => 1});
682
$row   = $result->one;
683
is($row->{$key1}, 1);
684
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
685

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
686
eval { $dbi->execute("drop table $table1") };
687
$dbi->execute($create_table1_2);
688
$param = {$key1 => 1};
689
$dbi->insert($param, table => $table1, ctime => $key2);
690
$result = $dbi->select(table => $table1);
691
is_deeply($param, {$key1 => 1});
692
$row   = $result->one;
693
is($row->{$key1}, 1);
694
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
695

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
696
eval { $dbi->execute("drop table $table1") };
697
$dbi->execute($create_table1_2);
698
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
699
$dbi->insert($param, table => $table1, updated_at => $key3);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
700
$result = $dbi->select(table => $table1);
701
is_deeply($param, {$key1 => 1});
702
$row   = $result->one;
703
is($row->{$key1}, 1);
704
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
705

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
706
eval { $dbi->execute("drop table $table1") };
707
$dbi->execute($create_table1_2);
708
$param = {$key1 => 1};
709
$dbi->insert($param, table => $table1, mtime => $key3);
710
$result = $dbi->select(table => $table1);
711
is_deeply($param, {$key1 => 1});
712
$row   = $result->one;
713
is($row->{$key1}, 1);
714
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
715

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
716
eval { $dbi->execute("drop table $table1") };
717
$dbi->execute($create_table1_2);
718
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
719
$dbi->insert($param, table => $table1, created_at => $key2, updated_at => $key3);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
720
$result = $dbi->select(table => $table1);
721
is_deeply($param, {$key1 => 1});
722
$row   = $result->one;
723
is($row->{$key1}, 1);
724
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
725
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
726
is($row->{$key2}, $row->{$key3});
727

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
728
eval { $dbi->execute("drop table $table1") };
729
$dbi->execute($create_table1_2);
730
$param = {$key1 => 1};
731
$dbi->insert($param, table => $table1, created_at => $key2, mtime => $key3);
732
$result = $dbi->select(table => $table1);
733
is_deeply($param, {$key1 => 1});
734
$row   = $result->one;
735
is($row->{$key1}, 1);
736
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
737
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
738
is($row->{$key2}, $row->{$key3});
739

            
740
eval { $dbi->execute("drop table $table1") };
741
$dbi->execute($create_table1_2);
742
$param = {$key1 => 1};
743
$dbi->insert($param, table => $table1, ctime => $key2, updated_at => $key3);
744
$result = $dbi->select(table => $table1);
745
is_deeply($param, {$key1 => 1});
746
$row   = $result->one;
747
is($row->{$key1}, 1);
748
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
749
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
750
is($row->{$key2}, $row->{$key3});
751

            
752
eval { $dbi->execute("drop table $table1") };
753
$dbi->execute($create_table1_2);
754
$param = {$key1 => 1};
755
$dbi->insert($param, table => $table1, ctime => $key2, mtime => $key3);
756
$result = $dbi->select(table => $table1);
757
is_deeply($param, {$key1 => 1});
758
$row   = $result->one;
759
is($row->{$key1}, 1);
760
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
761
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
762
is($row->{$key2}, $row->{$key3});
763

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
764
eval { $dbi->execute("drop table $table1") };
765
$dbi->execute($create_table1_2);
766
$model = $dbi->create_model(table => $table1, created_at => $key2);
767
$param = {$key1 => 1};
768
$model->insert($param);
769
$result = $dbi->select(table => $table1);
770
is_deeply($param, {$key1 => 1});
771
$row   = $result->one;
772
is($row->{$key1}, 1);
773
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
774

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
775
eval { $dbi->execute("drop table $table1") };
776
$dbi->execute($create_table1_2);
777
$model = $dbi->create_model(table => $table1, ctime => $key2);
778
$param = {$key1 => 1};
779
$model->insert($param);
780
$result = $dbi->select(table => $table1);
781
is_deeply($param, {$key1 => 1});
782
$row   = $result->one;
783
is($row->{$key1}, 1);
784
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
785

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
786
eval { $dbi->execute("drop table $table1") };
787
$dbi->execute($create_table1_2);
788
$param = {$key1 => 1};
789
$model = $dbi->create_model(table => $table1, updated_at => $key3);
790
$model->insert($param);
791
$result = $dbi->select(table => $table1);
792
is_deeply($param, {$key1 => 1});
793
$row   = $result->one;
794
is($row->{$key1}, 1);
795
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
796

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
797
eval { $dbi->execute("drop table $table1") };
798
$dbi->execute($create_table1_2);
799
$param = {$key1 => 1};
800
$model = $dbi->create_model(table => $table1, mtime => $key3);
801
$model->insert($param);
802
$result = $dbi->select(table => $table1);
803
is_deeply($param, {$key1 => 1});
804
$row   = $result->one;
805
is($row->{$key1}, 1);
806
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
807

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
808
eval { $dbi->execute("drop table $table1") };
809
$dbi->execute($create_table1_2);
810
$param = {$key1 => 1};
811
$model = $dbi->create_model(table => $table1, created_at => $key2, updated_at => $key3);
812
$model->insert($param);
813
$result = $dbi->select(table => $table1);
814
is_deeply($param, {$key1 => 1});
815
$row   = $result->one;
816
is($row->{$key1}, 1);
817
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
818
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
819
is($row->{$key2}, $row->{$key3});
820

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
821
eval { $dbi->execute("drop table $table1") };
822
$dbi->execute($create_table1_2);
823
$param = {$key1 => 1};
824
$model = $dbi->create_model(table => $table1, created_at => $key2, mtime => $key3);
825
$model->insert($param);
826
$result = $dbi->select(table => $table1);
827
is_deeply($param, {$key1 => 1});
828
$row   = $result->one;
829
is($row->{$key1}, 1);
830
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
831
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
832
is($row->{$key2}, $row->{$key3});
833

            
834
eval { $dbi->execute("drop table $table1") };
835
$dbi->execute($create_table1_2);
836
$param = {$key1 => 1};
837
$model = $dbi->create_model(table => $table1, ctime=> $key2, updated_at => $key3);
838
$model->insert($param);
839
$result = $dbi->select(table => $table1);
840
is_deeply($param, {$key1 => 1});
841
$row   = $result->one;
842
is($row->{$key1}, 1);
843
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
844
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
845
is($row->{$key2}, $row->{$key3});
846

            
847
eval { $dbi->execute("drop table $table1") };
848
$dbi->execute($create_table1_2);
849
$param = {$key1 => 1};
850
$model = $dbi->create_model(table => $table1, ctime=> $key2, mtime => $key3);
851
$model->insert($param);
852
$result = $dbi->select(table => $table1);
853
is_deeply($param, {$key1 => 1});
854
$row   = $result->one;
855
is($row->{$key1}, 1);
856
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
857
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
858
is($row->{$key2}, $row->{$key3});
859

            
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
860
eval { $dbi->execute("drop table $table1") };
861
$dbi->execute($create_table1);
862
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] , table => $table1);
863
$result = $dbi->execute("select * from $table1");
864
$rows   = $result->all;
865
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
866

            
867
eval { $dbi->execute("drop table $table1") };
868
$dbi->execute($create_table1_2);
869
$dbi->insert([{$key1 => 1}, {$key1 => 3}] ,
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
870
  table => $table1,
871
  updated_at => $key2,
872
  created_at => $key3
873
);
874
$result = $dbi->execute("select * from $table1");
875
$rows   = $result->all;
876
is($rows->[0]->{$key1}, 1);
877
is($rows->[1]->{$key1}, 3);
878
like($rows->[0]->{$key2}, qr/\d{2}:/);
879
like($rows->[1]->{$key2}, qr/\d{2}:/);
880
like($rows->[0]->{$key3}, qr/\d{2}:/);
881
like($rows->[1]->{$key3}, qr/\d{2}:/);
882

            
883
eval { $dbi->execute("drop table $table1") };
884
$dbi->execute($create_table1_2);
885
$dbi->insert([{$key1 => 1}, {$key1 => 3}] ,
886
  table => $table1,
887
  mtime => $key2,
888
  ctime => $key3
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
889
);
890
$result = $dbi->execute("select * from $table1");
891
$rows   = $result->all;
892
is($rows->[0]->{$key1}, 1);
893
is($rows->[1]->{$key1}, 3);
894
like($rows->[0]->{$key2}, qr/\d{2}:/);
895
like($rows->[1]->{$key2}, qr/\d{2}:/);
896
like($rows->[0]->{$key3}, qr/\d{2}:/);
897
like($rows->[1]->{$key3}, qr/\d{2}:/);
898

            
899
eval { $dbi->execute("drop table $table1") };
900
$dbi->execute($create_table1);
901
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] ,
cleanup
Yuki Kimoto authored on 2012-01-20
902
table => $table1, filter => {$key1 => sub { $_[0] * 2 }});
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
903
$result = $dbi->execute("select * from $table1");
904
$rows   = $result->all;
905
is_deeply($rows, [{$key1 => 2, $key2 => 2}, {$key1 => 6, $key2 => 4}], "basic");
906

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
907
test 'update_or_insert';
908
eval { $dbi->execute("drop table $table1") };
909
$dbi->execute($create_table1);
910
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
911
  {$key2 => 2},
912
  table => $table1,
913
  primary_key => $key1,
914
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
915
);
916
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
917
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
918

            
919
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
920
  {$key2 => 3},
921
  table => $table1,
922
  primary_key => $key1,
923
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
924
);
925
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
926
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
927

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
928
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
929
  $dbi->update_or_insert(
930
    {$key2 => 3},
931
    table => $table1,
932
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
933
};
934

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
937
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
938
  $dbi->insert({$key1 => 1}, table => $table1);
939
  $dbi->update_or_insert(
940
    {$key2 => 3},
941
    table => $table1,
942
    primary_key => $key1,
943
    id => 1
944
  );
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
945
};
946
like($@, qr/one/);
947

            
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
948
eval { $dbi->execute("drop table $table1") };
949
$dbi->execute($create_table1);
950
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
951
  {},
952
  table => $table1,
953
  primary_key => $key1,
954
  id => 1
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
955
);
956
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
957
is($row->{$key1}, 1);
958

            
959
eval { 
cleanup
Yuki Kimoto authored on 2012-01-20
960
  $affected = $dbi->update_or_insert(
961
    {},
962
    table => $table1,
963
    primary_key => $key1,
964
    id => 1
965
  );
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
966
};
967
is($affected, 0);
968

            
micro optimization
Yuki Kimoto authored on 2011-10-31
969
test 'model update_or_insert';
970
eval { $dbi->execute("drop table $table1") };
971
$dbi->execute($create_table1);
972
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
973
  table => $table1,
974
  primary_key => $key1
micro optimization
Yuki Kimoto authored on 2011-10-31
975
);
976
$model->update_or_insert({$key2 => 2}, id => 1);
977
$row = $model->select(id => 1)->one;
978
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
979

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
980
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
981
  $model->insert({$key1 => 1});
982
  $model->update_or_insert(
983
    {$key2 => 3},
984
    id => 1
985
  );
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
986
};
987
like($@, qr/one/);
988

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
989
test 'default_bind_filter';
990
$dbi->execute("delete from $table1");
991
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
992
  twice       => sub { $_[0] * 2 },
993
  three_times => sub { $_[0] * 3 }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
994
);
995
$dbi->default_bind_filter('twice');
cleanup
Yuki Kimoto authored on 2011-11-01
996
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
997
$result = $dbi->execute("select * from $table1");
998
$rows   = $result->all;
999
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
1000
$dbi->default_bind_filter(undef);
1001

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1002
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1003
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1004
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1005
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1006
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1007
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1008
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1009
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1010
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1011
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1012
  "basic");
added tests
Yuki Kimoto authored on 2011-11-01
1013

            
1014
eval { $dbi->execute("drop table $table1") };
1015
$dbi->execute($create_table1_2);
1016
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1017
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
1018
$dbi->update(param => {$key2 => 11}, table => $table1, where => {$key1 => 1});
1019
$result = $dbi->execute("select * from $table1 order by $key1");
1020
$rows   = $result->all;
1021
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1022
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1023
  "basic");
1024
                
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1025
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
1026
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1027
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1028
$dbi->update({$key2 => 12}, table => $table1, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
1029
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1030
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1031
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1032
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1033
  "update key same as search key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1034

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1042
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
1043
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1044
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1045
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
1046
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
1047
            filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
1048
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1049
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1050
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1051
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1052
  "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1053

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1056
eval{$dbi->update(table => $table1)};
test cleanup
Yuki Kimoto authored on 2011-08-10
1057
like($@, qr/where/, "not contain where");
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);
test cleanup
Yuki Kimoto authored on 2011-08-10
1062
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1063
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1064
$where->param({$key1 => 1, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
1065
$dbi->update({$key1 => 3}, table => $table1, where => $where);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1066
$result = $dbi->select(table => $table1);
1067
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1068

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

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1099
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1100
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1101
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1102
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
1103
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
1104
$dbi->insert({select => 1}, table => 'table');
1105
$dbi->update({update => 2}, table => 'table', where => {select => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1106
$result = $dbi->execute("select * from ${q}table$p");
1107
$rows   = $result->all;
1108
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
1109

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

            
1113
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1114
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1115
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
1116
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
1117
$dbi->insert({select => 1}, table => 'table');
1118
$dbi->update({update => 2}, table => 'table', where => {'table.select' => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1119
$result = $dbi->execute("select * from ${q}table$p");
1120
$rows   = $result->all;
1121
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
1122

            
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_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1125
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1126
$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
1127
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1128
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1129
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1130
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1131
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1132
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1133

            
updated pod
Yuki Kimoto authored on 2011-09-02
1134
eval { $dbi->execute("drop table $table1") };
1135
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1136
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1137
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1138
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
updated pod
Yuki Kimoto authored on 2011-09-02
1139
wrap => {$key2 => sub { "$_[0] - 1" }});
1140
$result = $dbi->execute("select * from $table1 order by $key1");
1141
$rows   = $result->all;
1142
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1143
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1144
  "basic");
updated pod
Yuki Kimoto authored on 2011-09-02
1145

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1146
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1147
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1148
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1149
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1150
$dbi->update({$key2 => \"'11'"}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1151
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1152
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1153
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1154
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1155
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1156

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1157
eval { $dbi->execute("drop table $table1") };
1158
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1159
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
1160
  $key1 => '5'
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1161
);
test cleanup
Yuki Kimoto authored on 2011-11-01
1162
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1163
$dbi->update(table => $table1, timestamp => 1, where => {$key2 => 2});
1164
$result = $dbi->execute("select * from $table1");
1165
$rows   = $result->all;
1166
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
1167

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1168
eval { $dbi->execute("drop table $table1") };
1169
$dbi->execute($create_table1);
1170
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
1171
  [$key1, $key2] => sub { '5' }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1172
);
test cleanup
Yuki Kimoto authored on 2011-11-01
1173
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1174
$dbi->update_all(table => $table1, timestamp => 1);
1175
$result = $dbi->execute("select * from $table1");
1176
$rows   = $result->all;
1177
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
1178

            
1179
eval { $dbi->execute("drop table $table1") };
1180
$dbi->execute($create_table1);
1181
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
1182
  [$key1, $key2] => sub { "" . DBIx::Custom->new }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1183
);
test cleanup
Yuki Kimoto authored on 2011-11-01
1184
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1185
$dbi->update_all(table => $table1, timestamp => 1);
1186
$result = $dbi->execute("select * from $table1");
1187
$rows   = $result->all;
1188
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
1189

            
micro optimization and
Yuki Kimoto authored on 2011-10-25
1190
eval { $dbi->execute("drop table $table1") };
1191
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1192
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1193
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
1194
$param = {$key2 => 11};
1195
$dbi->update($param, table => $table1, where => {$key1 => 1});
1196
is_deeply($param, {$key2 => 11});
1197
$result = $dbi->execute("select * from $table1 order by $key1");
1198
$rows   = $result->all;
1199
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1200
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1201
  "basic");
micro optimization and
Yuki Kimoto authored on 2011-10-25
1202

            
1203
eval { $dbi->execute("drop table $table1") };
1204
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1205
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1206
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
1207
$param = {$key2 => 11};
1208
$dbi->update($param, table => $table1, where => {$key2 => 2});
1209
is_deeply($param, {$key2 => 11});
1210
$result = $dbi->execute("select * from $table1 order by $key1");
1211
$rows   = $result->all;
1212
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1213
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1214
  "basic");
micro optimization and
Yuki Kimoto authored on 2011-10-25
1215

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1216
eval { $dbi->execute("drop table $table1") };
1217
$dbi->execute($create_table1_2);
1218
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1219
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1220
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key1 => 1});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1221
$result = $dbi->select(table => $table1);
1222
is_deeply($param, {$key3 => 4});
1223
$row   = $result->one;
1224
is($row->{$key3}, 4);
1225
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1226

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1227
eval { $dbi->execute("drop table $table1") };
1228
$dbi->execute($create_table1_2);
1229
$param = {$key3 => 4};
1230
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1231
$dbi->update($param, table => $table1, mtime => $key2, where => {$key1 => 1});
1232
$result = $dbi->select(table => $table1);
1233
is_deeply($param, {$key3 => 4});
1234
$row   = $result->one;
1235
is($row->{$key3}, 4);
1236
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1237

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1238
eval { $dbi->execute("drop table $table1") };
1239
$dbi->execute($create_table1_2);
1240
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1241
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1242
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key3 => 3});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1243
$result = $dbi->select(table => $table1);
1244
is_deeply($param, {$key3 => 4});
1245
$row   = $result->one;
1246
is($row->{$key3}, 4);
1247
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1248

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1249
eval { $dbi->execute("drop table $table1") };
1250
$dbi->execute($create_table1_2);
1251
$param = {$key3 => 4};
1252
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1253
$dbi->update($param, table => $table1, mtime => $key2, where => {$key3 => 3});
1254
$result = $dbi->select(table => $table1);
1255
is_deeply($param, {$key3 => 4});
1256
$row   = $result->one;
1257
is($row->{$key3}, 4);
1258
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1259

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
1260
eval { $dbi->execute("drop table $table1") };
1261
$dbi->execute($create_table1_2);
1262
$model = $dbi->create_model(table => $table1, updated_at => $key2);
1263
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1264
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
1265
$model->update($param, where => {$key1 => 1});
1266
$result = $dbi->select(table => $table1);
1267
is_deeply($param, {$key3 => 4});
1268
$row   = $result->one;
1269
is($row->{$key3}, 4);
1270
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1271

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1272
eval { $dbi->execute("drop table $table1") };
1273
$dbi->execute($create_table1_2);
1274
$model = $dbi->create_model(table => $table1, mtime => $key2);
1275
$param = {$key3 => 4};
1276
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1277
$model->update($param, where => {$key1 => 1});
1278
$result = $dbi->select(table => $table1);
1279
is_deeply($param, {$key3 => 4});
1280
$row   = $result->one;
1281
is($row->{$key3}, 4);
1282
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1283

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1284
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1285
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1286
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1287
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1288
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1289
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
1290
$dbi->update_all({$key2 => 10}, table => $table1, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1291
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1292
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1293
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1294
  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
1295
  "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1296

            
1297
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1298
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1299
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1300
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1301
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1302
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1303
$result = $dbi->execute("select * from $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 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1306

            
cleanup test
Yuki Kimoto authored on 2011-08-15
1307
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
1308
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1309
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1310
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1311
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1312
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1313
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1314
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1315

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1318
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1319
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1320
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1321
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
1322
$rows = $dbi->select(table => $table1)->all;
1323
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1324

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1325
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1326
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1327
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1328
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1329
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1330
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1331
$where->param({ke1 => 1, $key2 => 2});
1332
$dbi->delete(table => $table1, where => $where);
1333
$result = $dbi->select(table => $table1);
1334
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1335

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1336
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1337
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1338
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1339
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1340
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
1341
  table => $table1,
1342
  where => [
1343
    ['and', "$key1 = :$key1", "$key2 = :$key2"],
1344
    {ke1 => 1, $key2 => 2}
1345
  ]
test cleanup
Yuki Kimoto authored on 2011-08-10
1346
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1347
$result = $dbi->select(table => $table1);
1348
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1349

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1350
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1351
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1352
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1353
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
1354
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1355
$rows   = $result->all;
1356
is_deeply($rows, [], "basic");
1357

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1367
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
1368
$dbi = DBIx::Custom->connect;
1369
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1370
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1371
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1372
$dbi->insert({select => 1}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1373
$dbi->delete(table => 'table', where => {select => 1});
1374
$result = $dbi->execute("select * from ${q}table$p");
1375
$rows   = $result->all;
1376
is_deeply($rows, [], "reserved word");
1377

            
1378
test 'delete_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1379
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1380
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1381
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1382
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1383
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1384
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1385
$rows   = $result->all;
1386
is_deeply($rows, [], "basic");
1387

            
1388
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1389
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1390
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1391
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1392
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1393
$rows = $dbi->select(table => $table1)->all;
1394
is_deeply($rows, [{$key1 => 1, $key2 => 2},
cleanup
Yuki Kimoto authored on 2012-01-20
1395
  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
1396

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1411
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1412
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
1413
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1414
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1415
  table => [$table1, $table2],
fixed test
Yuki Kimoto authored on 2012-03-01
1416
  column => "$table1.$key1 as " . u("${table1}_$key1")
1417
    . ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
1418
  where   => {"$table1.$key2" => 2},
1419
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1420
)->all;
fixed test
Yuki Kimoto authored on 2012-03-01
1421
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], "relation : exists where");
test cleanup
Yuki Kimoto authored on 2011-08-10
1422

            
1423
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1424
  table => [$table1, $table2],
fixed test
Yuki Kimoto authored on 2012-03-01
1425
  column => ["$table1.$key1 as " . u("${table1}_$key1") . ", ${table2}.$key1 as " . u("${table2}_$key1"), $key2, $key3],
cleanup
Yuki Kimoto authored on 2012-01-20
1426
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1427
)->all;
fixed test
Yuki Kimoto authored on 2012-03-01
1428
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], "relation : no exists where");
test cleanup
Yuki Kimoto authored on 2011-08-10
1429

            
1430
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
1431
eval { $dbi->execute("drop table ${q}table$p") };
1432
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1433
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1434
$dbi->insert({select => 1, update => 2}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1435
$result = $dbi->select(table => 'table', where => {select => 1});
1436
$rows   = $result->all;
1437
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
1438

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
1439
eval { $dbi->execute("drop table $table1") };
1440
$dbi->execute($create_table1);
1441
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1442
$row = $dbi->select($key1, table => $table1)->one;
1443
is_deeply($row, {$key1 => 1});
1444

            
added tests
Yuki Kimoto authored on 2012-02-28
1445
eval { $dbi->select(table => $table1, where => {';' => 1}) };
1446
like($@, qr/safety/);
1447

            
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
1448
eval { $dbi->execute("drop table $table1") };
1449
$dbi->execute($create_table1);
1450
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1451
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
1452
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
1453

            
1454
$rows = $dbi->select(table => $table1, where => {$key1 => [1, 5]})->all;
1455
is_deeply($rows, [
1456
  {$key1 => 1, $key2 => 2},
1457
  {$key1 => 5, $key2 => 6}
1458
], "table");
1459

            
1460
$rows = $dbi->select(table => $table1, where => {$key1 => []})->all;
1461
is_deeply($rows, [], "table");
1462

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1463
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1464
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1465
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1466
  twice       => sub { $_[0] * 2 },
1467
  three_times => sub { $_[0] * 3 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1468
);
1469
$dbi->default_fetch_filter('twice');
1470
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1471
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1472
$result = $dbi->select(table => $table1);
1473
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1474
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1475
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1476

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1477
$dbi->default_fetch_filter('twice');
1478
eval { $dbi->execute("drop table $table1") };
1479
$dbi->execute($create_table1);
1480
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1481
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1482
$result->filter({$key1 => 'three_times'});
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1483
$row = $result->fetch_one;
1484
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter");
1485

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1492
test 'filters';
1493
$dbi = DBIx::Custom->new;
1494

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1501
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1502
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1503
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1504
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1505
$dbi->begin_work;
1506
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1507
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1508
$dbi->rollback;
1509
$dbi->dbh->{AutoCommit} = 1;
1510

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

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

            
1515
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1516
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1517
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1518
$dbi->begin_work;
1519
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1520
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1521
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1522
$dbi->commit;
1523
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1524
$result = $dbi->select(table => $table1);
1525
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
cleanup
Yuki Kimoto authored on 2012-01-20
1526
  "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1527

            
1528
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1529
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1530
$dbi->execute($create_table1);
1531
{
cleanup
Yuki Kimoto authored on 2012-01-20
1532
  local $Carp::Verbose = 0;
1533
  eval{$dbi->execute("select * frm $table1")};
1534
  like($@, qr/\Qselect * frm $table1/, "fail prepare");
1535
  like($@, qr/\.t /, "fail : not verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1536
}
1537
{
cleanup
Yuki Kimoto authored on 2012-01-20
1538
  local $Carp::Verbose = 1;
1539
  eval{$dbi->execute("select * frm $table1")};
1540
  like($@, qr/Custom.*\.t /s, "fail : verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1541
}
1542

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

            
1548
{
cleanup
Yuki Kimoto authored on 2012-01-20
1549
  local $Carp::Verbose = 0;
1550
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1551
  like($@, qr/\Q.t /, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1552
}
1553
{
cleanup
Yuki Kimoto authored on 2012-01-20
1554
  local $Carp::Verbose = 1;
1555
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1556
  like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1557
}
1558

            
1559

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1560
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1561
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1562
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1563
$dbi->execute($create_table1);
1564

            
1565
$dbi->begin_work;
1566

            
1567
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1568
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1569
  die "Error";
1570
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1571
};
1572

            
1573
$dbi->rollback if $@;
1574

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

            
1579
$dbi->begin_work;
1580

            
1581
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1582
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1583
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1584
};
1585

            
1586
$dbi->commit unless $@;
1587

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

            
1592
$dbi->dbh->{AutoCommit} = 0;
1593
eval{ $dbi->begin_work };
1594
ok($@, "exception");
1595
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1596

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1597
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1598
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1599
$dbi->cache(1);
1600
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1601
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1602
$dbi->execute($source, {}, query => 1);
1603
is_deeply($dbi->{_cached}->{$source}, 
cleanup
Yuki Kimoto authored on 2012-01-20
1604
  {sql => " select * from $table1 where $key1 = ?  and $key2 = ? ", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1605

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1606
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1607
$dbi->execute($create_table1);
1608
$dbi->{_cached} = {};
1609
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1610
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1611
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1612

            
1613
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1614
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1615
$dbi->execute($create_table1);
1616
{
cleanup
Yuki Kimoto authored on 2012-01-20
1617
  local $Carp::Verbose = 0;
1618
  eval{$dbi->execute("select * frm $table1")};
1619
  like($@, qr/\Qselect * frm $table1/, "fail prepare");
1620
  like($@, qr/\.t /, "fail : not verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1621
}
1622
{
cleanup
Yuki Kimoto authored on 2012-01-20
1623
  local $Carp::Verbose = 1;
1624
  eval{$dbi->execute("select * frm $table1")};
1625
  like($@, qr/Custom.*\.t /s, "fail : verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1626
}
1627

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

            
1633
{
cleanup
Yuki Kimoto authored on 2012-01-20
1634
  local $Carp::Verbose = 0;
1635
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1636
  like($@, qr/\Q.t /, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1637
}
1638
{
cleanup
Yuki Kimoto authored on 2012-01-20
1639
  local $Carp::Verbose = 1;
1640
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1641
  like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1642
}
1643

            
1644
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1645
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1646
  one => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1647
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1648
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1649
  two => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1650
);
1651
$dbi->method({
cleanup
Yuki Kimoto authored on 2012-01-20
1652
  twice => sub {
1653
    my $self = shift;
1654
    return $_[0] * 2;
1655
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
1656
});
1657

            
1658
is($dbi->one, 1, "first");
1659
is($dbi->two, 2, "second");
1660
is($dbi->twice(5), 10 , "second");
1661

            
1662
eval {$dbi->XXXXXX};
1663
ok($@, "not exists");
1664

            
1665
test 'out filter';
1666
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1667
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1668
$dbi->execute($create_table1);
1669
$dbi->register_filter(twice => sub { $_[0] * 2 });
1670
$dbi->register_filter(three_times => sub { $_[0] * 3});
1671
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1672
  $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1673
            $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
1674
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1675
$result = $dbi->execute("select * from $table1");
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1676
$row   = $result->fetch_hash_one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1677
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1678
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1679
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1680
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1681

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1687
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1688
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1689
$dbi->execute($create_table1);
1690
$dbi->register_filter(twice => sub { $_[0] * 2 });
1691
$dbi->register_filter(three_times => sub { $_[0] * 3});
1692
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1693
  $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1694
            $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1695
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1696
  $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1697
); 
test cleanup
Yuki Kimoto authored on 2011-11-01
1698
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1699
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1700
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1701
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1702

            
1703
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1704
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1705
$dbi->execute($create_table1);
1706
$dbi->register_filter(twice => sub { $_[0] * 2 });
1707
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1708
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1709
);
cleanup
Yuki Kimoto authored on 2011-11-01
1710
$dbi->insert({$key1 => 1, $key2 => 2},table => $table1, filter => {$key1 => undef});
1711
$dbi->update({$key1 => 2}, table => $table1, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1712
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1713
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1714
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
test cleanup
Yuki Kimoto authored on 2011-08-10
1715

            
1716
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1717
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1718
$dbi->execute($create_table1);
1719
$dbi->register_filter(twice => sub { $_[0] * 2 });
1720
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1721
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1722
);
cleanup
Yuki Kimoto authored on 2011-11-01
1723
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1=> undef});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1724
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1725
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1726
$rows   = $result->all;
1727
is_deeply($rows, [], "delete");
1728

            
1729
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1730
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1731
$dbi->execute($create_table1);
1732
$dbi->register_filter(twice => sub { $_[0] * 2 });
1733
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1734
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1735
);
cleanup
Yuki Kimoto authored on 2011-11-01
1736
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1737
$result = $dbi->select(table => $table1, where => {$key1 => 1});
1738
$result->filter({$key2 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1739
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1740
is_deeply($rows, [{$key1 => 4, $key2 => 4}], "select");
test cleanup
Yuki Kimoto authored on 2011-08-10
1741

            
1742
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1743
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1744
$dbi->execute($create_table1);
1745
$dbi->register_filter(twice => sub { $_[0] * 2 });
1746
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1747
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1748
);
cleanup
Yuki Kimoto authored on 2011-11-01
1749
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1750
$result = $dbi->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2",
cleanup
Yuki Kimoto authored on 2012-01-20
1751
  {$key1 => 1, $key2 => 2},
1752
  table => [$table1]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1753
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1754
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute");
test cleanup
Yuki Kimoto authored on 2011-08-10
1755

            
1756
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1757
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1758
$dbi->execute($create_table1);
1759
$dbi->register_filter(twice => sub { $_[0] * 2 });
1760
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1761
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1762
);
cleanup
Yuki Kimoto authored on 2011-11-01
1763
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1764
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
cleanup
Yuki Kimoto authored on 2012-01-20
1765
  {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1766
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1767
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1768

            
1769
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1770
eval { $dbi->execute("drop table $table1") };
1771
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1772
$dbi->execute($create_table1);
1773
$dbi->execute($create_table2);
1774
$dbi->register_filter(twice => sub { $_[0] * 2 });
1775
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1776
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1777
  $table1, $key2 => {out => 'twice', in => 'twice'}
cleanup test
Yuki Kimoto authored on 2011-08-15
1778
);
1779
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1780
  $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1781
);
cleanup
Yuki Kimoto authored on 2011-11-01
1782
$dbi->insert({$key1 => 5, $key2 => 2}, table => $table1, filter => {$key2 => undef});
1783
$dbi->insert({$key1 => 5, $key3 => 6}, table => $table2, filter => {$key3 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1784
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1785
  table => [$table1, $table2],
1786
  column => [$key2, $key3],
1787
  where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
cleanup test
Yuki Kimoto authored on 2011-08-15
1788

            
1789
$result->filter({$key2 => 'twice'});
1790
$rows   = $result->all;
1791
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1792

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

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

            
1802
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1803
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1804
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1805
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1806
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1807
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1808

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1809
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1810
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1811
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1812
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1813
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1814
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1815

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

            
1822
test 'end_filter';
1823
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1824
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1825
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1826
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1827
$result = $dbi->select(table => $table1);
1828
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1829
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1830
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1831
is_deeply($row, [6, 40]);
1832

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1833
$dbi = DBIx::Custom->connect;
1834
eval { $dbi->execute("drop table $table1") };
1835
$dbi->execute($create_table1);
1836
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1837
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1838
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1839
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1840
$row = $result->fetch_one;
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1841
is_deeply($row, [6, 6, 40]);
1842

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1843
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1844
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1845
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1846
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1847
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1848
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1849
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1850
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1851
is_deeply($row, [6, 12]);
1852

            
1853
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1854
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1855
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1856
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1857
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1858
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1859
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1860
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1861
is_deeply($row, [6, 12]);
1862

            
1863
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1864
$result = $dbi->select(table => $table1);
1865
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1866
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1867
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1868
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1869

            
1870
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1871
$dbi->apply_filter($table1,
cleanup
Yuki Kimoto authored on 2012-01-20
1872
  $key1 => {end => sub { $_[0] * 3 } },
1873
  $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1874
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1875
$result = $dbi->select(table => $table1);
1876
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1877
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1878
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1879

            
1880
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1881
$dbi->apply_filter($table1,
cleanup
Yuki Kimoto authored on 2012-01-20
1882
  $key1 => {end => sub { $_[0] * 3 } },
1883
  $key2 => {end => 'five_times'}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1884
);
1885
$result = $dbi->select(table => $table1);
1886
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1887
$result->filter($key1 => undef);
1888
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1889
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1890
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1891

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1892
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1893
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1894
$result->filter($key1 => undef);
1895
$result->end_filter($key1 => undef);
1896
$row = $result->fetch;
1897
is_deeply($row, [1, 1, 40], 'apply_filter overwrite');
1898

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1899
test 'remove_end_filter and remove_filter';
1900
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1901
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1902
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1903
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1904
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1905
$row = $result
cleanup
Yuki Kimoto authored on 2012-01-20
1906
  ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
1907
  ->remove_filter
1908
  ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
1909
  ->remove_end_filter
1910
  ->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1911
is_deeply($row, [1, 2]);
1912

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

            
1922
test 'select query option';
1923
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1924
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1925
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1926
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1927
ok(ref $query);
cleanup
Yuki Kimoto authored on 2011-11-01
1928
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1929
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1930
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1931
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1932
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1933
ok(ref $query);
test cleanup
Yuki Kimoto authored on 2011-08-10
1934

            
1935
test 'where';
1936
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1937
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1938
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1939
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1940
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1941
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1942
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1943

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

            
1948
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1949
  table => $table1,
1950
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1951
);
1952
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1953
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1954

            
1955
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1956
  table => $table1,
1957
  where => [
1958
    ['and', "$key1 = :$key1", "$key2 = :$key2"],
1959
    {$key1 => 1}
1960
  ]
test cleanup
Yuki Kimoto authored on 2011-08-10
1961
);
1962
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1963
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1964

            
1965
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1966
  ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1967
  ->param({$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1968
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1969
  table => $table1,
1970
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1971
);
1972
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1973
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1974

            
1975
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1976
  ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1977
  ->param({});
test cleanup
Yuki Kimoto authored on 2011-08-10
1978
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1979
  table => $table1,
1980
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1981
);
1982
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1983
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1984

            
1985
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1986
  ->clause(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"])
1987
  ->param({$key1 => [0, 3], $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1988
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1989
  table => $table1,
1990
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1991
); 
1992
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1993
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1994

            
1995
$where = $dbi->where;
1996
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1997
  table => $table1,
1998
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1999
);
2000
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2001
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2002

            
2003
eval {
2004
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2005
           ->clause(['uuu']);
test cleanup
Yuki Kimoto authored on 2011-08-10
2006
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2007
  table => $table1,
2008
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
2009
);
2010
};
2011
ok($@);
2012

            
2013
$where = $dbi->where;
2014
is("$where", '');
2015

            
2016
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2017
  ->clause(['or', ("$key1 = :$key1") x 2])
2018
  ->param({$key1 => [1, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2019
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2020
  table => $table1,
2021
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2022
);
2023
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2024
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2025

            
2026
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2027
   ->clause(['or', ("$key1 = :$key1") x 2])
2028
   ->param({$key1 => [1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2029
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2030
  table => $table1,
2031
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2032
);
2033
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2034
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2035

            
2036
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2037
  ->clause(['or', ("$key1 = :$key1") x 2])
2038
  ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
2039
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2040
  table => $table1,
2041
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2042
);
2043
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2044
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2045

            
2046
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2047
  ->clause("$key1 = :$key1")
2048
  ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
2049
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2050
  table => $table1,
2051
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2052
);
2053
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2054
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2055

            
2056
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2057
  ->clause(['or', ("$key1 = :$key1") x 3])
2058
  ->param({$key1 => [$dbi->not_exists, 1, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2059
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2060
  table => $table1,
2061
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2062
);
2063
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2064
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
2065

            
2066
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2067
  ->clause(['or', ("$key1 = :$key1") x 3])
2068
  ->param({$key1 => [1, $dbi->not_exists, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2069
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2070
  table => $table1,
2071
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2072
);
2073
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2074
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
2075

            
2076
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2077
  ->clause(['or', ("$key1 = :$key1") x 3])
2078
  ->param({$key1 => [1, 3, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2079
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2080
  table => $table1,
2081
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2082
);
2083
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2084
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
2085

            
2086
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2087
  ->clause(['or', ("$key1 = :$key1") x 3])
2088
  ->param({$key1 => [1, $dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2089
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2090
  table => $table1,
2091
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2092
);
2093
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2094
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
2095

            
2096
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2097
  ->clause(['or', ("$key1 = :$key1") x 3])
2098
  ->param({$key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2099
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2100
  table => $table1,
2101
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2102
);
2103
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2104
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
2105

            
2106
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2107
  ->clause(['or', ("$key1 = :$key1") x 3])
2108
  ->param({$key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2109
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2110
  table => $table1,
2111
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2112
);
2113
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2114
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
2115

            
2116
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2117
  ->clause(['or', ("$key1 = :$key1") x 3])
2118
  ->param({$key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2119
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2120
  table => $table1,
2121
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2122
);
2123
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2124
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
2125

            
2126
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2127
  ->clause(['or', ("$key1 = :$key1") x 3])
2128
  ->param({$key1 => []});
test cleanup
Yuki Kimoto authored on 2011-08-10
2129
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2130
  table => $table1,
2131
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2132
);
2133
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2134
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
2135

            
2136
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2137
  ->clause(['and', "{> $key1}", "{< $key1}" ])
2138
  ->param({$key1 => [2, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2139
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2140
  table => $table1,
2141
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2142
);
2143
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2144
is_deeply($row, [{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
2145

            
2146
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2147
  ->clause(['and', "{> $key1}", "{< $key1}" ])
2148
  ->param({$key1 => [$dbi->not_exists, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2149
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2150
  table => $table1,
2151
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2152
);
2153
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2154
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
2155

            
2156
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2157
  ->clause(['and', "{> $key1}", "{< $key1}" ])
2158
  ->param({$key1 => [$dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2159
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2160
  table => $table1,
2161
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2162
);
2163
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2164
is_deeply($row, [{$key1 => 1, $key2 => 2},{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
2165

            
2166
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2167
  ->clause(['and', "{> $key1}", "{< $key1}" ])
2168
  ->param({$key1 => [0, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2169
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2170
  table => $table1,
2171
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2172
);
2173
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2174
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
2175

            
2176
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2177
  ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2178
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2179
  table => $table1,
2180
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2181
);
2182
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2183
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
2184

            
2185
eval {$dbi->where(ppp => 1) };
2186
like($@, qr/invalid/);
2187

            
2188
$where = $dbi->where(
cleanup
Yuki Kimoto authored on 2012-01-20
2189
  clause => ['and', ['or'], ['and', "$key1 = :$key1", "$key2 = :$key2"]],
2190
  param => {$key1 => 1, $key2 => 2}
test cleanup
Yuki Kimoto authored on 2011-08-10
2191
);
2192
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2193
  table => $table1,
2194
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2195
);
2196
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2197
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2198

            
2199

            
2200
$where = $dbi->where(
cleanup
Yuki Kimoto authored on 2012-01-20
2201
  clause => ['and', ['or'], ['or', ":$key1", ":$key2"]],
2202
  param => {}
test cleanup
Yuki Kimoto authored on 2011-08-10
2203
);
2204
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2205
  table => $table1,
2206
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2207
);
2208
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2209
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2210

            
2211
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2212
$where->clause(['and', ":${key1}{=}"]);
2213
$where->param({$key1 => undef});
2214
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
2215
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2216
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2217

            
2218
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2219
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2220
$where->param({$key1 => [undef, undef]});
2221
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2222
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2223
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2224
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2225
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2226
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2227

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

            
2229
$dbi = DBIx::Custom->connect;
2230
eval { $dbi->execute("drop table $table1") };
2231
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2232
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
2233
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2234
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2235
  ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
2236
  ->param({$key1 => 1});
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2237

            
2238
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2239
  table => $table1,
2240
  where => $where
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2241
);
2242
$row = $result->all;
2243
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
2244

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2245
test 'register_tag_processor';
2246
$dbi = DBIx::Custom->connect;
2247
$dbi->register_tag_processor(
cleanup
Yuki Kimoto authored on 2012-01-20
2248
  a => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
2249
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2250
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2251

            
2252
test 'register_tag';
2253
$dbi = DBIx::Custom->connect;
2254
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
2255
  b => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
2256
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2257
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2258

            
2259
test 'table not specify exception';
2260
$dbi = DBIx::Custom->connect;
select method can be called ...
Yuki Kimoto authored on 2012-02-07
2261
eval {$dbi->select($key1)};
2262
ok($@);
test cleanup
Yuki Kimoto authored on 2011-08-10
2263

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2264
test 'more tests';
2265
$dbi = DBIx::Custom->connect;
2266
eval{$dbi->apply_filter('table', 'column', [])};
2267
like($@, qr/apply_filter/);
2268

            
2269
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
2270
like($@, qr/apply_filter/);
2271

            
2272
$dbi->apply_filter(
2273

            
2274
);
2275
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2276
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2277
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2278
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2279
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2280
$dbi->apply_filter($table1, $key2, 
cleanup
Yuki Kimoto authored on 2012-01-20
2281
                 {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2282
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
2283
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2284

            
2285
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2286
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2287
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2288
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2289
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2290
$dbi->apply_filter($table1, $key2, {});
2291
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
2292
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2293

            
2294
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2295
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2296
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2297
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2298
like($@, qr/not registered/);
2299
$dbi->method({one => sub { 1 }});
2300
is($dbi->one, 1);
2301

            
2302
eval{DBIx::Custom->connect(dsn => undef)};
2303
like($@, qr/_connect/);
2304

            
2305
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2306
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2307
$dbi->execute($create_table1);
2308
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
2309
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
2310
           filter => {$key1 => 'twice'});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2311
$row = $dbi->select(table => $table1)->one;
2312
is_deeply($row, {$key1 => 2, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
2313
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
2314
           filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
2315
like($@, qr//);
2316

            
2317
$dbi->register_filter(one => sub { });
2318
$dbi->default_fetch_filter('one');
2319
ok($dbi->default_fetch_filter);
2320
$dbi->default_bind_filter('one');
2321
ok($dbi->default_bind_filter);
2322
eval{$dbi->default_fetch_filter('no')};
2323
like($@, qr/not registered/);
2324
eval{$dbi->default_bind_filter('no')};
2325
like($@, qr/not registered/);
2326
$dbi->default_bind_filter(undef);
2327
ok(!defined $dbi->default_bind_filter);
2328
$dbi->default_fetch_filter(undef);
2329
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2330
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2331
like($@, qr/Tag not finished/);
2332

            
2333
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2334
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2335
$dbi->execute($create_table1);
2336
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2337
$result = $dbi->select(table => $table1);
2338
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2339
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2340
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2341
like($@, qr/not registered/);
2342
$result->default_filter(undef);
2343
ok(!defined $result->default_filter);
2344
$result->default_filter('one');
2345
is($result->default_filter->(), 1);
2346

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2347
test 'option';
2348
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
2349
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
2350
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2351
ok($dbi->dbh->{PrintError});
2352
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2353
ok($dbi->dbh->{PrintError});
2354

            
2355
test 'DBIx::Custom::Result stash()';
2356
$result = DBIx::Custom::Result->new;
2357
is_deeply($result->stash, {}, 'default');
2358
$result->stash->{foo} = 1;
2359
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2360

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

            
cleanup
Yuki Kimoto authored on 2011-11-01
2373
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2374
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2375
  table => $table1,
2376
  primary_key => $key1,
2377
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2378
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2379
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2380

            
2381
test 'insert_at';
2382
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2383
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2384
$dbi->execute($create_table1_2);
2385
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2386
  {$key3 => 3},
2387
  primary_key => [$key1, $key2], 
2388
  table => $table1,
2389
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2390
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2391
is($dbi->select(table => $table1)->one->{$key1}, 1);
2392
is($dbi->select(table => $table1)->one->{$key2}, 2);
2393
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2394

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2395
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2396
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2397
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2398
  {$key2 => 2, $key3 => 3},
2399
  primary_key => $key1, 
2400
  table => $table1,
2401
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2402
);
2403

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

            
2408
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2409
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2410
$dbi->execute($create_table1_2);
2411
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2412
  {$key3 => 3},
2413
  primary_key => [$key1, $key2], 
2414
  table => $table1,
2415
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2416
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2417
is($dbi->select(table => $table1)->one->{$key1}, 1);
2418
is($dbi->select(table => $table1)->one->{$key2}, 2);
2419
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2420

            
2421
test 'update_at';
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_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2425
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2426
$dbi->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2427
  {$key3 => 4},
2428
  table => $table1,
2429
  primary_key => [$key1, $key2],
2430
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2431
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2432
is($dbi->select(table => $table1)->one->{$key1}, 1);
2433
is($dbi->select(table => $table1)->one->{$key2}, 2);
2434
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2435

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2436
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2437
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2438
$dbi->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2439
  {$key3 => 4},
2440
  table => $table1,
2441
  primary_key => $key1,
2442
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2443
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2444
is($dbi->select(table => $table1)->one->{$key1}, 1);
2445
is($dbi->select(table => $table1)->one->{$key2}, 2);
2446
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2447

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

            
2462
test 'select_at';
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_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2466
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2467
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2468
  table => $table1,
2469
  primary_key => [$key1, $key2],
2470
  where => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2471
);
2472
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2473
is($row->{$key1}, 1);
2474
is($row->{$key2}, 2);
2475
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2476

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2477
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2478
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2479
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2480
  table => $table1,
2481
  primary_key => $key1,
2482
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2483
);
2484
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2485
is($row->{$key1}, 1);
2486
is($row->{$key2}, 2);
2487
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2488

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2489
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2490
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2491
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2492
  table => $table1,
2493
  primary_key => [$key1, $key2],
2494
  where => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2495
);
2496
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2497
is($row->{$key1}, 1);
2498
is($row->{$key2}, 2);
2499
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2500

            
2501
test 'model delete_at';
2502
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2503
eval { $dbi->execute("drop table $table1") };
2504
eval { $dbi->execute("drop table $table2") };
2505
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2506
$dbi->execute($create_table1_2);
2507
$dbi->execute($create_table2_2);
2508
$dbi->execute($create_table3);
test cleanup
Yuki Kimoto authored on 2011-11-01
2509
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2510
$dbi->model($table1)->delete_at(where => [1, 2]);
2511
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2512
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2513
$dbi->model($table1)->delete_at(where => [1, 2]);
2514
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2515
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2516
$dbi->model($table3)->delete_at(where => [1, 2]);
2517
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2518

            
2519
test 'model insert_at';
2520
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2521
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2522
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2523
$dbi->model($table1)->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2524
  {$key3 => 3},
2525
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2526
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2527
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2528
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2529
is($row->{$key1}, 1);
2530
is($row->{$key2}, 2);
2531
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2532

            
2533
test 'model update_at';
2534
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2535
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2536
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2537
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2538
$dbi->model($table1)->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2539
  {$key3 => 4},
2540
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2541
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2542
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2543
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2544
is($row->{$key1}, 1);
2545
is($row->{$key2}, 2);
2546
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2547

            
2548
test 'model select_at';
2549
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2550
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2551
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2552
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2553
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2554
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2555
is($row->{$key1}, 1);
2556
is($row->{$key2}, 2);
2557
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2558

            
2559

            
2560
test 'mycolumn and column';
2561
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2562
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2563
eval { $dbi->execute("drop table $table1") };
2564
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2565
$dbi->execute($create_table1);
2566
$dbi->execute($create_table2);
2567
$dbi->separator('__');
improved test
Yuki Kimoto authored on 2012-03-01
2568
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
2569
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2570
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2571
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2572
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2573
  column => [$model->mycolumn, $model->column($table2)],
2574
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2575
);
2576
is_deeply($result->one,
improved test
Yuki Kimoto authored on 2012-03-01
2577
        {$key1 => 1, $key2 => 2, u2"${table2}__$key1" => 1, u2"${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2578

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2579
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2580
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2581
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2582
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2583
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2584
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2585
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2586
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2587
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2588
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2589
is($dbi->select(table => $table1)->one->{$key1}, 1);
2590
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2591

            
2592
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2593
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2594
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2595
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2596
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2597
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2598
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2599
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2600
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2601
is($dbi->select(table => $table1)->one->{$key1}, 1);
2602
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2603

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2604
test 'mycolumn';
2605
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2606
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2607
eval { $dbi->execute("drop table $table1") };
2608
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2609
$dbi->execute($create_table1);
2610
$dbi->execute($create_table2);
improved test
Yuki Kimoto authored on 2012-03-01
2611
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
2612
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2613
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2614
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2615
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2616
  column => [
2617
    $model->mycolumn,
2618
    $model->column($table2)
2619
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2620
);
2621
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2622
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2623

            
2624
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2625
  column => [
2626
    $model->mycolumn([$key1]),
2627
    $model->column($table2 => [$key1])
2628
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2629
);
2630
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2631
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2632
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2633
  column => [
2634
    $model->mycolumn([$key1]),
2635
    {$table2 => [$key1]}
2636
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2637
);
2638
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2639
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2640

            
2641
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2642
  column => [
2643
    $model->mycolumn([$key1]),
2644
    ["$table2.$key1", as => "$table2.$key1"]
2645
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2646
);
2647
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2648
  {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2649

            
2650
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2651
  column => [
2652
    $model->mycolumn([$key1]),
2653
    ["$table2.$key1" => "$table2.$key1"]
2654
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2655
);
2656
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2657
  {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2658

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2659
test 'merge_param';
2660
$dbi = DBIx::Custom->new;
2661
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2662
  {$key1 => 1, $key2 => 2, $key3 => 3},
2663
  {$key1 => 1, $key2 => 2},
2664
  {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2665
];
2666
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2667
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2668

            
2669
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2670
  {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2671
  {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2672
];
2673
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2674
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
2675

            
2676
test 'select() param option';
2677
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2678
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2679
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2680
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2681
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2682
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2683
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2684
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
2685
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
2686
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2687
  table => $table1,
improved test
Yuki Kimoto authored on 2012-03-01
2688
  column => "$table1.$key1 as " . u("${table1}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
2689
  where   => {"$table1.$key2" => 3},
2690
  join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
improved test
Yuki Kimoto authored on 2012-03-01
2691
            " $q$table2$p on $table1.$key1 = $q$table2$p.$key1"],
cleanup
Yuki Kimoto authored on 2012-01-20
2692
  param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2693
)->all;
improved test
Yuki Kimoto authored on 2012-03-01
2694
is_deeply($rows, [{u"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2695

            
cleanup
Yuki Kimoto authored on 2011-10-21
2696
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2697
  table => $table1,
improved test
Yuki Kimoto authored on 2012-03-01
2698
  column => "$table1.$key1 as " . u("${table1}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
2699
  where   => {"$table1.$key2" => 3},
2700
  join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
improved test
Yuki Kimoto authored on 2012-03-01
2701
           " $q$table2$p on $table1.$key1 = $q$table2$p.$key1",
cleanup
Yuki Kimoto authored on 2012-01-20
2702
  param => {"$table2.$key3" => 5}
cleanup
Yuki Kimoto authored on 2011-10-21
2703
)->all;
improved test
Yuki Kimoto authored on 2012-03-01
2704
is_deeply($rows, [{u"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup
Yuki Kimoto authored on 2011-10-21
2705

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2706
test 'select() string where';
2707
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2708
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2709
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2710
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2711
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2712
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2713
  table => $table1,
2714
  where => "$key1 = :$key1 and $key2 = :$key2",
2715
  where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2716
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2717
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2718

            
2719
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2720
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2721
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2722
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2723
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2724
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2725
  table => $table1,
2726
  where => [
2727
    "$key1 = :$key1 and $key2 = :$key2",
2728
    {$key1 => 1, $key2 => 2}
2729
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2730
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2731
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2732

            
cleanup
Yuki Kimoto authored on 2011-10-21
2733
$dbi = DBIx::Custom->connect;
2734
eval { $dbi->execute("drop table $table1") };
2735
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2736
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2737
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
2738
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2739
  table => $table1,
2740
  where => [
2741
    "$key1 = :$key1 and $key2 = :$key2",
2742
    {$key1 => 1, $key2 => 2}
2743
  ]
cleanup
Yuki Kimoto authored on 2011-10-21
2744
)->all;
2745
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2746

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2747
test 'delete() string where';
2748
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2749
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2750
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2751
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2752
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2753
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2754
  table => $table1,
2755
  where => "$key1 = :$key1 and $key2 = :$key2",
2756
  where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2757
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2758
$rows = $dbi->select(table => $table1)->all;
2759
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2760

            
2761
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2762
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2763
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2764
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2765
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2766
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2767
  table => $table1,
2768
  where => [
2769
    "$key1 = :$key1 and $key2 = :$key2",
2770
     {$key1 => 1, $key2 => 2}
2771
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2772
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2773
$rows = $dbi->select(table => $table1)->all;
2774
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2775

            
2776

            
2777
test 'update() string where';
2778
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2779
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2780
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2781
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2782
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2783
  {$key1 => 5},
2784
  table => $table1,
2785
  where => "$key1 = :$key1 and $key2 = :$key2",
2786
  where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2787
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2788
$rows = $dbi->select(table => $table1)->all;
2789
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2790

            
2791
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2792
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2793
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2794
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2795
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2796
  {$key1 => 5},
2797
  table => $table1,
2798
  where => [
2799
    "$key1 = :$key1 and $key2 = :$key2",
2800
    {$key1 => 1, $key2 => 2}
2801
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2802
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2803
$rows = $dbi->select(table => $table1)->all;
2804
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2805

            
2806
test 'insert id and primary_key option';
2807
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2808
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2809
$dbi->execute($create_table1_2);
2810
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2811
  {$key3 => 3},
2812
  primary_key => [$key1, $key2], 
2813
  table => $table1,
2814
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2815
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2816
is($dbi->select(table => $table1)->one->{$key1}, 1);
2817
is($dbi->select(table => $table1)->one->{$key2}, 2);
2818
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2819

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2820
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2821
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2822
  {$key2 => 2, $key3 => 3},
2823
  primary_key => $key1, 
2824
  table => $table1,
2825
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2826
);
2827

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2832
$dbi = DBIx::Custom->connect;
2833
eval { $dbi->execute("drop table $table1") };
2834
$dbi->execute($create_table1_2);
2835
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2836
  {$key3 => 3},
2837
  primary_key => [$key1, $key2], 
2838
  table => $table1,
2839
  id => 1,
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2840
);
2841
is($dbi->select(table => $table1)->one->{$key1}, 1);
2842
ok(!$dbi->select(table => $table1)->one->{$key2});
2843
is($dbi->select(table => $table1)->one->{$key3}, 3);
2844

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2845
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2846
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2847
$dbi->execute($create_table1_2);
2848
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2849
  {$key3 => 3},
2850
  primary_key => [$key1, $key2], 
2851
  table => $table1,
2852
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2853
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2854
is($dbi->select(table => $table1)->one->{$key1}, 1);
2855
is($dbi->select(table => $table1)->one->{$key2}, 2);
2856
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2857

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2858
$dbi = DBIx::Custom->connect;
2859
eval { $dbi->execute("drop table $table1") };
2860
$dbi->execute($create_table1_2);
2861
$param = {$key3 => 3, $key2 => 4};
2862
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2863
  $param,
2864
  primary_key => [$key1, $key2], 
2865
  table => $table1,
2866
  id => [1, 2],
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2867
);
2868
is($dbi->select(table => $table1)->one->{$key1}, 1);
2869
is($dbi->select(table => $table1)->one->{$key2}, 4);
2870
is($dbi->select(table => $table1)->one->{$key3}, 3);
2871
is_deeply($param, {$key3 => 3, $key2 => 4});
2872

            
added test
Yuki Kimoto authored on 2011-10-25
2873
$dbi = DBIx::Custom->connect;
2874
eval { $dbi->execute("drop table $table1") };
2875
$dbi->execute($create_table1_2);
2876
$param = {$key3 => 3, $key2 => 4};
2877
$query = $dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2878
  $param,
2879
  primary_key => [$key1, $key2], 
2880
  table => $table1,
2881
  id => [1, 2],
2882
  query => 1
added test
Yuki Kimoto authored on 2011-10-25
2883
);
micro optimization
Yuki Kimoto authored on 2011-11-16
2884
ok(ref $query);
added test
Yuki Kimoto authored on 2011-10-25
2885
is_deeply($param, {$key3 => 3, $key2 => 4});
2886

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2887
test 'model insert id and primary_key option';
2888
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2889
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2890
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2891
$dbi->model($table1)->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2892
  {$key3 => 3},
2893
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2894
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2895
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2896
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2897
is($row->{$key1}, 1);
2898
is($row->{$key2}, 2);
2899
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2900

            
2901
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2902
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2903
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2904
$dbi->model($table1)->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2905
  {$key3 => 3},
2906
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2907
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2908
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2909
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2910
is($row->{$key1}, 1);
2911
is($row->{$key2}, 2);
2912
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2913

            
2914
test 'update and id option';
2915
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2916
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2917
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2918
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2919
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2920
  {$key3 => 4},
2921
  table => $table1,
2922
  primary_key => [$key1, $key2],
2923
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2924
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2925
is($dbi->select(table => $table1)->one->{$key1}, 1);
2926
is($dbi->select(table => $table1)->one->{$key2}, 2);
2927
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2928

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2929
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2930
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2931
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2932
  {$key3 => 4},
2933
  table => $table1,
2934
  primary_key => $key1,
2935
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2936
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2937
is($dbi->select(table => $table1)->one->{$key1}, 0);
2938
is($dbi->select(table => $table1)->one->{$key2}, 2);
2939
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2940

            
2941
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2942
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2943
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2944
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2945
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2946
  {$key3 => 4},
2947
  table => $table1,
2948
  primary_key => [$key1, $key2],
2949
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2950
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2951
is($dbi->select(table => $table1)->one->{$key1}, 1);
2952
is($dbi->select(table => $table1)->one->{$key2}, 2);
2953
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2954

            
2955

            
2956
test 'model update and id option';
2957
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2958
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2959
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2960
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2961
$dbi->model($table1)->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2962
  {$key3 => 4},
2963
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2964
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2965
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2966
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2967
is($row->{$key1}, 1);
2968
is($row->{$key2}, 2);
2969
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2970

            
2971

            
2972
test 'delete and id option';
2973
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2974
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2975
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2976
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2977
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2978
  table => $table1,
2979
  primary_key => [$key1, $key2],
2980
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2981
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2982
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2983

            
cleanup
Yuki Kimoto authored on 2011-11-01
2984
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2985
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2986
  table => $table1,
2987
  primary_key => $key1,
2988
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2989
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2990
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2991

            
2992

            
2993
test 'model delete and id option';
2994
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2995
eval { $dbi->execute("drop table $table1") };
2996
eval { $dbi->execute("drop table $table2") };
2997
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2998
$dbi->execute($create_table1_2);
2999
$dbi->execute($create_table2_2);
3000
$dbi->execute($create_table3);
cleanup
Yuki Kimoto authored on 2011-11-01
3001
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3002
$dbi->model($table1)->delete(id => [1, 2]);
3003
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
3004
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3005
$dbi->model($table1)->delete(id => [1, 2]);
3006
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
3007
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3008
$dbi->model($table3)->delete(id => [1, 2]);
3009
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
3010

            
3011

            
3012
test 'select and id option';
3013
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3014
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3015
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
3016
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3017
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3018
  table => $table1,
3019
  primary_key => [$key1, $key2],
3020
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
3021
);
3022
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3023
is($row->{$key1}, 1);
3024
is($row->{$key2}, 2);
3025
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
3026

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3027
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3028
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3029
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3030
  table => $table1,
3031
  primary_key => $key1,
3032
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
3033
);
3034
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3035
is($row->{$key1}, 0);
3036
is($row->{$key2}, 2);
3037
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
3038

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3039
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3040
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3041
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3042
  table => $table1,
3043
  primary_key => [$key1, $key2],
3044
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
3045
);
3046
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3047
is($row->{$key1}, 1);
3048
is($row->{$key2}, 2);
3049
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
3050

            
3051

            
3052
test 'model select_at';
3053
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3054
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3055
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
3056
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3057
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3058
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3059
is($row->{$key1}, 1);
3060
is($row->{$key2}, 2);
3061
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
3062

            
3063
test 'column separator is default .';
3064
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3065
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3066
eval { $dbi->execute("drop table $table1") };
3067
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3068
$dbi->execute($create_table1);
3069
$dbi->execute($create_table2);
improved test
Yuki Kimoto authored on 2012-03-01
3070
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
3071
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3072
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3073
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3074
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3075
  column => [$model->column($table2)],
3076
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3077
);
3078
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3079
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
3080

            
3081
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3082
  column => [$model->column($table2 => [$key1, $key3])],
3083
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3084
);
3085
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3086
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3087

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3088
test 'separator';
3089
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3090
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3091
eval { $dbi->execute("drop table $table1") };
3092
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3093
$dbi->execute($create_table1);
3094
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
3095

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3096
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3097
  table => $table1,
3098
  join => [
3099
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3100
  ],
3101
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
3102
);
3103
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3104
  table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
3105
);
improved test
Yuki Kimoto authored on 2012-03-01
3106
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
3107
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3108
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3109
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3110
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3111
  column => [
3112
    $model->mycolumn,
3113
    {$table2 => [$key1, $key3]}
3114
  ],
3115
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3116
);
3117
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3118
        {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3119
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3120

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3121
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3122
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3123
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3124
  column => [
3125
    $model->mycolumn,
3126
    {$table2 => [$key1, $key3]}
3127
  ],
3128
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3129
);
3130
is_deeply($result->one,
improved test
Yuki Kimoto authored on 2012-03-01
3131
        {$key1 => 1, $key2 => 2, u2"${table2}__$key1" => 1, u2"${table2}__$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3132
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3133

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3134
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3135
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3136
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3137
  column => [
3138
    $model->mycolumn,
3139
    {$table2 => [$key1, $key3]}
3140
  ],
3141
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3142
);
3143
is_deeply($result->one,
improved test
Yuki Kimoto authored on 2012-03-01
3144
  {$key1 => 1, $key2 => 2, hy"$table2-$key1" => 1, hy"$table2-$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3145
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3146

            
3147

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3148
test 'filter_off';
3149
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3150
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3151
eval { $dbi->execute("drop table $table1") };
3152
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3153
$dbi->execute($create_table1);
3154
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
3155

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3156
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3157
  table => $table1,
3158
  join => [
3159
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3160
  ],
3161
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
3162
);
improved test
Yuki Kimoto authored on 2012-03-01
3163
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
3164
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3165
$model = $dbi->model($table1);
3166
$result = $model->select(column => $key1);
3167
$result->filter($key1 => sub { $_[0] * 2 });
3168
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
3169

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3170
test 'available_datetype';
3171
$dbi = DBIx::Custom->connect;
3172
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
3173

            
3174

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3175
test 'select prefix option';
3176
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3177
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3178
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3179
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3180
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3181
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
3182

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

            
added tests
Yuki Kimoto authored on 2011-08-26
3184
test 'mapper';
3185
$dbi = DBIx::Custom->connect;
3186
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3187
  id => {key => "$table1.id"},
3188
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3189
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
3190
);
3191
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3192
"$table1.price" => 1900});
added tests
Yuki Kimoto authored on 2011-08-26
3193

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3194
$dbi = DBIx::Custom->connect;
3195
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3196
  id => {key => "$table1.id"},
3197
  author => ["$table1.author" => $dbi->like_value],
3198
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3199
);
3200
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3201
"$table1.price" => 1900});
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3202

            
added tests
Yuki Kimoto authored on 2011-08-26
3203
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3204
  id => {key => "$table1.id"},
3205
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3206
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
3207
);
3208
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
3209

            
3210
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3211
  id => {key => "$table1.id"},
3212
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3213
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
added tests
Yuki Kimoto authored on 2011-08-26
3214
);
3215
is_deeply($param, {});
3216

            
3217
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3218
  id => {key => "$table1.id"},
3219
  price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
3220
);
3221
is_deeply($param, {"$table1.price" => undef});
3222

            
3223
$param = $dbi->mapper(param => {price => 'a'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3224
  id => {key => "$table1.id", condition => 'exists'},
3225
  price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
3226
);
3227
is_deeply($param, {"$table1.price" => '%a'});
3228

            
3229
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3230
  id => {key => "$table1.id"},
3231
  price => ["$table1.price", sub { '%' . $_[0] }]
added tests
Yuki Kimoto authored on 2011-08-26
3232
);
3233
is_deeply($param, {"$table1.price" => '%a'});
3234

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3235
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3236
  price => sub { '%' . $_[0] },
3237
  author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
3238
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3239
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
3240

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

            
3246
$where = $dbi->where;
3247
$where->clause(['and', ":${key1}{=}"]);
3248
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
3249
$where->param($param);
3250
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3251
$row = $result->all;
3252
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3253

            
3254
$where = $dbi->where;
3255
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
3256
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
3257
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
3258
$row = $result->all;
3259
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3260
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
3261
$row = $result->all;
3262
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3263

            
3264
$where = $dbi->where;
3265
$where->clause(['and', ":${key1}{=}"]);
3266
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
3267
$where->param($param);
3268
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
3269
$row = $result->all;
3270
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3271
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
3272
$row = $result->all;
3273
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3274

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3276
$where = $dbi->where;
3277
$where->clause(['and', ":${key1}{=}"]);
3278
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
cleanup
Yuki Kimoto authored on 2012-01-20
3279
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3280
$where->param($param);
3281
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3282
$row = $result->all;
3283
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3284

            
3285
$where = $dbi->where;
3286
$where->clause(['and', ":${key1}{=}"]);
3287
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
3288
$where->param($param);
3289
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3290
$row = $result->all;
3291
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3292

            
3293
$where = $dbi->where;
3294
$where->clause(['and', ":${key1}{=}"]);
3295
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
cleanup
Yuki Kimoto authored on 2012-01-20
3296
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3297
$where->param($param);
3298
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3299
$row = $result->all;
3300
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3301

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3303
$where = $dbi->where;
3304
$where->clause(['and', ":${key1}{=}"]);
3305
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
3306
$where->param($param);
3307
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3308
$row = $result->all;
3309
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3310

            
3311
$where = $dbi->where;
3312
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3313
  id => {key => "$table1.id"},
3314
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3315
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3316
);
3317
$where->param($param);
3318
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3319
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3320

            
3321
$where = $dbi->where;
3322
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3323
  id => {key => "$table1.id"},
3324
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3325
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3326
);
3327
$where->param($param);
3328
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
3329

            
3330
$where = $dbi->where;
3331
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3332
  id => {key => "$table1.id"},
3333
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3334
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3335
);
3336
$where->param($param);
3337
is_deeply($where->param, {});
3338

            
3339
$where = $dbi->where;
3340
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3341
  id => {key => "$table1.id"},
3342
  price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3343
);
3344
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
3345

            
3346
$where = $dbi->where;
3347
$param = $dbi->mapper(param => {price => 'a'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3348
  id => {key => "$table1.id", condition => 'exists'},
3349
  price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3350
);
3351
is_deeply($param, {"$table1.price" => '%a'});
3352

            
3353
$where = $dbi->where;
3354
$param = $dbi->mapper(param => {id => [1, 2], author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3355
  id => {key => "$table1.id"},
3356
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3357
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3358
);
3359
is_deeply($param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3360
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3361

            
3362
$where = $dbi->where;
3363
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900}, condition => 'length')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3364
  id => {key => "$table1.id"},
3365
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3366
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3367
);
3368
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3369
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3370

            
3371
$where = $dbi->where;
3372
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3373
  id => {key => "$table1.id", condition => 'length'},
3374
  author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
3375
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3376
);
3377
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3378
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3379

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

            
- DBIx::Custom::Mapper::map ...
Yuki Kimoto authored on 2012-02-29
3385
$param = $dbi->mapper(param => {author => 'Ken',})->map(
3386
  author => ["$table1.author" => '%<value>%'],
3387
);
3388
is_deeply($param, {"$table1.author" => '%Ken%'});
3389

            
3390
$param = $dbi->mapper(param => {author => 'Ken'})->map(
3391
  author => ["$table1.author" => 'p'],
3392
);
3393
is_deeply($param, {"$table1.author" => 'p'});
3394

            
3395
$param = $dbi->mapper(param => {author => 'Ken',})->map(
3396
  author => {value => '%<value>%'}
3397
);
3398
is_deeply($param, {"author" => '%Ken%'});
3399

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3400
test 'order';
3401
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3402
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3403
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3404
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3405
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3406
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3407
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3408
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3409
$order->prepend($key1, "$key2 desc");
3410
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3411
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
3412
{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3413
$order->prepend("$key1 desc");
3414
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3415
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
cleanup
Yuki Kimoto authored on 2012-01-20
3416
{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3417

            
3418
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3419
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3420
$result = $dbi->select(table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
3421
column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
3422
append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3423
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
cleanup
Yuki Kimoto authored on 2012-01-20
3424
{"$table1-$key1" => 1, "$table1-$key2" => 1},
3425
{"$table1-$key1" => 2, "$table1-$key2" => 4},
3426
{"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3427

            
3428
test 'tag_parse';
3429
$dbi = DBIx::Custom->connect;
3430
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3431
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3432
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3433
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3434
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3435
ok($@);
3436

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3437
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3438
{
cleanup
Yuki Kimoto authored on 2012-01-20
3439
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3440
  $dbi = DBIx::Custom->connect;
3441
  eval { $dbi->execute("drop table $table1") };
3442
  $dbi->execute($create_table1);
3443
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3444
  eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3445
  ok($@);
3446
  eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) };
3447
  ok($@);
3448
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3449
}
3450

            
3451
{
cleanup
Yuki Kimoto authored on 2012-01-20
3452
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3453
  $dbi = DBIx::Custom->connect;
3454
  eval { $dbi->execute("drop table $table1") };
3455
  $dbi->execute($create_table1);
3456
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3457
  is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1);
3458
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3459
}
3460

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3461
test 'last_sql';
3462
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3463
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3464
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3465
$dbi->execute("select * from $table1");
micro optimization
Yuki Kimoto authored on 2011-11-18
3466
is($dbi->last_sql, " select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3467

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3499
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3500
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
3501
  $source,
3502
  {"$table1.$key1" => 1, "$table1.$key2" => 1},
3503
  filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3504
);
3505
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3506
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3507

            
3508
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3509
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3510
$dbi->execute($create_table1_highperformance);
3511
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3512
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3513
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3514
];
3515
{
cleanup
Yuki Kimoto authored on 2012-01-20
3516
  my $query;
3517
  for my $row (@$rows) {
3518
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3519
    $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3520
  }
3521
  is_deeply($dbi->select(table => $table1)->all,
3522
    [
3523
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3524
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3525
    ]
3526
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3527
}
3528

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3529
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3530
$dbi->execute($create_table1_highperformance);
3531
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3532
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3533
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3534
];
3535
{
cleanup
Yuki Kimoto authored on 2012-01-20
3536
  my $query;
3537
  my $sth;
3538
  for my $row (@$rows) {
3539
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3540
    $sth ||= $query->{sth};
3541
    $sth->execute(map { $row->{$_} } sort keys %$row);
3542
  }
3543
  is_deeply($dbi->select(table => $table1)->all,
3544
    [
3545
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3546
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3547
    ]
3548
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3549
}
3550

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3551
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3552
$dbi->execute($create_table1_highperformance);
3553
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3554
  {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
3555
  {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3556
];
3557
{
cleanup
Yuki Kimoto authored on 2012-01-20
3558
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3559
  my $query;
3560
  for my $row (@$rows) {
3561
    $query ||= $model->insert($row, query => 1);
3562
    $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3563
  }
3564
  is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3565
    [
3566
      {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3567
      {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
3568
    ]
3569
  );
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3570
}
3571

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3572
eval { $dbi->execute("drop table $table1") };
3573
$dbi->execute($create_table1);
3574
{
cleanup
Yuki Kimoto authored on 2012-01-20
3575
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3576
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3577
  eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3578
  like($@, qr/primary_key/);
3579
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3580
}
3581

            
3582
{
cleanup
Yuki Kimoto authored on 2012-01-20
3583
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3584
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3585
  $model->insert({$key1 => 1});
3586
  $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3587
    table => $table1, primary_key => $key1);
3588
  is($result->one->{$key1}, 1);
3589
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3590
}
3591

            
3592
eval { $dbi->execute("drop table $table1") };
3593
$dbi->execute($create_table1);
3594
{
cleanup
Yuki Kimoto authored on 2012-01-20
3595
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3596
  $model->insert({$key1 => 1});
3597
  eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3598
  is($result->one->{$key1}, 1);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3599
}
3600

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3601
test 'id option more';
3602
eval { $dbi->execute("drop table $table1") };
3603
$dbi->execute($create_table1_highperformance);
3604
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3605
  $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
3606
};
3607
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3608
$model->insert($row);
3609
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3610
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3611
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3612
  {$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
3613
);
3614

            
3615
eval { $dbi->execute("drop table $table1") };
3616
eval { $dbi->execute("drop table $table2") };
3617
$dbi->execute($create_table1);
3618
$dbi->execute($create_table2);
3619
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3620
$model->insert({$key1 => 1, $key2 => 2});
3621
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
3622
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3623
$model->insert({$key1 => 1, $key3 => 3});
3624
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3625
  column => {$table1 => ["$key2"]},
3626
  id => 1
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3627
);
3628
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3629

            
3630
eval { $dbi->execute("drop table $table1") };
3631
$dbi->execute($create_table1_highperformance);
3632
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3633
  $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
3634
};
3635
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3636
$model->insert($row);
3637
$query = $model->delete(id => 1, query => 1);
3638
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3639
is_deeply($dbi->select(table => $table1)->all, []);
3640

            
3641
eval { $dbi->execute("drop table $table1") };
3642
eval { $dbi->execute($create_table1_highperformance) };
3643
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3644
  $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
3645
};
3646
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3647
$model->insert($row);
3648
$query = $model->select(id => 1, query => 1);
3649
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3650
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3651
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3652
  {$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
3653
);
3654

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3655
test 'result';
3656
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3657
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3658
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3659
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3660
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3661

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3662
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3663
@rows = ();
3664
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
3665
  push @rows, [@$row];
test cleanup
Yuki Kimoto authored on 2011-08-10
3666
}
3667
is_deeply(\@rows, [[1, 2], [3, 4]]);
3668

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3669
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3670
@rows = ();
3671
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
3672
  push @rows, {%$row};
test cleanup
Yuki Kimoto authored on 2011-08-10
3673
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3674
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3675

            
3676
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3677
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3678
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3679
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3680
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3681

            
3682
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3683
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3684
$rows = $result->fetch_all;
3685
is_deeply($rows, [[1, 2], [3, 4]]);
3686

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3691
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3692
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3693
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3694
$rows = $result->fetch_all;
3695
is_deeply($rows, [[3, 2], [9, 4]], "array");
3696

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2012-02-28
3709
test 'flat';
3710
$result = $dbi->select(table => $table1);
3711
$rows = [$result->flat];
3712
is_deeply($rows, [1, 2, 3, 4]);
3713

            
added EXPERIMETAL DBIx::Cust...
Yuki Kimoto authored on 2012-02-28
3714
test 'kv';
3715
$dbi = DBIx::Custom->connect;
3716
eval { $dbi->execute("drop table $table1") };
3717
$dbi->execute($create_table1);
3718
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3719
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3720

            
3721
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key1");
3722
$rows = $result->kv;
3723
is_deeply($rows, {0 => {$key2 => 2}, 3 => {$key2 => 4}});
3724

            
3725
$dbi = DBIx::Custom->connect;
3726
eval { $dbi->execute("drop table $table1") };
3727
$dbi->execute($create_table1);
3728
$dbi->insert({$key1 => 0, $key2 => 1}, table => $table1);
3729
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3730
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3731
$dbi->insert({$key1 => 3, $key2 => 5}, table => $table1);
3732

            
3733
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key2");
3734
$rows = $result->kv(multi => 1);
3735
is_deeply($rows, {
3736
  0 => [
3737
    {$key2 => 1},
3738
    {$key2 => 2}
3739
  ],
3740
  3 => [
3741
    {$key2 => 4},
3742
    {$key2 => 5}
3743
  ]
3744
});
3745

            
3746

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3747
test 'DBIx::Custom::Result fetch_multi';
3748
eval { $dbi->execute("drop table $table1") };
3749
$dbi->execute($create_table1);
3750
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3751
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3752
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3753
$result = $dbi->select(table => $table1);
3754
$rows = $result->fetch_multi(2);
3755
is_deeply($rows, [[1, 2], [3, 4]]);
3756
$rows = $result->fetch_multi(2);
3757
is_deeply($rows, [[5, 6]]);
3758
$rows = $result->fetch_multi(2);
3759
ok(!$rows);
3760

            
3761
test 'DBIx::Custom::Result fetch_hash_multi';
3762
eval { $dbi->execute("drop table $table1") };
3763
$dbi->execute($create_table1);
3764
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3765
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3766
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3767
$result = $dbi->select(table => $table1);
3768
$rows = $result->fetch_hash_multi(2);
3769
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3770
$rows = $result->fetch_hash_multi(2);
3771
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3772
$rows = $result->fetch_hash_multi(2);
3773
ok(!$rows);
3774

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3775
test "query_builder";
3776
$datas = [
cleanup
Yuki Kimoto authored on 2012-01-20
3777
  # Basic tests
3778
  {   name            => 'placeholder basic',
3779
    source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
3780
    sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
3781
    columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3782
  },
3783
  {
3784
    name            => 'placeholder in',
3785
    source            => "{in k1 3}",
3786
    sql_expected    => "k1 in (?, ?, ?)",
3787
    columns_expected   => [qw/k1 k1 k1/]
3788
  },
3789
  
3790
  # Table name
3791
  {
3792
    name            => 'placeholder with table name',
3793
    source            => "{= a.k1} {= a.k2}",
3794
    sql_expected    => "a.k1 = ? a.k2 = ?",
3795
    columns_expected  => [qw/a.k1 a.k2/]
3796
  },
3797
  {   
3798
    name            => 'placeholder in with table name',
3799
    source            => "{in a.k1 2} {in b.k2 2}",
3800
    sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
3801
    columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3802
  },
3803
  {
3804
    name            => 'not contain tag',
3805
    source            => "aaa",
3806
    sql_expected    => "aaa",
3807
    columns_expected  => [],
3808
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3809
];
3810

            
3811
for (my $i = 0; $i < @$datas; $i++) {
cleanup
Yuki Kimoto authored on 2012-01-20
3812
  my $data = $datas->[$i];
3813
  my $dbi = DBIx::Custom->new;
3814
  my $builder = $dbi->query_builder;
3815
  my $query = $builder->build_query($data->{source});
3816
  is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3817
  is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3818
}
3819

            
cleanup
Yuki Kimoto authored on 2011-08-13
3820
$dbi = DBIx::Custom->new;
3821
$builder = $dbi->query_builder;
3822
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
3823
  p => sub {
3824
    my @args = @_;
3825
    
3826
    my $expand    = "? $args[0] $args[1]";
3827
    my $columns = [2];
3828
    return [$expand, $columns];
3829
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3830
);
3831

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3842
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3843
  q => 'string'
test cleanup
Yuki Kimoto authored on 2011-08-10
3844
});
3845

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3849
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3850
  r => sub {} 
test cleanup
Yuki Kimoto authored on 2011-08-10
3851
});
3852

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

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

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

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

            
3867

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

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

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

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

            
3883
test 'variouse source';
3884
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3885
$query = $builder->build_query($source);
3886
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3887

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

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

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

            
3900
$source = "a {= b} }";
3901
eval{$builder->build_query($source)};
3902
like($@, qr/unexpected "}"/, "error : 1");
3903

            
3904
$source = "a {= {}";
3905
eval{$builder->build_query($source)};
3906
like($@, qr/unexpected "{"/, "error : 2");
3907

            
3908
test 'select() sqlfilter option';
3909
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3910
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3911
eval { $dbi->execute("drop table $table1") };
3912
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3913
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3914
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3915
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3916
  table => $table1,
3917
  column => $key1,
3918
  sqlfilter => sub {
3919
    my $sql = shift;
3920
    $sql = "select * from ( $sql ) t where $key1 = 1";
3921
    return $sql;
3922
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3923
)->all;
3924
is_deeply($rows, [{$key1 => 1}]);
3925

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3926
test 'select() after_build_sql option';
3927
$dbi = DBIx::Custom->connect;
3928
$dbi->user_table_info($user_table_info);
3929
eval { $dbi->execute("drop table $table1") };
3930
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3931
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3932
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3933
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3934
  table => $table1,
3935
  column => $key1,
3936
  after_build_sql => sub {
3937
    my $sql = shift;
3938
    $sql = "select * from ( $sql ) t where $key1 = 1";
3939
    return $sql;
3940
  }
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3941
)->all;
3942
is_deeply($rows, [{$key1 => 1}]);
3943

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3944
test 'dbi method from model';
3945
$dbi = MyDBI9->connect;
3946
eval { $dbi->execute("drop table $table1") };
3947
$dbi->execute($create_table1);
improved test
Yuki Kimoto authored on 2012-03-01
3948
$dbi->setup_model(@$setup_model_args);
cleanup test
Yuki Kimoto authored on 2011-08-15
3949
$model = $dbi->model($table1);
3950
eval{$model->execute("select * from $table1")};
3951
ok(!$@);
3952

            
3953
test 'column table option';
3954
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3955
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3956
eval { $dbi->execute("drop table $table1") };
3957
$dbi->execute($create_table1);
3958
eval { $dbi->execute("drop table $table2") };
3959
$dbi->execute($create_table2);
improved test
Yuki Kimoto authored on 2012-03-01
3960
$dbi->setup_model(@$setup_model_args);
cleanup test
Yuki Kimoto authored on 2011-08-15
3961
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3962
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3963
$model = $dbi->model($table1);
3964
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3965
  column => [
improved test
Yuki Kimoto authored on 2012-03-01
3966
    $model->column($table2, {alias => u$table2_alias})
cleanup
Yuki Kimoto authored on 2012-01-20
3967
  ],
improved test
Yuki Kimoto authored on 2012-03-01
3968
  where => {u($table2_alias) . ".$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3969
);
3970
is_deeply($result->one, 
improved test
Yuki Kimoto authored on 2012-03-01
3971
        {u($table2_alias) . ".$key1" => 1, u($table2_alias) . ".$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3972

            
3973
$dbi->separator('__');
3974
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3975
  column => [
improved test
Yuki Kimoto authored on 2012-03-01
3976
    $model->column($table2, {alias => u$table2_alias})
cleanup
Yuki Kimoto authored on 2012-01-20
3977
  ],
improved test
Yuki Kimoto authored on 2012-03-01
3978
  where => {u($table2_alias) . ".$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3979
);
3980
is_deeply($result->one, 
improved test
Yuki Kimoto authored on 2012-03-01
3981
  {u(${table2_alias}) . "__$key1" => 1, u(${table2_alias}) . "__$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3982

            
3983
$dbi->separator('-');
3984
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3985
  column => [
improved test
Yuki Kimoto authored on 2012-03-01
3986
    $model->column($table2, {alias => u$table2_alias})
cleanup
Yuki Kimoto authored on 2012-01-20
3987
  ],
improved test
Yuki Kimoto authored on 2012-03-01
3988
  where => {u($table2_alias) . ".$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3989
);
3990
is_deeply($result->one, 
improved test
Yuki Kimoto authored on 2012-03-01
3991
  {u(${table2_alias}) . "-$key1" => 1, u(${table2_alias}) . "-$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3992

            
3993
test 'create_model';
3994
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3995
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3996
eval { $dbi->execute("drop table $table1") };
3997
eval { $dbi->execute("drop table $table2") };
3998
$dbi->execute($create_table1);
3999
$dbi->execute($create_table2);
4000

            
4001
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
4002
  table => $table1,
4003
  join => [
4004
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
4005
  ],
4006
  primary_key => [$key1]
cleanup test
Yuki Kimoto authored on 2011-08-15
4007
);
4008
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
4009
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
4010
);
4011
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
4012
  table => $table3,
4013
  filter => [
4014
    $key1 => {in => sub { uc $_[0] }}
4015
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
4016
);
improved test
Yuki Kimoto authored on 2012-03-01
4017
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
4018
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4019
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4020
$model = $dbi->model($table1);
4021
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4022
  column => [$model->mycolumn, $model->column($table2)],
4023
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-15
4024
);
4025
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
4026
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
4027
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
4028

            
4029
test 'model method';
4030
$dbi = DBIx::Custom->connect;
4031
eval { $dbi->execute("drop table $table2") };
4032
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4033
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4034
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
4035
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
4036
);
4037
$model->method(foo => sub { shift->select(@_) });
4038
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
4039

            
4040
test 'model helper';
4041
$dbi = DBIx::Custom->connect;
4042
eval { $dbi->execute("drop table $table2") };
4043
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4044
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
4045
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
4046
  table => $table2
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
4047
);
4048
$model->helper(foo => sub { shift->select(@_) });
4049
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
4050

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

            
4058
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4059
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
4060
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4061
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
4062
where $key1 = 1
4063
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
4064
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
4065
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
4066
$rows   = $result->all;
4067
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
4068
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
4069
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
4070

            
4071

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

            
4078
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4079
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
4080
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4081
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
4082
where $key1 = 1
4083
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
4084
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
4085
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
4086
$rows   = $result->all;
4087
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
4088
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
4089
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
4090

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

            
4097
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4098
$assign_clause = $dbi->update_param($param, {no_set => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
4099
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4100
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
4101
where $key1 = 1
4102
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
4103
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
4104
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
4105
$rows   = $result->all;
4106
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
4107
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
4108
  "update param no_set");
cleanup test
Yuki Kimoto authored on 2011-08-15
4109

            
cleanup
Yuki Kimoto authored on 2012-01-20
4110
          
cleanup test
Yuki Kimoto authored on 2011-08-15
4111
$dbi = DBIx::Custom->connect;
4112
eval { $dbi->execute("drop table $table1") };
4113
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4114
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
4115
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
4116

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4117
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4118
$assign_clause = $dbi->assign_param($param);
4119
$sql = <<"EOS";
4120
update $table1 set $assign_clause
4121
where $key1 = 1
4122
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
4123
$dbi->execute($sql, $param, table => $table1);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4124
$result = $dbi->execute("select * from $table1 order by $key1");
4125
$rows   = $result->all;
4126
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
4127
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
4128
  "basic");
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4129

            
4130
$param = {$key2 => 11};
4131
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
4132
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4133
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
4134
where $key1 = 1
4135
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
4136
$dbi->execute($sql, $param, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4137
$result = $dbi->execute("select * from $table1 order by $key1");
4138
$rows   = $result->all;
4139
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
4140
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
4141
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
4142

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4143
test 'Model class';
4144
$dbi = MyDBI1->connect;
4145
eval { $dbi->execute("drop table $table1") };
4146
$dbi->execute($create_table1);
4147
$model = $dbi->model($table1);
4148
$model->insert({$key1 => 'a', $key2 => 'b'});
4149
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4150
eval { $dbi->execute("drop table $table2") };
4151
$dbi->execute($create_table2);
4152
$model = $dbi->model($table2);
4153
$model->insert({$key1 => 'a'});
4154
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4155
is($dbi->models->{$table1}, $dbi->model($table1));
4156
is($dbi->models->{$table2}, $dbi->model($table2));
4157

            
4158
$dbi = MyDBI4->connect;
4159
eval { $dbi->execute("drop table $table1") };
4160
$dbi->execute($create_table1);
4161
$model = $dbi->model($table1);
4162
$model->insert({$key1 => 'a', $key2 => 'b'});
4163
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4164
eval { $dbi->execute("drop table $table2") };
4165
$dbi->execute($create_table2);
4166
$model = $dbi->model($table2);
4167
$model->insert({$key1 => 'a'});
4168
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4169

            
4170
$dbi = MyDBI5->connect;
4171
eval { $dbi->execute("drop table $table1") };
4172
eval { $dbi->execute("drop table $table2") };
4173
$dbi->execute($create_table1);
4174
$dbi->execute($create_table2);
4175
$model = $dbi->model($table2);
4176
$model->insert({$key1 => 'a'});
4177
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
4178
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4179
$model = $dbi->model($table1);
4180
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
4181

            
4182
test 'primary_key';
4183
$dbi = MyDBI1->connect;
4184
$model = $dbi->model($table1);
4185
$model->primary_key([$key1, $key2]);
4186
is_deeply($model->primary_key, [$key1, $key2]);
4187

            
4188
test 'columns';
4189
$dbi = MyDBI1->connect;
4190
$model = $dbi->model($table1);
4191
$model->columns([$key1, $key2]);
4192
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4193

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4194
test 'setup_model';
4195
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
4196
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4197
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4198
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
4199

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4200
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4201
$dbi->execute($create_table2);
improved test
Yuki Kimoto authored on 2012-03-01
4202
$dbi->setup_model(@$setup_model_args);
cleanup test
Yuki Kimoto authored on 2011-08-15
4203
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
4204
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4205

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4206
test 'each_column';
4207
$dbi = DBIx::Custom->connect;
4208
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4209
eval { $dbi->execute("drop table $table1") };
4210
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4211
eval { $dbi->execute("drop table $table3") };
4212
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4213
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4214

            
4215
$infos = [];
4216
$dbi->each_column(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4217
  my ($self, $table, $column, $cinfo) = @_;
4218
  
4219
  if ($table =~ /^table\d/i) {
4220
     my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
4221
     push @$infos, $info;
4222
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4223
});
4224
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4225
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4226
  [
improved tests
Yuki Kimoto authored on 2012-03-01
4227
    [table_only($table1), $key1, $key1],
4228
    [table_only($table1), $key2, $key2],
4229
    [table_only($table2), $key1, $key1],
4230
    [table_only($table2), $key3, $key3]
cleanup
Yuki Kimoto authored on 2012-01-20
4231
  ]
4232
  
cleanup test
Yuki Kimoto authored on 2011-08-10
4233
);
cleanup test
Yuki Kimoto authored on 2011-08-16
4234

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4235
test 'each_table';
4236
$dbi = DBIx::Custom->connect;
4237
eval { $dbi->execute("drop table $table1") };
4238
eval { $dbi->execute("drop table $table2") };
4239
$dbi->execute($create_table2);
4240
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4241

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4242
$infos = [];
4243
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4244
  my ($self, $table, $table_info) = @_;
4245
  
4246
  if ($table =~ /^table\d/i) {
4247
    my $info = [$table, $table_info->{TABLE_NAME}];
4248
    push @$infos, $info;
4249
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4250
});
4251
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4252
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4253
  [
improved tests
Yuki Kimoto authored on 2012-03-01
4254
    [table_only($table1), table_only($table1)],
4255
    [table_only($table2), table_only($table2)],
cleanup
Yuki Kimoto authored on 2012-01-20
4256
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4257
);
4258

            
cleanup test
Yuki Kimoto authored on 2011-08-16
4259
$dbi = DBIx::Custom->connect;
4260
eval { $dbi->execute("drop table $table1") };
4261
eval { $dbi->execute("drop table $table2") };
4262
$dbi->execute($create_table2);
4263
$dbi->execute($create_table1_type);
4264

            
4265
$infos = [];
4266
$dbi->user_table_info($user_table_info);
4267
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4268
  my ($self, $table, $table_info) = @_;
4269
  
4270
  if ($table =~ /^table\d/i) {
4271
     my $info = [$table, $table_info->{TABLE_NAME}];
4272
     push @$infos, $info;
4273
  }
cleanup test
Yuki Kimoto authored on 2011-08-16
4274
});
4275
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4276
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4277
  [
improved tests
Yuki Kimoto authored on 2012-03-01
4278
    [table_only($table1), table_only($table1)],
4279
    [table_only($table2), table_only($table2)],
4280
    [table_only($table3), table_only($table3)],
cleanup
Yuki Kimoto authored on 2012-01-20
4281
  ]
cleanup test
Yuki Kimoto authored on 2011-08-16
4282
);
4283

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4284
test 'type_rule into';
4285
eval { $dbi->execute("drop table $table1") };
4286
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4287
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
4288

            
4289

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4290
$dbi = DBIx::Custom->connect;
4291
eval { $dbi->execute("drop table $table1") };
4292
$dbi->execute($create_table1_type);
4293

            
cleanup
Yuki Kimoto authored on 2011-08-16
4294
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4295
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4296
  into1 => {
4297
    $date_typename => sub { '2010-' . $_[0] }
4298
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4299
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4300
$dbi->insert({$key1 => '01-01'}, table => $table1);
4301
$result = $dbi->select(table => $table1);
4302
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4303

            
4304
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4305
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4306
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4307
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4308
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4309
  into1 => [
4310
     [$date_typename, $datetime_typename] => sub {
4311
        my $value = shift;
4312
        $value =~ s/02/03/g;
4313
        return $value;
4314
     }
4315
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
4316
);
4317
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
4318
$result = $dbi->select(table => $table1);
4319
$row = $result->one;
4320
like($row->{$key1}, qr/^2010-01-03/);
4321
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4322

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4323
$dbi = DBIx::Custom->connect;
4324
eval { $dbi->execute("drop table $table1") };
4325
$dbi->execute($create_table1_type);
4326
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4327
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4328
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4329
  into1 => [
4330
    [$date_typename, $datetime_typename] => sub {
4331
      my $value = shift;
4332
      $value =~ s/02/03/g;
4333
      return $value;
4334
    }
4335
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4336
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4337
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
4338
  "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
4339
  {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
4340
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4341
$row = $result->one;
4342
like($row->{$key1}, qr/^2010-01-03/);
4343
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4344

            
4345
$dbi = DBIx::Custom->connect;
4346
eval { $dbi->execute("drop table $table1") };
4347
$dbi->execute($create_table1_type);
4348
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4349
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4350
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4351
  into1 => [
4352
    [$date_typename, $datetime_typename] => sub {
4353
      my $value = shift;
4354
      $value =~ s/02/03/g;
4355
      return $value;
4356
    }
4357
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4358
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4359
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
4360
  "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
4361
  {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
4362
  table => $table1
cleanup test
Yuki Kimoto authored on 2011-08-15
4363
);
4364
$row = $result->one;
4365
like($row->{$key1}, qr/^2010-01-03/);
4366
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4367

            
4368
$dbi = DBIx::Custom->connect;
4369
eval { $dbi->execute("drop table $table1") };
4370
$dbi->execute($create_table1_type);
4371
$dbi->register_filter(convert => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4372
  my $value = shift || '';
4373
  $value =~ s/02/03/;
4374
  return $value;
cleanup test
Yuki Kimoto authored on 2011-08-15
4375
});
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
  from1 => {
4379
    $date_datatype => 'convert',
4380
  },
4381
  into1 => {
4382
      $date_typename => 'convert',
4383
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4384
);
4385
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
4386
$result = $dbi->select(table => $table1);
4387
like($result->fetch->[0], qr/^2010-03-03/);
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
4388
$result = $dbi->select(column => [$key1, $key1], table => $table1);
4389
$row = $result->fetch;
4390
like($row->[0], qr/^2010-03-03/);
4391
like($row->[1], qr/^2010-03-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4392

            
4393
test 'type_rule and filter order';
4394
$dbi = DBIx::Custom->connect;
4395
eval { $dbi->execute("drop table $table1") };
4396
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4397
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4398
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4399
  into1 => {
4400
    $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4401
  },
4402
  into2 => {
4403
    $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4404
  },
4405
  from1 => {
4406
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4407
  },
4408
  from2 => {
4409
    $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
4410
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4411
);
4412
$dbi->insert({$key1 => '2010-01-03'}, 
cleanup
Yuki Kimoto authored on 2012-01-20
4413
table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
cleanup test
Yuki Kimoto authored on 2011-08-15
4414
$result = $dbi->select(table => $table1);
4415
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4416
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4417

            
4418

            
4419
$dbi = DBIx::Custom->connect;
4420
eval { $dbi->execute("drop table $table1") };
4421
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4422
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4423
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4424
  from1 => {
4425
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4426
  },
4427
  from2 => {
4428
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4429
  },
cleanup test
Yuki Kimoto authored on 2011-08-15
4430
);
4431
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4432
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4433
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4434
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4435
  from1 => {
4436
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4437
  },
4438
  from2 => {
4439
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
4440
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4441
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4442
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4443
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4444

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4445
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
4446
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
4447
eval { $dbi->execute("drop table $table1") };
4448
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4449
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4450
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4451
  from1 => {
4452
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4453
  },
4454
  into1 => {
4455
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4456
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4457
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4458
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4459
$result = $dbi->select(table => $table1, type_rule_off => 1);
4460
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4461

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4462
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4463
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4464
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4465
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4466
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4467
  from1 => {
4468
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4469
  },
4470
  into1 => {
4471
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4472
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4473
);
4474
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4475
$result = $dbi->select(table => $table1, type_rule_off => 1);
4476
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4477

            
4478
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4479
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4480
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4481
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4482
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4483
  from1 => {
4484
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4485
  },
4486
  into1 => {
4487
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4488
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4489
);
4490
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4491
$result = $dbi->select(table => $table1);
4492
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4493

            
4494
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4495
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4496
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4497
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4498
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4499
  from1 => {
4500
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4501
  },
4502
  into1 => {
4503
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4504
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4505
);
4506
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4507
$result = $dbi->select(table => $table1);
4508
like($result->fetch->[0], qr/2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4509

            
4510
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4511
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4512
$dbi->execute($create_table1_type);
4513
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
4514
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4515
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4516
  into1 => {
4517
    $date_typename => 'ppp'
4518
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4519
);
4520
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4521
$result = $dbi->select(table => $table1);
4522
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4523

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4524
eval{$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4525
  into1 => {
4526
    $date_typename => 'pp'
4527
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4528
)};
4529
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4530

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4531
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4532
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4533
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4534
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4535
  $dbi->type_rule(
4536
    from1 => {
4537
      Date => sub { $_[0] * 2 },
4538
    }
4539
  );
cleanup test
Yuki Kimoto authored on 2011-08-10
4540
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4541
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4542

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4543
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4544
  $dbi->type_rule(
4545
    into1 => {
4546
      Date => sub { $_[0] * 2 },
4547
    }
4548
  );
cleanup test
Yuki Kimoto authored on 2011-08-15
4549
};
4550
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4551

            
4552
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4553
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4554
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4555
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4556
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4557
  from1 => {
4558
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4559
  },
4560
  into1 => {
4561
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4562
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4563
);
4564
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4565
$result = $dbi->select(table => $table1);
4566
$result->type_rule_off;
4567
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4568

            
4569
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4570
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4571
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4572
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4573
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4574
  from1 => {
4575
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4576
    $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4577
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4578
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4579
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
4580
$result = $dbi->select(table => $table1);
4581
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4582
  from1 => {
4583
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4584
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4585
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4586
$row = $result->one;
4587
like($row->{$key1}, qr/^2010-01-05/);
4588
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4589

            
4590
$result = $dbi->select(table => $table1);
4591
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4592
  from1 => {
4593
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4594
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4595
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4596
$row = $result->one;
4597
like($row->{$key1}, qr/2010-01-05/);
4598
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4599

            
4600
$result = $dbi->select(table => $table1);
4601
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4602
  from1 => {
4603
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4604
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4605
);
4606
$row = $result->one;
4607
like($row->{$key1}, qr/2010-01-05/);
4608
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4609

            
4610
$result = $dbi->select(table => $table1);
4611
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4612
  from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
cleanup test
Yuki Kimoto authored on 2011-08-15
4613
);
4614
$row = $result->one;
4615
like($row->{$key1}, qr/2010-01-05/);
4616
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4617

            
4618
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4619
$result = $dbi->select(table => $table1);
4620
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4621
  from1 => [$date_datatype => 'five']
cleanup test
Yuki Kimoto authored on 2011-08-15
4622
);
4623
$row = $result->one;
4624
like($row->{$key1}, qr/^2010-01-05/);
4625
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4626

            
4627
$result = $dbi->select(table => $table1);
4628
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4629
  from1 => [$date_datatype => undef]
cleanup test
Yuki Kimoto authored on 2011-08-15
4630
);
4631
$row = $result->one;
4632
like($row->{$key1}, qr/^2010-01-03/);
4633
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4634

            
4635
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4636
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4637
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4638
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4639
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4640
  from1 => {
4641
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4642
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4643
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4644
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4645
$result = $dbi->select(table => $table1);
4646
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4647
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4648

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4649
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4650
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4651
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4652
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4653
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4654
  from1 => {
4655
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4656
  },
cleanup test
Yuki Kimoto authored on 2011-08-15
4657
);
4658
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4659
$result = $dbi->select(table => $table1);
4660
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4661
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4662

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4663
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4664
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4665
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4666
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4667
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4668
  into1 => {
4669
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4670
  },
4671
  into2 => {
4672
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4673
  },
4674
  from1 => {
4675
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4676
  },
4677
  from2 => {
4678
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4679
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4680
);
4681
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4682
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4683
like($result->type_rule_off->fetch_one->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4684
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4685
like($result->type_rule_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4686

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4687
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4688
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4689
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4690
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4691
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4692
  into1 => {
4693
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4694
  },
4695
  into2 => {
4696
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4697
  },
4698
  from1 => {
4699
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
4700
  },
4701
  from2 => {
4702
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4703
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4704
);
4705
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4706
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4707
like($result->type_rule1_off->fetch_one->[0], qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4708
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4709
like($result->type_rule1_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4710

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4711
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4712
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4713
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4714
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4715
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4716
  into1 => {
4717
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4718
  },
4719
  into2 => {
4720
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4721
  },
4722
  from1 => {
4723
    $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4724
  },
4725
  from2 => {
4726
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4727
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4728
);
4729
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4730
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4731
like($result->type_rule2_off->fetch_one->[0], qr/^2010-01-06/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4732
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4733
like($result->type_rule2_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4734

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4735
test 'join';
4736
$dbi = DBIx::Custom->connect;
4737
eval { $dbi->execute("drop table $table1") };
4738
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4739
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4740
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4741
eval { $dbi->execute("drop table $table2") };
4742
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4743
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4744
eval { $dbi->execute("drop table $table3") };
4745
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4746
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4747
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4748
  table => $table1,
improved tests
Yuki Kimoto authored on 2012-03-01
4749
  column => "$table1.$key1 as " . u("${table1}_$key1") . ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
4750
  where   => {"$table1.$key2" => 2},
4751
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4752
)->all;
improved tests
Yuki Kimoto authored on 2012-03-01
4753
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4754

            
4755
$dbi = DBIx::Custom->connect;
4756
eval { $dbi->execute("drop table $table1") };
4757
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4758
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4759
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4760
eval { $dbi->execute("drop table $table2") };
4761
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4762
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4763
eval { $dbi->execute("drop table $table3") };
4764
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4765
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4766
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4767
  table => $table1,
improved tests
Yuki Kimoto authored on 2012-03-01
4768
  column => "$table1.$key1 as " . u("${table1}_$key1") . ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
4769
  where   => {"$table1.$key2" => 2},
4770
  join  => {
4771
    clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4772
    table => [$table1, $table2]
4773
  }
added test
Yuki Kimoto authored on 2011-10-27
4774
)->all;
improved tests
Yuki Kimoto authored on 2012-03-01
4775
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4776

            
4777
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4778
  table => $table1,
4779
  where   => {$key1 => 1},
4780
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4781
)->all;
4782
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4783

            
4784
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4785
  table => $table1,
4786
  where   => {$key1 => 1},
4787
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4788
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4789
)->all;
4790
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4791

            
4792
$rows = $dbi->select(
improved tests
Yuki Kimoto authored on 2012-03-01
4793
  column => "$table3.$key4 as " . u2("${table3}__$key4"),
cleanup
Yuki Kimoto authored on 2012-01-20
4794
  table => $table1,
4795
  where   => {"$table1.$key1" => 1},
4796
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4797
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4798
)->all;
improved tests
Yuki Kimoto authored on 2012-03-01
4799
is_deeply($rows, [{u2"${table3}__$key4" => 4}]);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4800

            
4801
$rows = $dbi->select(
improved tests
Yuki Kimoto authored on 2012-03-01
4802
  column => "$table1.$key1 as " . u2("${table1}__$key1"),
cleanup
Yuki Kimoto authored on 2012-01-20
4803
  table => $table1,
4804
  where   => {"$table3.$key4" => 4},
4805
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4806
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4807
)->all;
improved tests
Yuki Kimoto authored on 2012-03-01
4808
is_deeply($rows, [{u2"${table1}__$key1" => 1}]);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4809

            
4810
$dbi = DBIx::Custom->connect;
4811
eval { $dbi->execute("drop table $table1") };
4812
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4813
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4814
eval { $dbi->execute("drop table $table2") };
4815
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4816
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4817
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4818
  table => $table1,
fixed tests for fullqualifie...
Yuki Kimoto authored on 2012-03-02
4819
  column => $dbi->_tq($table1) . ".${q}$key1$p as ${q}" . u("${table1}_$key1") . "$p, " . $dbi->_tq($table2) . ".${q}$key1$p as ${q}" . u("${table2}_$key1") . "$p, ${q}$key2$p, ${q}$key3$p",
cleanup
Yuki Kimoto authored on 2012-01-20
4820
  where   => {"$table1.$key2" => 2},
fixed tests for fullqualifie...
Yuki Kimoto authored on 2012-03-02
4821
  join  => ["left outer join " . $dbi->_tq($table2) . " on " . $dbi->_tq($table1) . ".${q}$key1$p = " . $dbi->_tq($table2) . ".${q}$key1$p"],
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4822
)->all;
fixed tests for fullqualifie...
Yuki Kimoto authored on 2012-03-02
4823
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
cleanup
Yuki Kimoto authored on 2012-01-20
4824
  'quote');
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4825

            
4826

            
4827
$dbi = DBIx::Custom->connect;
4828
eval { $dbi->execute("drop table $table1") };
4829
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4830
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4831
$sql = <<"EOS";
4832
left outer join (
cleanup
Yuki Kimoto authored on 2012-01-20
4833
select * from $table1 t1
added t/common-mysql-qualifi...
Yuki Kimoto authored on 2012-03-02
4834
  where t1.$key2 = (
4835
    select max(t2.$key2) from $table1 t2
4836
    where t1.$key1 = t2.$key1
4837
  )
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4838
) $table3 on $table1.$key1 = $table3.$key1
4839
EOS
added t/common-mysql-qualifi...
Yuki Kimoto authored on 2012-03-02
4840
$sql =~ s/\Q.table3/_table3/g;
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4841
$join = [$sql];
4842
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4843
  table => $table1,
fixed tests for fullqualifie...
Yuki Kimoto authored on 2012-03-02
4844
  column => u($table3) . ".$key1 as " . u2("${table3}__$key1"),
cleanup
Yuki Kimoto authored on 2012-01-20
4845
  join  => $join
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4846
)->all;
fixed tests for fullqualifie...
Yuki Kimoto authored on 2012-03-02
4847
is_deeply($rows, [{u2"${table3}__$key1" => 1}]);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4848

            
4849
$dbi = DBIx::Custom->connect;
4850
eval { $dbi->execute("drop table $table1") };
4851
eval { $dbi->execute("drop table $table2") };
4852
$dbi->execute($create_table1);
4853
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4854
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4855
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4856
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4857
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4858
  table => $table1,
4859
  join => [
4860
    "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4861
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4862
);
4863
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4864
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4865
  table => $table1,
4866
  column => [{$table2 => [$key3]}],
4867
  join => [
4868
    "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4869
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4870
);
4871
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4872
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4873
  table => $table1,
4874
  column => [{$table2 => [$key3]}],
4875
  join => [
4876
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4877
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4878
);
4879
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4880

            
4881
$dbi = DBIx::Custom->connect;
4882
eval { $dbi->execute("drop table $table1") };
4883
eval { $dbi->execute("drop table $table2") };
4884
$dbi->execute($create_table1);
4885
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4886
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4887
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4888
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4889
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4890
  table => $table1,
4891
  column => [{$table2 => [$key3]}],
4892
  join => [
4893
    {
4894
      clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4895
      table => [$table1, $table2]
4896
    }
4897
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4898
);
4899
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4900

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4901
$dbi = DBIx::Custom->connect;
4902
eval { $dbi->execute("drop table $table1") };
4903
eval { $dbi->execute("drop table $table2") };
4904
$dbi->execute($create_table1);
4905
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4906
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4907
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4908
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4909
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4910
  table => $table1,
4911
  column => [{$table2 => [$key3]}],
4912
  join => [
4913
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4914
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4915
);
4916
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4917

            
4918
$dbi = DBIx::Custom->connect;
4919
eval { $dbi->execute("drop table $table1") };
4920
eval { $dbi->execute("drop table $table2") };
4921
$dbi->execute($create_table1);
4922
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4923
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4924
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4925
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4926
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4927
  table => $table1,
4928
  column => [{$table2 => [$key3]}],
4929
  join => [
4930
    "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4931
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4932
);
4933
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4934

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4935
test 'columns';
4936
$dbi = MyDBI1->connect;
4937
$model = $dbi->model($table1);
4938

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4939
test 'count';
4940
$dbi = DBIx::Custom->connect;
4941
eval { $dbi->execute("drop table $table1") };
4942
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4943
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4944
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4945
is($dbi->count(table => $table1), 2);
4946
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4947
$model = $dbi->create_model(table => $table1);
4948
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4949

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4950
eval { $dbi->execute("drop table $table1") };
4951
eval { $dbi->execute("drop table $table2") };
4952
$dbi->execute($create_table1);
4953
$dbi->execute($create_table2);
4954
$model = $dbi->create_model(table => $table1, primary_key => $key1);
4955
$model->insert({$key1 => 1, $key2 => 2});
4956
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
4957
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4958
$model->insert({$key1 => 1, $key3 => 3});
4959
is($model->count(id => 1), 1);
4960
is($model->count(where => {"$table2.$key3" => 3}), 1);
4961

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