DBIx-Custom / t / common.t /
Newer Older
4963 lines | 161.923kb
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);
added t/common-mysql-qualifi...
Yuki Kimoto authored on 2012-03-02
3964
$DB::single = 1;
cleanup test
Yuki Kimoto authored on 2011-08-15
3965
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3966
  column => [
improved test
Yuki Kimoto authored on 2012-03-01
3967
    $model->column($table2, {alias => u$table2_alias})
cleanup
Yuki Kimoto authored on 2012-01-20
3968
  ],
improved test
Yuki Kimoto authored on 2012-03-01
3969
  where => {u($table2_alias) . ".$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3970
);
3971
is_deeply($result->one, 
improved test
Yuki Kimoto authored on 2012-03-01
3972
        {u($table2_alias) . ".$key1" => 1, u($table2_alias) . ".$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3973

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

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

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

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

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

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

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

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

            
4072

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4290

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

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

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

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

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

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

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

            
4419

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4827

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

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

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

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

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

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

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

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

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