DBIx-Custom / t / common.t /
Newer Older
5027 lines | 163.561kb
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 DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
8
$ENV{DBIX_CUSTOM_SUPPRESS_DEPRECATION} = '0.25';
9

            
added common test executing ...
Yuki Kimoto authored on 2011-08-07
10
my $dbi;
11

            
12
plan skip_all => $ENV{DBIX_CUSTOM_SKIP_MESSAGE} || 'common.t is always skipped'
13
  unless $ENV{DBIX_CUSTOM_TEST_RUN}
14
    && eval { $dbi = DBIx::Custom->connect; 1 };
15

            
16
plan 'no_plan';
17

            
finished oracle test
Yuki Kimoto authored on 2011-08-15
18
sub test { print "# $_[0]\n" }
19

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
200
  use base 'MyModel2::Base1';
201

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

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

            
210

            
211
  package MyModel2::main::table1;
212

            
213
  use strict;
214
  use warnings;
215

            
216
  use base 'MyModel2::Base1';
217

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

            
224
  sub list { shift->select; }
225

            
226
  package MyModel2::main::table2;
227

            
228
  use strict;
229
  use warnings;
230

            
231
  use base 'MyModel2::Base1';
232

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

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

            
241
  package MyModel2::dbix_custom::table1;
242

            
243
  use strict;
244
  use warnings;
245

            
246
  use base 'MyModel2::Base1';
247

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

            
254
  sub list { shift->select; }
255

            
256
  package MyModel2::dbix_custom::table2;
257

            
258
  use strict;
259
  use warnings;
260

            
261
  use base 'MyModel2::Base1';
262

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1560

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

            
1566
$dbi->begin_work;
1567

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

            
1574
$dbi->rollback if $@;
1575

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

            
1580
$dbi->begin_work;
1581

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

            
1587
$dbi->commit unless $@;
1588

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2200

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

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

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

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

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

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

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

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

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

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

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

            
2273
$dbi->apply_filter(
2274

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2560

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2777

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

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

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

            
fixed bug that when id optio...
Yuki Kimoto authored on 2012-07-11
2821
$dbi->insert(
2822
  {$key3 => 3},
2823
  primary_key => [$key1, $key2], 
2824
  table => $table1,
2825
  id => [1, 2],
2826
);
2827
is($dbi->select(table => $table1)->one->{$key1}, 1);
2828
is($dbi->select(table => $table1)->one->{$key2}, 2);
2829
is($dbi->select(table => $table1)->one->{$key3}, 3);
2830

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2831
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2832
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2833
  {$key2 => 2, $key3 => 3},
2834
  primary_key => $key1, 
2835
  table => $table1,
2836
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2837
);
2838

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

            
fixed bug that when id optio...
Yuki Kimoto authored on 2012-07-11
2843
$dbi = DBIx::Custom->connect;
2844
eval { $dbi->execute("drop table $table1") };
2845
$dbi->execute($create_table1_2);
2846
$dbi->insert(
2847
  {$key3 => 3},
2848
  primary_key => $key1, 
2849
  table => $table1,
2850
  id => bless({value => 1}, 'AAAA'),
2851
  filter => {$key1 => sub { shift->{value} }}
2852
);
2853
is($dbi->select(table => $table1)->one->{$key1}, 1);
2854
is($dbi->select(table => $table1)->one->{$key3}, 3);
2855

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2856
$dbi = DBIx::Custom->connect;
2857
eval { $dbi->execute("drop table $table1") };
2858
$dbi->execute($create_table1_2);
2859
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2860
  {$key3 => 3},
2861
  primary_key => [$key1, $key2], 
2862
  table => $table1,
2863
  id => 1,
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2864
);
2865
is($dbi->select(table => $table1)->one->{$key1}, 1);
2866
ok(!$dbi->select(table => $table1)->one->{$key2});
2867
is($dbi->select(table => $table1)->one->{$key3}, 3);
2868

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2869
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2870
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2871
$dbi->execute($create_table1_2);
2872
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2873
  {$key3 => 3},
2874
  primary_key => [$key1, $key2], 
2875
  table => $table1,
2876
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2877
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2878
is($dbi->select(table => $table1)->one->{$key1}, 1);
2879
is($dbi->select(table => $table1)->one->{$key2}, 2);
2880
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2881

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2882
$dbi = DBIx::Custom->connect;
2883
eval { $dbi->execute("drop table $table1") };
2884
$dbi->execute($create_table1_2);
2885
$param = {$key3 => 3, $key2 => 4};
2886
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2887
  $param,
2888
  primary_key => [$key1, $key2], 
2889
  table => $table1,
2890
  id => [1, 2],
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2891
);
2892
is($dbi->select(table => $table1)->one->{$key1}, 1);
2893
is($dbi->select(table => $table1)->one->{$key2}, 4);
2894
is($dbi->select(table => $table1)->one->{$key3}, 3);
2895
is_deeply($param, {$key3 => 3, $key2 => 4});
2896

            
added test
Yuki Kimoto authored on 2011-10-25
2897
$dbi = DBIx::Custom->connect;
2898
eval { $dbi->execute("drop table $table1") };
2899
$dbi->execute($create_table1_2);
2900
$param = {$key3 => 3, $key2 => 4};
2901
$query = $dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2902
  $param,
2903
  primary_key => [$key1, $key2], 
2904
  table => $table1,
2905
  id => [1, 2],
2906
  query => 1
added test
Yuki Kimoto authored on 2011-10-25
2907
);
micro optimization
Yuki Kimoto authored on 2011-11-16
2908
ok(ref $query);
added test
Yuki Kimoto authored on 2011-10-25
2909
is_deeply($param, {$key3 => 3, $key2 => 4});
2910

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

            
2925
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2926
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2927
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2928
$dbi->model($table1)->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2929
  {$key3 => 3},
2930
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2931
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2932
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2933
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2934
is($row->{$key1}, 1);
2935
is($row->{$key2}, 2);
2936
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2937

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2953
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2954
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2955
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2956
  {$key3 => 4},
2957
  table => $table1,
2958
  primary_key => $key1,
2959
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2960
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2961
is($dbi->select(table => $table1)->one->{$key1}, 0);
2962
is($dbi->select(table => $table1)->one->{$key2}, 2);
2963
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2964

            
2965
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2966
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2967
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2968
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2969
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2970
  {$key3 => 4},
2971
  table => $table1,
2972
  primary_key => [$key1, $key2],
2973
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2974
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2975
is($dbi->select(table => $table1)->one->{$key1}, 1);
2976
is($dbi->select(table => $table1)->one->{$key2}, 2);
2977
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2978

            
2979

            
2980
test 'model update and id option';
2981
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2982
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2983
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2984
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2985
$dbi->model($table1)->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2986
  {$key3 => 4},
2987
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2988
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2989
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2990
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2991
is($row->{$key1}, 1);
2992
is($row->{$key2}, 2);
2993
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2994

            
2995

            
2996
test 'delete and id option';
2997
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2998
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2999
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
3000
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3001
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
3002
  table => $table1,
3003
  primary_key => [$key1, $key2],
3004
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
3005
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3006
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
3007

            
cleanup
Yuki Kimoto authored on 2011-11-01
3008
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3009
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
3010
  table => $table1,
3011
  primary_key => $key1,
3012
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
3013
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3014
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
3015

            
3016

            
3017
test 'model delete and id option';
3018
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3019
eval { $dbi->execute("drop table $table1") };
3020
eval { $dbi->execute("drop table $table2") };
3021
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3022
$dbi->execute($create_table1_2);
3023
$dbi->execute($create_table2_2);
3024
$dbi->execute($create_table3);
cleanup
Yuki Kimoto authored on 2011-11-01
3025
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3026
$dbi->model($table1)->delete(id => [1, 2]);
3027
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
3028
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3029
$dbi->model($table1)->delete(id => [1, 2]);
3030
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
3031
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3032
$dbi->model($table3)->delete(id => [1, 2]);
3033
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
3034

            
3035

            
3036
test 'select and id option';
3037
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3038
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3039
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
3040
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3041
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3042
  table => $table1,
3043
  primary_key => [$key1, $key2],
3044
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
3045
);
3046
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3047
is($row->{$key1}, 1);
3048
is($row->{$key2}, 2);
3049
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
3050

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3051
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3052
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3053
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3054
  table => $table1,
3055
  primary_key => $key1,
3056
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
3057
);
3058
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3059
is($row->{$key1}, 0);
3060
is($row->{$key2}, 2);
3061
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
3062

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3063
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3064
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3065
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3066
  table => $table1,
3067
  primary_key => [$key1, $key2],
3068
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
3069
);
3070
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3071
is($row->{$key1}, 1);
3072
is($row->{$key2}, 2);
3073
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
3074

            
3075

            
3076
test 'model select_at';
3077
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3078
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3079
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
3080
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3081
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3082
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3083
is($row->{$key1}, 1);
3084
is($row->{$key2}, 2);
3085
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
3086

            
3087
test 'column separator is default .';
3088
$dbi = MyDBI7->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);
fixed setup method logic
Yuki Kimoto authored on 2012-03-02
3094
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3095
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3096
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3097
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3098
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3099
  column => [$model->column($table2)],
3100
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3101
);
3102
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3103
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
3104

            
3105
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3106
  column => [$model->column($table2 => [$key1, $key3])],
3107
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3108
);
3109
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3110
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3111

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3112
test 'separator';
3113
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3114
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3115
eval { $dbi->execute("drop table $table1") };
3116
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3117
$dbi->execute($create_table1);
3118
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
3119

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3120
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3121
  table => $table1,
3122
  join => [
3123
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3124
  ],
3125
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
3126
);
3127
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3128
  table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
3129
);
fixed setup method logic
Yuki Kimoto authored on 2012-03-02
3130
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3131
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3132
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3133
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3134
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3135
  column => [
3136
    $model->mycolumn,
3137
    {$table2 => [$key1, $key3]}
3138
  ],
3139
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3140
);
3141
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3142
        {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3143
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3144

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3145
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3146
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3147
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3148
  column => [
3149
    $model->mycolumn,
3150
    {$table2 => [$key1, $key3]}
3151
  ],
3152
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3153
);
3154
is_deeply($result->one,
improved test
Yuki Kimoto authored on 2012-03-01
3155
        {$key1 => 1, $key2 => 2, u2"${table2}__$key1" => 1, u2"${table2}__$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3156
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3157

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3158
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3159
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3160
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3161
  column => [
3162
    $model->mycolumn,
3163
    {$table2 => [$key1, $key3]}
3164
  ],
3165
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3166
);
3167
is_deeply($result->one,
improved test
Yuki Kimoto authored on 2012-03-01
3168
  {$key1 => 1, $key2 => 2, hy"$table2-$key1" => 1, hy"$table2-$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3169
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3170

            
3171

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3172
test 'filter_off';
3173
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3174
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3175
eval { $dbi->execute("drop table $table1") };
3176
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3177
$dbi->execute($create_table1);
3178
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
3179

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3180
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3181
  table => $table1,
3182
  join => [
3183
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3184
  ],
3185
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
3186
);
fixed setup method logic
Yuki Kimoto authored on 2012-03-02
3187
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3188
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3189
$model = $dbi->model($table1);
3190
$result = $model->select(column => $key1);
3191
$result->filter($key1 => sub { $_[0] * 2 });
3192
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
3193

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3194
test 'available_datetype';
3195
$dbi = DBIx::Custom->connect;
3196
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
3197

            
3198

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3199
test 'select prefix option';
3200
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3201
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3202
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3203
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3204
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3205
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
3206

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

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

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3218
$dbi = DBIx::Custom->connect;
3219
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3220
  id => {key => "$table1.id"},
3221
  author => ["$table1.author" => $dbi->like_value],
3222
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3223
);
3224
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3225
"$table1.price" => 1900});
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3226

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

            
3234
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3235
  id => {key => "$table1.id"},
3236
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3237
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
added tests
Yuki Kimoto authored on 2011-08-26
3238
);
3239
is_deeply($param, {});
3240

            
3241
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3242
  id => {key => "$table1.id"},
3243
  price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
3244
);
3245
is_deeply($param, {"$table1.price" => undef});
3246

            
3247
$param = $dbi->mapper(param => {price => 'a'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3248
  id => {key => "$table1.id", condition => 'exists'},
3249
  price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
3250
);
3251
is_deeply($param, {"$table1.price" => '%a'});
3252

            
3253
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3254
  id => {key => "$table1.id"},
3255
  price => ["$table1.price", sub { '%' . $_[0] }]
added tests
Yuki Kimoto authored on 2011-08-26
3256
);
3257
is_deeply($param, {"$table1.price" => '%a'});
3258

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3259
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3260
  price => sub { '%' . $_[0] },
3261
  author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
3262
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3263
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
3264

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

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

            
3278
$where = $dbi->where;
3279
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
3280
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
3281
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
3282
$row = $result->all;
3283
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3284
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
3285
$row = $result->all;
3286
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3287

            
3288
$where = $dbi->where;
3289
$where->clause(['and', ":${key1}{=}"]);
3290
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
3291
$where->param($param);
3292
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
3293
$row = $result->all;
3294
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3295
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
3296
$row = $result->all;
3297
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3298

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3300
$where = $dbi->where;
3301
$where->clause(['and', ":${key1}{=}"]);
3302
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
cleanup
Yuki Kimoto authored on 2012-01-20
3303
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3304
$where->param($param);
3305
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3306
$row = $result->all;
3307
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3308

            
3309
$where = $dbi->where;
3310
$where->clause(['and', ":${key1}{=}"]);
3311
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
3312
$where->param($param);
3313
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3314
$row = $result->all;
3315
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3316

            
3317
$where = $dbi->where;
3318
$where->clause(['and', ":${key1}{=}"]);
3319
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
cleanup
Yuki Kimoto authored on 2012-01-20
3320
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3321
$where->param($param);
3322
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3323
$row = $result->all;
3324
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3325

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3327
$where = $dbi->where;
3328
$where->clause(['and', ":${key1}{=}"]);
3329
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
3330
$where->param($param);
3331
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3332
$row = $result->all;
3333
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3334

            
3335
$where = $dbi->where;
3336
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3337
  id => {key => "$table1.id"},
3338
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3339
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3340
);
3341
$where->param($param);
3342
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3343
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3344

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

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

            
3363
$where = $dbi->where;
3364
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3365
  id => {key => "$table1.id"},
3366
  price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3367
);
3368
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
3369

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

            
3377
$where = $dbi->where;
3378
$param = $dbi->mapper(param => {id => [1, 2], author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3379
  id => {key => "$table1.id"},
3380
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3381
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3382
);
3383
is_deeply($param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3384
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3385

            
3386
$where = $dbi->where;
3387
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900}, condition => 'length')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3388
  id => {key => "$table1.id"},
3389
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3390
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3391
);
3392
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3393
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3394

            
3395
$where = $dbi->where;
3396
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3397
  id => {key => "$table1.id", condition => 'length'},
3398
  author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
3399
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3400
);
3401
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3402
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3403

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

            
- DBIx::Custom::Mapper::map ...
Yuki Kimoto authored on 2012-02-29
3409
$param = $dbi->mapper(param => {author => 'Ken',})->map(
3410
  author => ["$table1.author" => '%<value>%'],
3411
);
3412
is_deeply($param, {"$table1.author" => '%Ken%'});
3413

            
3414
$param = $dbi->mapper(param => {author => 'Ken'})->map(
3415
  author => ["$table1.author" => 'p'],
3416
);
3417
is_deeply($param, {"$table1.author" => 'p'});
3418

            
3419
$param = $dbi->mapper(param => {author => 'Ken',})->map(
3420
  author => {value => '%<value>%'}
3421
);
3422
is_deeply($param, {"author" => '%Ken%'});
3423

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3424
test 'order';
3425
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3426
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3427
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3428
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3429
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3430
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3431
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3432
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3433
$order->prepend($key1, "$key2 desc");
3434
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3435
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
3436
{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3437
$order->prepend("$key1 desc");
3438
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3439
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
cleanup
Yuki Kimoto authored on 2012-01-20
3440
{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3441

            
3442
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3443
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3444
$result = $dbi->select(table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
3445
column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
3446
append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3447
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
cleanup
Yuki Kimoto authored on 2012-01-20
3448
{"$table1-$key1" => 1, "$table1-$key2" => 1},
3449
{"$table1-$key1" => 2, "$table1-$key2" => 4},
3450
{"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3451

            
3452
test 'tag_parse';
3453
$dbi = DBIx::Custom->connect;
3454
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3455
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3456
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3457
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3458
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3459
ok($@);
3460

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3461
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3462
{
cleanup
Yuki Kimoto authored on 2012-01-20
3463
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3464
  $dbi = DBIx::Custom->connect;
3465
  eval { $dbi->execute("drop table $table1") };
3466
  $dbi->execute($create_table1);
3467
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3468
  eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3469
  ok($@);
3470
  eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) };
3471
  ok($@);
3472
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3473
}
3474

            
3475
{
cleanup
Yuki Kimoto authored on 2012-01-20
3476
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3477
  $dbi = DBIx::Custom->connect;
3478
  eval { $dbi->execute("drop table $table1") };
3479
  $dbi->execute($create_table1);
3480
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3481
  is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1);
3482
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3483
}
3484

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3485
test 'last_sql';
3486
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3487
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3488
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3489
$dbi->execute("select * from $table1");
micro optimization
Yuki Kimoto authored on 2011-11-18
3490
is($dbi->last_sql, " select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3491

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3523
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3524
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
3525
  $source,
3526
  {"$table1.$key1" => 1, "$table1.$key2" => 1},
3527
  filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3528
);
3529
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3530
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3531

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

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3553
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3554
$dbi->execute($create_table1_highperformance);
3555
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3556
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3557
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3558
];
3559
{
cleanup
Yuki Kimoto authored on 2012-01-20
3560
  my $query;
3561
  my $sth;
3562
  for my $row (@$rows) {
3563
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3564
    $sth ||= $query->{sth};
3565
    $sth->execute(map { $row->{$_} } sort keys %$row);
3566
  }
3567
  is_deeply($dbi->select(table => $table1)->all,
3568
    [
3569
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3570
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3571
    ]
3572
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3573
}
3574

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3575
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3576
$dbi->execute($create_table1_highperformance);
3577
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3578
  {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
3579
  {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3580
];
3581
{
cleanup
Yuki Kimoto authored on 2012-01-20
3582
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3583
  my $query;
3584
  for my $row (@$rows) {
3585
    $query ||= $model->insert($row, query => 1);
3586
    $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3587
  }
3588
  is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3589
    [
3590
      {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3591
      {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
3592
    ]
3593
  );
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3594
}
3595

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3596
eval { $dbi->execute("drop table $table1") };
3597
$dbi->execute($create_table1);
3598
{
cleanup
Yuki Kimoto authored on 2012-01-20
3599
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3600
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3601
  eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3602
  like($@, qr/primary_key/);
3603
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3604
}
3605

            
3606
{
cleanup
Yuki Kimoto authored on 2012-01-20
3607
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3608
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3609
  $model->insert({$key1 => 1});
3610
  $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3611
    table => $table1, primary_key => $key1);
3612
  is($result->one->{$key1}, 1);
3613
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3614
}
3615

            
3616
eval { $dbi->execute("drop table $table1") };
3617
$dbi->execute($create_table1);
3618
{
cleanup
Yuki Kimoto authored on 2012-01-20
3619
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3620
  $model->insert({$key1 => 1});
3621
  eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3622
  is($result->one->{$key1}, 1);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3623
}
3624

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3625
test 'id option more';
3626
eval { $dbi->execute("drop table $table1") };
3627
$dbi->execute($create_table1_highperformance);
3628
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3629
  $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
3630
};
3631
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3632
$model->insert($row);
3633
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3634
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3635
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3636
  {$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
3637
);
3638

            
3639
eval { $dbi->execute("drop table $table1") };
3640
eval { $dbi->execute("drop table $table2") };
3641
$dbi->execute($create_table1);
3642
$dbi->execute($create_table2);
3643
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3644
$model->insert({$key1 => 1, $key2 => 2});
3645
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
3646
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3647
$model->insert({$key1 => 1, $key3 => 3});
3648
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3649
  column => {$table1 => ["$key2"]},
3650
  id => 1
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3651
);
3652
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3653

            
3654
eval { $dbi->execute("drop table $table1") };
3655
$dbi->execute($create_table1_highperformance);
3656
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3657
  $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
3658
};
3659
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3660
$model->insert($row);
3661
$query = $model->delete(id => 1, query => 1);
3662
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3663
is_deeply($dbi->select(table => $table1)->all, []);
3664

            
3665
eval { $dbi->execute("drop table $table1") };
3666
eval { $dbi->execute($create_table1_highperformance) };
3667
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3668
  $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
3669
};
3670
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3671
$model->insert($row);
3672
$query = $model->select(id => 1, query => 1);
3673
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3674
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3675
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3676
  {$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
3677
);
3678

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3679
test 'result';
3680
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3681
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3682
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3683
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3684
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
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 = ();
3688
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
3689
  push @rows, [@$row];
test cleanup
Yuki Kimoto authored on 2011-08-10
3690
}
3691
is_deeply(\@rows, [[1, 2], [3, 4]]);
3692

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3693
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3694
@rows = ();
3695
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
3696
  push @rows, {%$row};
test cleanup
Yuki Kimoto authored on 2011-08-10
3697
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3698
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3699

            
3700
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3701
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3702
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3703
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3704
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3705

            
3706
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3707
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3708
$rows = $result->fetch_all;
3709
is_deeply($rows, [[1, 2], [3, 4]]);
3710

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3715
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3716
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3717
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3718
$rows = $result->fetch_all;
3719
is_deeply($rows, [[3, 2], [9, 4]], "array");
3720

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2012-02-28
3733
test 'flat';
3734
$result = $dbi->select(table => $table1);
3735
$rows = [$result->flat];
3736
is_deeply($rows, [1, 2, 3, 4]);
3737

            
added EXPERIMETAL DBIx::Cust...
Yuki Kimoto authored on 2012-02-28
3738
test 'kv';
3739
$dbi = DBIx::Custom->connect;
3740
eval { $dbi->execute("drop table $table1") };
3741
$dbi->execute($create_table1);
3742
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3743
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3744

            
3745
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key1");
3746
$rows = $result->kv;
3747
is_deeply($rows, {0 => {$key2 => 2}, 3 => {$key2 => 4}});
3748

            
3749
$dbi = DBIx::Custom->connect;
3750
eval { $dbi->execute("drop table $table1") };
3751
$dbi->execute($create_table1);
3752
$dbi->insert({$key1 => 0, $key2 => 1}, table => $table1);
3753
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3754
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3755
$dbi->insert({$key1 => 3, $key2 => 5}, table => $table1);
3756

            
3757
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key2");
3758
$rows = $result->kv(multi => 1);
3759
is_deeply($rows, {
3760
  0 => [
3761
    {$key2 => 1},
3762
    {$key2 => 2}
3763
  ],
3764
  3 => [
3765
    {$key2 => 4},
3766
    {$key2 => 5}
3767
  ]
3768
});
3769

            
3770

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3771
test 'DBIx::Custom::Result fetch_multi';
3772
eval { $dbi->execute("drop table $table1") };
3773
$dbi->execute($create_table1);
3774
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3775
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3776
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3777
$result = $dbi->select(table => $table1);
3778
$rows = $result->fetch_multi(2);
3779
is_deeply($rows, [[1, 2], [3, 4]]);
3780
$rows = $result->fetch_multi(2);
3781
is_deeply($rows, [[5, 6]]);
3782
$rows = $result->fetch_multi(2);
3783
ok(!$rows);
3784

            
3785
test 'DBIx::Custom::Result fetch_hash_multi';
3786
eval { $dbi->execute("drop table $table1") };
3787
$dbi->execute($create_table1);
3788
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3789
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3790
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3791
$result = $dbi->select(table => $table1);
3792
$rows = $result->fetch_hash_multi(2);
3793
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3794
$rows = $result->fetch_hash_multi(2);
3795
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3796
$rows = $result->fetch_hash_multi(2);
3797
ok(!$rows);
3798

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3799
test "query_builder";
3800
$datas = [
cleanup
Yuki Kimoto authored on 2012-01-20
3801
  # Basic tests
3802
  {   name            => 'placeholder basic',
3803
    source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
3804
    sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
3805
    columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3806
  },
3807
  {
3808
    name            => 'placeholder in',
3809
    source            => "{in k1 3}",
3810
    sql_expected    => "k1 in (?, ?, ?)",
3811
    columns_expected   => [qw/k1 k1 k1/]
3812
  },
3813
  
3814
  # Table name
3815
  {
3816
    name            => 'placeholder with table name',
3817
    source            => "{= a.k1} {= a.k2}",
3818
    sql_expected    => "a.k1 = ? a.k2 = ?",
3819
    columns_expected  => [qw/a.k1 a.k2/]
3820
  },
3821
  {   
3822
    name            => 'placeholder in with table name',
3823
    source            => "{in a.k1 2} {in b.k2 2}",
3824
    sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
3825
    columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3826
  },
3827
  {
3828
    name            => 'not contain tag',
3829
    source            => "aaa",
3830
    sql_expected    => "aaa",
3831
    columns_expected  => [],
3832
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3833
];
3834

            
3835
for (my $i = 0; $i < @$datas; $i++) {
cleanup
Yuki Kimoto authored on 2012-01-20
3836
  my $data = $datas->[$i];
3837
  my $dbi = DBIx::Custom->new;
3838
  my $builder = $dbi->query_builder;
3839
  my $query = $builder->build_query($data->{source});
3840
  is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3841
  is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3842
}
3843

            
cleanup
Yuki Kimoto authored on 2011-08-13
3844
$dbi = DBIx::Custom->new;
3845
$builder = $dbi->query_builder;
3846
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
3847
  p => sub {
3848
    my @args = @_;
3849
    
3850
    my $expand    = "? $args[0] $args[1]";
3851
    my $columns = [2];
3852
    return [$expand, $columns];
3853
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3854
);
3855

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3866
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3867
  q => 'string'
test cleanup
Yuki Kimoto authored on 2011-08-10
3868
});
3869

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3873
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3874
  r => sub {} 
test cleanup
Yuki Kimoto authored on 2011-08-10
3875
});
3876

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

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

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

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

            
3891

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3892
test 'Default tag Error case';
3893
eval{$builder->build_query("{= }")};
fixed bug that when id optio...
Yuki Kimoto authored on 2012-07-11
3894
like($@, qr/\QColumn name must be specified in tag "{= }"/, "basic '=' : key not exist");
cleanup test
Yuki Kimoto authored on 2011-08-15
3895

            
3896
eval{$builder->build_query("{in }")};
fixed bug that when id optio...
Yuki Kimoto authored on 2012-07-11
3897
like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/, "in : key not exist");
cleanup test
Yuki Kimoto authored on 2011-08-15
3898

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

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

            
3907
test 'variouse source';
3908
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3909
$query = $builder->build_query($source);
3910
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3911

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

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

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

            
3924
$source = "a {= b} }";
3925
eval{$builder->build_query($source)};
3926
like($@, qr/unexpected "}"/, "error : 1");
3927

            
3928
$source = "a {= {}";
3929
eval{$builder->build_query($source)};
fixed bug that when id optio...
Yuki Kimoto authored on 2012-07-11
3930
like($@, qr/\Qunexpected "{"/, "error : 2");
cleanup test
Yuki Kimoto authored on 2011-08-15
3931

            
3932
test 'select() sqlfilter option';
3933
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3934
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3935
eval { $dbi->execute("drop table $table1") };
3936
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3937
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3938
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3939
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3940
  table => $table1,
3941
  column => $key1,
3942
  sqlfilter => sub {
3943
    my $sql = shift;
3944
    $sql = "select * from ( $sql ) t where $key1 = 1";
3945
    return $sql;
3946
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3947
)->all;
3948
is_deeply($rows, [{$key1 => 1}]);
3949

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3950
test 'select() after_build_sql option';
3951
$dbi = DBIx::Custom->connect;
3952
$dbi->user_table_info($user_table_info);
3953
eval { $dbi->execute("drop table $table1") };
3954
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3955
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3956
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3957
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3958
  table => $table1,
3959
  column => $key1,
3960
  after_build_sql => sub {
3961
    my $sql = shift;
3962
    $sql = "select * from ( $sql ) t where $key1 = 1";
3963
    return $sql;
3964
  }
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3965
)->all;
3966
is_deeply($rows, [{$key1 => 1}]);
3967

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3968
test 'dbi method from model';
3969
$dbi = MyDBI9->connect;
3970
eval { $dbi->execute("drop table $table1") };
3971
$dbi->execute($create_table1);
fixed setup method logic
Yuki Kimoto authored on 2012-03-02
3972
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3973
$model = $dbi->model($table1);
3974
eval{$model->execute("select * from $table1")};
3975
ok(!$@);
3976

            
3977
test 'column table option';
3978
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3979
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3980
eval { $dbi->execute("drop table $table1") };
3981
$dbi->execute($create_table1);
3982
eval { $dbi->execute("drop table $table2") };
3983
$dbi->execute($create_table2);
fixed setup method logic
Yuki Kimoto authored on 2012-03-02
3984
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3985
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3986
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3987
$model = $dbi->model($table1);
3988
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3989
  column => [
improved test
Yuki Kimoto authored on 2012-03-01
3990
    $model->column($table2, {alias => u$table2_alias})
cleanup
Yuki Kimoto authored on 2012-01-20
3991
  ],
improved test
Yuki Kimoto authored on 2012-03-01
3992
  where => {u($table2_alias) . ".$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3993
);
3994
is_deeply($result->one, 
improved test
Yuki Kimoto authored on 2012-03-01
3995
        {u($table2_alias) . ".$key1" => 1, u($table2_alias) . ".$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3996

            
3997
$dbi->separator('__');
3998
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3999
  column => [
improved test
Yuki Kimoto authored on 2012-03-01
4000
    $model->column($table2, {alias => u$table2_alias})
cleanup
Yuki Kimoto authored on 2012-01-20
4001
  ],
improved test
Yuki Kimoto authored on 2012-03-01
4002
  where => {u($table2_alias) . ".$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
4003
);
4004
is_deeply($result->one, 
improved test
Yuki Kimoto authored on 2012-03-01
4005
  {u(${table2_alias}) . "__$key1" => 1, u(${table2_alias}) . "__$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
4006

            
4007
$dbi->separator('-');
4008
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4009
  column => [
improved test
Yuki Kimoto authored on 2012-03-01
4010
    $model->column($table2, {alias => u$table2_alias})
cleanup
Yuki Kimoto authored on 2012-01-20
4011
  ],
improved test
Yuki Kimoto authored on 2012-03-01
4012
  where => {u($table2_alias) . ".$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
4013
);
4014
is_deeply($result->one, 
improved test
Yuki Kimoto authored on 2012-03-01
4015
  {u(${table2_alias}) . "-$key1" => 1, u(${table2_alias}) . "-$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
4016

            
4017
test 'create_model';
4018
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
4019
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4020
eval { $dbi->execute("drop table $table1") };
4021
eval { $dbi->execute("drop table $table2") };
4022
$dbi->execute($create_table1);
4023
$dbi->execute($create_table2);
4024

            
4025
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
4026
  table => $table1,
4027
  join => [
4028
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
4029
  ],
4030
  primary_key => [$key1]
cleanup test
Yuki Kimoto authored on 2011-08-15
4031
);
4032
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
4033
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
4034
);
4035
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
4036
  table => $table3,
4037
  filter => [
4038
    $key1 => {in => sub { uc $_[0] }}
4039
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
4040
);
fixed setup method logic
Yuki Kimoto authored on 2012-03-02
4041
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
4042
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4043
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4044
$model = $dbi->model($table1);
4045
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4046
  column => [$model->mycolumn, $model->column($table2)],
4047
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-15
4048
);
4049
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
4050
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
4051
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
4052

            
4053
test 'model method';
4054
$dbi = DBIx::Custom->connect;
4055
eval { $dbi->execute("drop table $table2") };
4056
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4057
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4058
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
4059
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
4060
);
4061
$model->method(foo => sub { shift->select(@_) });
4062
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
4063

            
4064
test 'model helper';
4065
$dbi = DBIx::Custom->connect;
4066
eval { $dbi->execute("drop table $table2") };
4067
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4068
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
4069
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
4070
  table => $table2
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
4071
);
4072
$model->helper(foo => sub { shift->select(@_) });
4073
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
4074

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

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

            
4095

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
4134
          
cleanup test
Yuki Kimoto authored on 2011-08-15
4135
$dbi = DBIx::Custom->connect;
4136
eval { $dbi->execute("drop table $table1") };
4137
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4138
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
4139
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
4140

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4141
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4142
$assign_clause = $dbi->assign_param($param);
4143
$sql = <<"EOS";
4144
update $table1 set $assign_clause
4145
where $key1 = 1
4146
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
4147
$dbi->execute($sql, $param, table => $table1);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4148
$result = $dbi->execute("select * from $table1 order by $key1");
4149
$rows   = $result->all;
4150
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
4151
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
4152
  "basic");
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4153

            
4154
$param = {$key2 => 11};
4155
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
4156
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4157
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
4158
where $key1 = 1
4159
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
4160
$dbi->execute($sql, $param, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4161
$result = $dbi->execute("select * from $table1 order by $key1");
4162
$rows   = $result->all;
4163
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
4164
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
4165
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
4166

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4167
test 'Model class';
4168
$dbi = MyDBI1->connect;
4169
eval { $dbi->execute("drop table $table1") };
4170
$dbi->execute($create_table1);
4171
$model = $dbi->model($table1);
4172
$model->insert({$key1 => 'a', $key2 => 'b'});
4173
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4174
eval { $dbi->execute("drop table $table2") };
4175
$dbi->execute($create_table2);
4176
$model = $dbi->model($table2);
4177
$model->insert({$key1 => 'a'});
4178
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4179
is($dbi->models->{$table1}, $dbi->model($table1));
4180
is($dbi->models->{$table2}, $dbi->model($table2));
4181

            
4182
$dbi = MyDBI4->connect;
4183
eval { $dbi->execute("drop table $table1") };
4184
$dbi->execute($create_table1);
4185
$model = $dbi->model($table1);
4186
$model->insert({$key1 => 'a', $key2 => 'b'});
4187
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4188
eval { $dbi->execute("drop table $table2") };
4189
$dbi->execute($create_table2);
4190
$model = $dbi->model($table2);
4191
$model->insert({$key1 => 'a'});
4192
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4193

            
4194
$dbi = MyDBI5->connect;
4195
eval { $dbi->execute("drop table $table1") };
4196
eval { $dbi->execute("drop table $table2") };
4197
$dbi->execute($create_table1);
4198
$dbi->execute($create_table2);
4199
$model = $dbi->model($table2);
4200
$model->insert({$key1 => 'a'});
4201
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
4202
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4203
$model = $dbi->model($table1);
4204
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
4205

            
4206
test 'primary_key';
4207
$dbi = MyDBI1->connect;
4208
$model = $dbi->model($table1);
4209
$model->primary_key([$key1, $key2]);
4210
is_deeply($model->primary_key, [$key1, $key2]);
4211

            
4212
test 'columns';
4213
$dbi = MyDBI1->connect;
4214
$model = $dbi->model($table1);
4215
$model->columns([$key1, $key2]);
4216
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4217

            
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
4218
test 'columns';
4219
$dbi = MyDBI1->connect;
4220
$model = $dbi->model($table1);
4221
$model->columns([$key1, $key2]);
4222
is_deeply($model->columns, [$key1, $key2]);
4223

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4224
test 'setup_model';
4225
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
4226
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4227
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4228
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
4229

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4230
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4231
$dbi->execute($create_table2);
fixed setup method logic
Yuki Kimoto authored on 2012-03-02
4232
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
4233
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
4234
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4235

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4236
test 'each_column';
4237
$dbi = DBIx::Custom->connect;
4238
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4239
eval { $dbi->execute("drop table $table1") };
4240
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4241
eval { $dbi->execute("drop table $table3") };
4242
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4243
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4244

            
4245
$infos = [];
4246
$dbi->each_column(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4247
  my ($self, $table, $column, $cinfo) = @_;
4248
  
4249
  if ($table =~ /^table\d/i) {
4250
     my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
4251
     push @$infos, $info;
4252
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4253
});
4254
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4255
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4256
  [
improved tests
Yuki Kimoto authored on 2012-03-01
4257
    [table_only($table1), $key1, $key1],
4258
    [table_only($table1), $key2, $key2],
4259
    [table_only($table2), $key1, $key1],
4260
    [table_only($table2), $key3, $key3]
cleanup
Yuki Kimoto authored on 2012-01-20
4261
  ]
4262
  
cleanup test
Yuki Kimoto authored on 2011-08-10
4263
);
cleanup test
Yuki Kimoto authored on 2011-08-16
4264

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4265
test 'each_table';
4266
$dbi = DBIx::Custom->connect;
4267
eval { $dbi->execute("drop table $table1") };
4268
eval { $dbi->execute("drop table $table2") };
4269
$dbi->execute($create_table2);
4270
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4271

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

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

            
4295
$infos = [];
4296
$dbi->user_table_info($user_table_info);
4297
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4298
  my ($self, $table, $table_info) = @_;
4299
  
4300
  if ($table =~ /^table\d/i) {
4301
     my $info = [$table, $table_info->{TABLE_NAME}];
4302
     push @$infos, $info;
4303
  }
cleanup test
Yuki Kimoto authored on 2011-08-16
4304
});
4305
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4306
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4307
  [
improved tests
Yuki Kimoto authored on 2012-03-01
4308
    [table_only($table1), table_only($table1)],
4309
    [table_only($table2), table_only($table2)],
4310
    [table_only($table3), table_only($table3)],
cleanup
Yuki Kimoto authored on 2012-01-20
4311
  ]
cleanup test
Yuki Kimoto authored on 2011-08-16
4312
);
4313

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4314
test 'type_rule into';
4315
eval { $dbi->execute("drop table $table1") };
4316
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4317
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
4318

            
4319

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4320
$dbi = DBIx::Custom->connect;
4321
eval { $dbi->execute("drop table $table1") };
4322
$dbi->execute($create_table1_type);
4323

            
cleanup
Yuki Kimoto authored on 2011-08-16
4324
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4325
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4326
  into1 => {
4327
    $date_typename => sub { '2010-' . $_[0] }
4328
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4329
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4330
$dbi->insert({$key1 => '01-01'}, table => $table1);
4331
$result = $dbi->select(table => $table1);
4332
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4333

            
4334
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4335
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4336
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4337
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4338
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4339
  into1 => [
4340
     [$date_typename, $datetime_typename] => sub {
4341
        my $value = shift;
4342
        $value =~ s/02/03/g;
4343
        return $value;
4344
     }
4345
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
4346
);
4347
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
4348
$result = $dbi->select(table => $table1);
4349
$row = $result->one;
4350
like($row->{$key1}, qr/^2010-01-03/);
4351
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4352

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

            
4375
$dbi = DBIx::Custom->connect;
4376
eval { $dbi->execute("drop table $table1") };
4377
$dbi->execute($create_table1_type);
4378
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4379
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4380
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4381
  into1 => [
4382
    [$date_typename, $datetime_typename] => sub {
4383
      my $value = shift;
4384
      $value =~ s/02/03/g;
4385
      return $value;
4386
    }
4387
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4388
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4389
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
4390
  "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
4391
  {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
4392
  table => $table1
cleanup test
Yuki Kimoto authored on 2011-08-15
4393
);
4394
$row = $result->one;
4395
like($row->{$key1}, qr/^2010-01-03/);
4396
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4397

            
4398
$dbi = DBIx::Custom->connect;
4399
eval { $dbi->execute("drop table $table1") };
4400
$dbi->execute($create_table1_type);
4401
$dbi->register_filter(convert => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4402
  my $value = shift || '';
4403
  $value =~ s/02/03/;
4404
  return $value;
cleanup test
Yuki Kimoto authored on 2011-08-15
4405
});
cleanup
Yuki Kimoto authored on 2011-08-16
4406
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4407
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4408
  from1 => {
4409
    $date_datatype => 'convert',
4410
  },
4411
  into1 => {
4412
      $date_typename => 'convert',
4413
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4414
);
4415
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
4416
$result = $dbi->select(table => $table1);
4417
like($result->fetch->[0], qr/^2010-03-03/);
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
4418
$result = $dbi->select(column => [$key1, $key1], table => $table1);
4419
$row = $result->fetch;
4420
like($row->[0], qr/^2010-03-03/);
4421
like($row->[1], qr/^2010-03-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4422

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

            
4448

            
4449
$dbi = DBIx::Custom->connect;
4450
eval { $dbi->execute("drop table $table1") };
4451
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4452
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4453
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4454
  from1 => {
4455
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4456
  },
4457
  from2 => {
4458
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4459
  },
cleanup test
Yuki Kimoto authored on 2011-08-15
4460
);
4461
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4462
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4463
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4464
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4465
  from1 => {
4466
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4467
  },
4468
  from2 => {
4469
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
4470
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4471
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4472
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4473
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4474

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

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

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

            
4524
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4525
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4526
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4527
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4528
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4529
  from1 => {
4530
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4531
  },
4532
  into1 => {
4533
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4534
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4535
);
4536
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4537
$result = $dbi->select(table => $table1);
4538
like($result->fetch->[0], qr/2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4539

            
4540
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4541
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4542
$dbi->execute($create_table1_type);
4543
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
4544
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4545
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4546
  into1 => {
4547
    $date_typename => 'ppp'
4548
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4549
);
4550
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4551
$result = $dbi->select(table => $table1);
4552
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4553

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4554
eval{$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4555
  into1 => {
4556
    $date_typename => 'pp'
4557
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4558
)};
4559
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4560

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4561
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4562
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4563
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4564
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4565
  $dbi->type_rule(
4566
    from1 => {
4567
      Date => sub { $_[0] * 2 },
4568
    }
4569
  );
cleanup test
Yuki Kimoto authored on 2011-08-10
4570
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4571
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4572

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4573
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4574
  $dbi->type_rule(
4575
    into1 => {
4576
      Date => sub { $_[0] * 2 },
4577
    }
4578
  );
cleanup test
Yuki Kimoto authored on 2011-08-15
4579
};
4580
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4581

            
4582
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4583
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4584
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4585
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4586
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4587
  from1 => {
4588
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4589
  },
4590
  into1 => {
4591
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4592
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4593
);
4594
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4595
$result = $dbi->select(table => $table1);
4596
$result->type_rule_off;
4597
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4598

            
4599
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4600
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4601
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4602
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4603
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4604
  from1 => {
4605
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4606
    $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4607
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4608
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4609
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
4610
$result = $dbi->select(table => $table1);
4611
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4612
  from1 => {
4613
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4614
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4615
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4616
$row = $result->one;
4617
like($row->{$key1}, qr/^2010-01-05/);
4618
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4619

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

            
4630
$result = $dbi->select(table => $table1);
4631
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4632
  from1 => {
4633
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4634
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4635
);
4636
$row = $result->one;
4637
like($row->{$key1}, qr/2010-01-05/);
4638
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4639

            
4640
$result = $dbi->select(table => $table1);
4641
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4642
  from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
cleanup test
Yuki Kimoto authored on 2011-08-15
4643
);
4644
$row = $result->one;
4645
like($row->{$key1}, qr/2010-01-05/);
4646
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4647

            
4648
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4649
$result = $dbi->select(table => $table1);
4650
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4651
  from1 => [$date_datatype => 'five']
cleanup test
Yuki Kimoto authored on 2011-08-15
4652
);
4653
$row = $result->one;
4654
like($row->{$key1}, qr/^2010-01-05/);
4655
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4656

            
4657
$result = $dbi->select(table => $table1);
4658
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4659
  from1 => [$date_datatype => undef]
cleanup test
Yuki Kimoto authored on 2011-08-15
4660
);
4661
$row = $result->one;
4662
like($row->{$key1}, qr/^2010-01-03/);
4663
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4664

            
4665
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4666
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4667
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4668
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4669
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4670
  from1 => {
4671
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4672
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4673
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4674
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4675
$result = $dbi->select(table => $table1);
4676
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4677
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4678

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4679
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4680
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4681
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4682
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4683
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4684
  from1 => {
4685
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4686
  },
cleanup test
Yuki Kimoto authored on 2011-08-15
4687
);
4688
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4689
$result = $dbi->select(table => $table1);
4690
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4691
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4692

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4741
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4742
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4743
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4744
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4745
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4746
  into1 => {
4747
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4748
  },
4749
  into2 => {
4750
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4751
  },
4752
  from1 => {
4753
    $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4754
  },
4755
  from2 => {
4756
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4757
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4758
);
4759
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4760
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4761
like($result->type_rule2_off->fetch_one->[0], qr/^2010-01-06/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4762
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4763
like($result->type_rule2_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4764

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

            
4785
$dbi = DBIx::Custom->connect;
4786
eval { $dbi->execute("drop table $table1") };
4787
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4788
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4789
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4790
eval { $dbi->execute("drop table $table2") };
4791
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4792
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4793
eval { $dbi->execute("drop table $table3") };
4794
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4795
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4796
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4797
  table => $table1,
improved tests
Yuki Kimoto authored on 2012-03-01
4798
  column => "$table1.$key1 as " . u("${table1}_$key1") . ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
4799
  where   => {"$table1.$key2" => 2},
4800
  join  => {
4801
    clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4802
    table => [$table1, $table2]
4803
  }
added test
Yuki Kimoto authored on 2011-10-27
4804
)->all;
improved tests
Yuki Kimoto authored on 2012-03-01
4805
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
4806

            
4807
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4808
  table => $table1,
4809
  where   => {$key1 => 1},
4810
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4811
)->all;
4812
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4813

            
4814
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4815
  table => $table1,
4816
  where   => {$key1 => 1},
4817
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4818
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4819
)->all;
4820
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4821

            
4822
$rows = $dbi->select(
improved tests
Yuki Kimoto authored on 2012-03-01
4823
  column => "$table3.$key4 as " . u2("${table3}__$key4"),
cleanup
Yuki Kimoto authored on 2012-01-20
4824
  table => $table1,
4825
  where   => {"$table1.$key1" => 1},
4826
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4827
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4828
)->all;
improved tests
Yuki Kimoto authored on 2012-03-01
4829
is_deeply($rows, [{u2"${table3}__$key4" => 4}]);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4830

            
4831
$rows = $dbi->select(
improved tests
Yuki Kimoto authored on 2012-03-01
4832
  column => "$table1.$key1 as " . u2("${table1}__$key1"),
cleanup
Yuki Kimoto authored on 2012-01-20
4833
  table => $table1,
4834
  where   => {"$table3.$key4" => 4},
4835
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4836
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4837
)->all;
improved tests
Yuki Kimoto authored on 2012-03-01
4838
is_deeply($rows, [{u2"${table1}__$key1" => 1}]);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4839

            
4840
$dbi = DBIx::Custom->connect;
4841
eval { $dbi->execute("drop table $table1") };
4842
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4843
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4844
eval { $dbi->execute("drop table $table2") };
4845
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4846
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4847
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4848
  table => $table1,
fixed tests for fullqualifie...
Yuki Kimoto authored on 2012-03-02
4849
  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
4850
  where   => {"$table1.$key2" => 2},
fixed tests for fullqualifie...
Yuki Kimoto authored on 2012-03-02
4851
  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
4852
)->all;
fixed tests for fullqualifie...
Yuki Kimoto authored on 2012-03-02
4853
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
cleanup
Yuki Kimoto authored on 2012-01-20
4854
  'quote');
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4855

            
4856

            
4857
$dbi = DBIx::Custom->connect;
4858
eval { $dbi->execute("drop table $table1") };
4859
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4860
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4861
$sql = <<"EOS";
4862
left outer join (
cleanup
Yuki Kimoto authored on 2012-01-20
4863
select * from $table1 t1
added t/common-mysql-qualifi...
Yuki Kimoto authored on 2012-03-02
4864
  where t1.$key2 = (
4865
    select max(t2.$key2) from $table1 t2
4866
    where t1.$key1 = t2.$key1
4867
  )
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4868
) $table3 on $table1.$key1 = $table3.$key1
4869
EOS
added t/common-mysql-qualifi...
Yuki Kimoto authored on 2012-03-02
4870
$sql =~ s/\Q.table3/_table3/g;
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4871
$join = [$sql];
4872
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4873
  table => $table1,
fixed tests for fullqualifie...
Yuki Kimoto authored on 2012-03-02
4874
  column => u($table3) . ".$key1 as " . u2("${table3}__$key1"),
cleanup
Yuki Kimoto authored on 2012-01-20
4875
  join  => $join
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4876
)->all;
fixed tests for fullqualifie...
Yuki Kimoto authored on 2012-03-02
4877
is_deeply($rows, [{u2"${table3}__$key1" => 1}]);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4878

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

            
4911
$dbi = DBIx::Custom->connect;
4912
eval { $dbi->execute("drop table $table1") };
4913
eval { $dbi->execute("drop table $table2") };
4914
$dbi->execute($create_table1);
4915
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4916
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4917
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4918
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4919
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4920
  table => $table1,
4921
  column => [{$table2 => [$key3]}],
4922
  join => [
4923
    {
4924
      clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4925
      table => [$table1, $table2]
4926
    }
4927
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4928
);
4929
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4930

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4931
$dbi = DBIx::Custom->connect;
4932
eval { $dbi->execute("drop table $table1") };
4933
eval { $dbi->execute("drop table $table2") };
4934
$dbi->execute($create_table1);
4935
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4936
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4937
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4938
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4939
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4940
  table => $table1,
4941
  column => [{$table2 => [$key3]}],
4942
  join => [
4943
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4944
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4945
);
4946
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4947

            
4948
$dbi = DBIx::Custom->connect;
4949
eval { $dbi->execute("drop table $table1") };
4950
eval { $dbi->execute("drop table $table2") };
4951
$dbi->execute($create_table1);
4952
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4953
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4954
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4955
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4956
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4957
  table => $table1,
4958
  column => [{$table2 => [$key3]}],
4959
  join => [
4960
    "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4961
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4962
);
4963
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4964

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4965
test 'columns';
4966
$dbi = MyDBI1->connect;
4967
$model = $dbi->model($table1);
4968

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4969
test 'count';
4970
$dbi = DBIx::Custom->connect;
4971
eval { $dbi->execute("drop table $table1") };
4972
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4973
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4974
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4975
is($dbi->count(table => $table1), 2);
4976
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4977
$model = $dbi->create_model(table => $table1);
4978
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4979

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4980
eval { $dbi->execute("drop table $table1") };
4981
eval { $dbi->execute("drop table $table2") };
4982
$dbi->execute($create_table1);
4983
$dbi->execute($create_table2);
4984
$model = $dbi->create_model(table => $table1, primary_key => $key1);
4985
$model->insert({$key1 => 1, $key2 => 2});
4986
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
4987
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4988
$model->insert({$key1 => 1, $key3 => 3});
4989
is($model->count(id => 1), 1);
4990
is($model->count(where => {"$table2.$key3" => 3}), 1);
4991

            
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
4992
test 'table_alias option';
4993
$dbi = DBIx::Custom->connect;
4994
eval { $dbi->execute("drop table $table1") };
4995
$dbi->execute($create_table1_type);
4996
$dbi->insert({$key1 => '2010-01-01'}, table => $table1);
4997
$dbi->user_column_info($user_column_info);
4998
$dbi->type_rule(
4999
  into1 => {
5000
    $date_typename => sub { '2010-' . $_[0] }
5001
  }
5002
);
5003
$result = $dbi->execute(
5004
  "select * from $table1 TABLE1_ALIAS where :TABLE1_ALIAS.${key1}{=}",
5005
  {"TABLE1_ALIAS.${key1}" => '01-01'},
5006
  table_alias => {TABLE1_ALIAS => $table1}
5007
);
5008
like($result->one->{$key1}, qr/^2010-01-01/);
5009

            
5010
$dbi = DBIx::Custom->connect;
5011
eval { $dbi->execute("drop table $table1") };
5012
$dbi->execute($create_table1_type);
5013
$dbi->insert({$key1 => '2010-01-01'}, table => $table1);
5014
$dbi->user_column_info($user_column_info);
5015
$dbi->type_rule(
5016
  into2 => {
5017
    $date_typename => sub { '2010-' . $_[0] }
5018
  }
5019
);
5020
$result = $dbi->execute(
5021
  "select * from $table1 TABLE1_ALIAS where :TABLE1_ALIAS.${key1}{=}",
5022
  {"TABLE1_ALIAS.${key1}" => '01-01'},
5023
  table_alias => {TABLE1_ALIAS => $table1}
5024
);
5025
like($result->one->{$key1}, qr/^2010-01-01/);
5026

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