DBIx-Custom / t / common.t /
Newer Older
4961 lines | 161.642kb
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;
78

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
199
  use base 'MyModel2::Base1';
200

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

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

            
209

            
210
  package MyModel2::main::table1;
211

            
212
  use strict;
213
  use warnings;
214

            
215
  use base 'MyModel2::Base1';
216

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

            
223
  sub list { shift->select; }
224

            
225
  package MyModel2::main::table2;
226

            
227
  use strict;
228
  use warnings;
229

            
230
  use base 'MyModel2::Base1';
231

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

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

            
240
  package MyModel2::dbix_custom::table1;
241

            
242
  use strict;
243
  use warnings;
244

            
245
  use base 'MyModel2::Base1';
246

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

            
253
  sub list { shift->select; }
254

            
255
  package MyModel2::dbix_custom::table2;
256

            
257
  use strict;
258
  use warnings;
259

            
260
  use base 'MyModel2::Base1';
261

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1422
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1423
  table => [$table1, $table2],
fixed test
Yuki Kimoto authored on 2012-03-01
1424
  column => ["$table1.$key1 as " . u("${table1}_$key1") . ", ${table2}.$key1 as " . u("${table2}_$key1"), $key2, $key3],
cleanup
Yuki Kimoto authored on 2012-01-20
1425
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1426
)->all;
fixed test
Yuki Kimoto authored on 2012-03-01
1427
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
1428

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1558

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

            
1564
$dbi->begin_work;
1565

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

            
1572
$dbi->rollback if $@;
1573

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

            
1578
$dbi->begin_work;
1579

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

            
1585
$dbi->commit unless $@;
1586

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2198

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

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

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

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

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

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

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

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

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

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

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

            
2271
$dbi->apply_filter(
2272

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2461
test 'select_at';
2462
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2463
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2464
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2465
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2466
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2467
  table => $table1,
2468
  primary_key => [$key1, $key2],
2469
  where => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2470
);
2471
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2472
is($row->{$key1}, 1);
2473
is($row->{$key2}, 2);
2474
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2475

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

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

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

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

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

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

            
2558

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2775

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2954

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

            
2970

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

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

            
2991

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

            
3010

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

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

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

            
3050

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

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

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

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

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

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

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

            
3146

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

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

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

            
3173

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3745

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3866

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4070

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4288

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

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

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

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

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

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

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

            
4417

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4825

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

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

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

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

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

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

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

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

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