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

            
DBIx::Custom::Result::kv met...
Yuki Kimoto authored on 2013-03-04
8
$ENV{DBIX_CUSTOM_SUPPRESS_DEPRECATION} = '0.28';
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
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

            
DBIx::Custom::Result::kv met...
Yuki Kimoto authored on 2013-03-04
3770
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key2");
3771
$rows = $result->kvs;
3772
is_deeply($rows, {
3773
  0 => [
3774
    {$key2 => 1},
3775
    {$key2 => 2}
3776
  ],
3777
  3 => [
3778
    {$key2 => 4},
3779
    {$key2 => 5}
3780
  ]
3781
});
added EXPERIMETAL DBIx::Cust...
Yuki Kimoto authored on 2012-02-28
3782

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3783
test 'DBIx::Custom::Result fetch_multi';
3784
eval { $dbi->execute("drop table $table1") };
3785
$dbi->execute($create_table1);
3786
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3787
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3788
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3789
$result = $dbi->select(table => $table1);
3790
$rows = $result->fetch_multi(2);
3791
is_deeply($rows, [[1, 2], [3, 4]]);
3792
$rows = $result->fetch_multi(2);
3793
is_deeply($rows, [[5, 6]]);
3794
$rows = $result->fetch_multi(2);
3795
ok(!$rows);
3796

            
3797
test 'DBIx::Custom::Result fetch_hash_multi';
3798
eval { $dbi->execute("drop table $table1") };
3799
$dbi->execute($create_table1);
3800
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3801
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3802
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3803
$result = $dbi->select(table => $table1);
3804
$rows = $result->fetch_hash_multi(2);
3805
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3806
$rows = $result->fetch_hash_multi(2);
3807
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3808
$rows = $result->fetch_hash_multi(2);
3809
ok(!$rows);
3810

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3811
test "query_builder";
3812
$datas = [
cleanup
Yuki Kimoto authored on 2012-01-20
3813
  # Basic tests
3814
  {   name            => 'placeholder basic',
3815
    source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
3816
    sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
3817
    columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3818
  },
3819
  {
3820
    name            => 'placeholder in',
3821
    source            => "{in k1 3}",
3822
    sql_expected    => "k1 in (?, ?, ?)",
3823
    columns_expected   => [qw/k1 k1 k1/]
3824
  },
3825
  
3826
  # Table name
3827
  {
3828
    name            => 'placeholder with table name',
3829
    source            => "{= a.k1} {= a.k2}",
3830
    sql_expected    => "a.k1 = ? a.k2 = ?",
3831
    columns_expected  => [qw/a.k1 a.k2/]
3832
  },
3833
  {   
3834
    name            => 'placeholder in with table name',
3835
    source            => "{in a.k1 2} {in b.k2 2}",
3836
    sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
3837
    columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3838
  },
3839
  {
3840
    name            => 'not contain tag',
3841
    source            => "aaa",
3842
    sql_expected    => "aaa",
3843
    columns_expected  => [],
3844
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3845
];
3846

            
3847
for (my $i = 0; $i < @$datas; $i++) {
cleanup
Yuki Kimoto authored on 2012-01-20
3848
  my $data = $datas->[$i];
3849
  my $dbi = DBIx::Custom->new;
3850
  my $builder = $dbi->query_builder;
3851
  my $query = $builder->build_query($data->{source});
3852
  is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3853
  is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3854
}
3855

            
cleanup
Yuki Kimoto authored on 2011-08-13
3856
$dbi = DBIx::Custom->new;
3857
$builder = $dbi->query_builder;
3858
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
3859
  p => sub {
3860
    my @args = @_;
3861
    
3862
    my $expand    = "? $args[0] $args[1]";
3863
    my $columns = [2];
3864
    return [$expand, $columns];
3865
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3866
);
3867

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3878
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3879
  q => 'string'
test cleanup
Yuki Kimoto authored on 2011-08-10
3880
});
3881

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3885
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3886
  r => sub {} 
test cleanup
Yuki Kimoto authored on 2011-08-10
3887
});
3888

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

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

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

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

            
3903

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

            
3908
eval{$builder->build_query("{in }")};
fixed bug that when id optio...
Yuki Kimoto authored on 2012-07-11
3909
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
3910

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

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

            
3919
test 'variouse source';
3920
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3921
$query = $builder->build_query($source);
3922
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3923

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

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

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

            
3936
$source = "a {= b} }";
3937
eval{$builder->build_query($source)};
3938
like($@, qr/unexpected "}"/, "error : 1");
3939

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

            
3944
test 'select() sqlfilter option';
3945
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3946
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3947
eval { $dbi->execute("drop table $table1") };
3948
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3949
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3950
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3951
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3952
  table => $table1,
3953
  column => $key1,
3954
  sqlfilter => sub {
3955
    my $sql = shift;
3956
    $sql = "select * from ( $sql ) t where $key1 = 1";
3957
    return $sql;
3958
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3959
)->all;
3960
is_deeply($rows, [{$key1 => 1}]);
3961

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3962
test 'select() after_build_sql option';
3963
$dbi = DBIx::Custom->connect;
3964
$dbi->user_table_info($user_table_info);
3965
eval { $dbi->execute("drop table $table1") };
3966
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3967
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3968
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3969
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3970
  table => $table1,
3971
  column => $key1,
3972
  after_build_sql => sub {
3973
    my $sql = shift;
3974
    $sql = "select * from ( $sql ) t where $key1 = 1";
3975
    return $sql;
3976
  }
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3977
)->all;
3978
is_deeply($rows, [{$key1 => 1}]);
3979

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3980
test 'dbi method from model';
3981
$dbi = MyDBI9->connect;
3982
eval { $dbi->execute("drop table $table1") };
3983
$dbi->execute($create_table1);
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
$model = $dbi->model($table1);
3986
eval{$model->execute("select * from $table1")};
3987
ok(!$@);
3988

            
3989
test 'column table option';
3990
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3991
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3992
eval { $dbi->execute("drop table $table1") };
3993
$dbi->execute($create_table1);
3994
eval { $dbi->execute("drop table $table2") };
3995
$dbi->execute($create_table2);
fixed setup method logic
Yuki Kimoto authored on 2012-03-02
3996
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3997
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3998
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3999
$model = $dbi->model($table1);
4000
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4001
  column => [
improved test
Yuki Kimoto authored on 2012-03-01
4002
    $model->column($table2, {alias => u$table2_alias})
cleanup
Yuki Kimoto authored on 2012-01-20
4003
  ],
improved test
Yuki Kimoto authored on 2012-03-01
4004
  where => {u($table2_alias) . ".$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
4005
);
4006
is_deeply($result->one, 
improved test
Yuki Kimoto authored on 2012-03-01
4007
        {u($table2_alias) . ".$key1" => 1, u($table2_alias) . ".$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
4008

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

            
4019
$dbi->separator('-');
4020
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4021
  column => [
improved test
Yuki Kimoto authored on 2012-03-01
4022
    $model->column($table2, {alias => u$table2_alias})
cleanup
Yuki Kimoto authored on 2012-01-20
4023
  ],
improved test
Yuki Kimoto authored on 2012-03-01
4024
  where => {u($table2_alias) . ".$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
4025
);
4026
is_deeply($result->one, 
improved test
Yuki Kimoto authored on 2012-03-01
4027
  {u(${table2_alias}) . "-$key1" => 1, u(${table2_alias}) . "-$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
4028

            
4029
test 'create_model';
4030
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
4031
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4032
eval { $dbi->execute("drop table $table1") };
4033
eval { $dbi->execute("drop table $table2") };
4034
$dbi->execute($create_table1);
4035
$dbi->execute($create_table2);
4036

            
4037
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
4038
  table => $table1,
4039
  join => [
4040
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
4041
  ],
4042
  primary_key => [$key1]
cleanup test
Yuki Kimoto authored on 2011-08-15
4043
);
4044
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
4045
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
4046
);
4047
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
4048
  table => $table3,
4049
  filter => [
4050
    $key1 => {in => sub { uc $_[0] }}
4051
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
4052
);
fixed setup method logic
Yuki Kimoto authored on 2012-03-02
4053
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
4054
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4055
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4056
$model = $dbi->model($table1);
4057
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4058
  column => [$model->mycolumn, $model->column($table2)],
4059
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-15
4060
);
4061
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
4062
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
4063
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
4064

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

            
4076
test 'model helper';
4077
$dbi = DBIx::Custom->connect;
4078
eval { $dbi->execute("drop table $table2") };
4079
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4080
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
4081
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
4082
  table => $table2
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
4083
);
4084
$model->helper(foo => sub { shift->select(@_) });
4085
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
4086

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

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

            
4107

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
4146
          
cleanup test
Yuki Kimoto authored on 2011-08-15
4147
$dbi = DBIx::Custom->connect;
4148
eval { $dbi->execute("drop table $table1") };
4149
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4150
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
4151
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
4152

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

            
4166
$param = {$key2 => 11};
4167
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
4168
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4169
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
4170
where $key1 = 1
4171
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
4172
$dbi->execute($sql, $param, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4173
$result = $dbi->execute("select * from $table1 order by $key1");
4174
$rows   = $result->all;
4175
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
4176
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
4177
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
4178

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4179
test 'Model class';
4180
$dbi = MyDBI1->connect;
4181
eval { $dbi->execute("drop table $table1") };
4182
$dbi->execute($create_table1);
4183
$model = $dbi->model($table1);
4184
$model->insert({$key1 => 'a', $key2 => 'b'});
4185
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4186
eval { $dbi->execute("drop table $table2") };
4187
$dbi->execute($create_table2);
4188
$model = $dbi->model($table2);
4189
$model->insert({$key1 => 'a'});
4190
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4191
is($dbi->models->{$table1}, $dbi->model($table1));
4192
is($dbi->models->{$table2}, $dbi->model($table2));
4193

            
4194
$dbi = MyDBI4->connect;
4195
eval { $dbi->execute("drop table $table1") };
4196
$dbi->execute($create_table1);
4197
$model = $dbi->model($table1);
4198
$model->insert({$key1 => 'a', $key2 => 'b'});
4199
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4200
eval { $dbi->execute("drop table $table2") };
4201
$dbi->execute($create_table2);
4202
$model = $dbi->model($table2);
4203
$model->insert({$key1 => 'a'});
4204
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4205

            
4206
$dbi = MyDBI5->connect;
4207
eval { $dbi->execute("drop table $table1") };
4208
eval { $dbi->execute("drop table $table2") };
4209
$dbi->execute($create_table1);
4210
$dbi->execute($create_table2);
4211
$model = $dbi->model($table2);
4212
$model->insert({$key1 => 'a'});
4213
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
4214
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4215
$model = $dbi->model($table1);
4216
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
4217

            
4218
test 'primary_key';
4219
$dbi = MyDBI1->connect;
4220
$model = $dbi->model($table1);
4221
$model->primary_key([$key1, $key2]);
4222
is_deeply($model->primary_key, [$key1, $key2]);
4223

            
4224
test 'columns';
4225
$dbi = MyDBI1->connect;
4226
$model = $dbi->model($table1);
4227
$model->columns([$key1, $key2]);
4228
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4229

            
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
4230
test 'columns';
4231
$dbi = MyDBI1->connect;
4232
$model = $dbi->model($table1);
4233
$model->columns([$key1, $key2]);
4234
is_deeply($model->columns, [$key1, $key2]);
4235

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4236
test 'setup_model';
4237
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
4238
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4239
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4240
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
4241

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4242
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4243
$dbi->execute($create_table2);
fixed setup method logic
Yuki Kimoto authored on 2012-03-02
4244
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
4245
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
4246
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4247

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4248
test 'each_column';
4249
$dbi = DBIx::Custom->connect;
4250
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4251
eval { $dbi->execute("drop table $table1") };
4252
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4253
eval { $dbi->execute("drop table $table3") };
4254
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4255
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4256

            
4257
$infos = [];
4258
$dbi->each_column(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4259
  my ($self, $table, $column, $cinfo) = @_;
4260
  
4261
  if ($table =~ /^table\d/i) {
4262
     my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
4263
     push @$infos, $info;
4264
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4265
});
4266
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4267
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4268
  [
improved tests
Yuki Kimoto authored on 2012-03-01
4269
    [table_only($table1), $key1, $key1],
4270
    [table_only($table1), $key2, $key2],
4271
    [table_only($table2), $key1, $key1],
4272
    [table_only($table2), $key3, $key3]
cleanup
Yuki Kimoto authored on 2012-01-20
4273
  ]
4274
  
cleanup test
Yuki Kimoto authored on 2011-08-10
4275
);
cleanup test
Yuki Kimoto authored on 2011-08-16
4276

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4277
test 'each_table';
4278
$dbi = DBIx::Custom->connect;
4279
eval { $dbi->execute("drop table $table1") };
4280
eval { $dbi->execute("drop table $table2") };
4281
$dbi->execute($create_table2);
4282
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4283

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4284
$infos = [];
4285
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4286
  my ($self, $table, $table_info) = @_;
4287
  
4288
  if ($table =~ /^table\d/i) {
4289
    my $info = [$table, $table_info->{TABLE_NAME}];
4290
    push @$infos, $info;
4291
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4292
});
4293
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4294
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4295
  [
improved tests
Yuki Kimoto authored on 2012-03-01
4296
    [table_only($table1), table_only($table1)],
4297
    [table_only($table2), table_only($table2)],
cleanup
Yuki Kimoto authored on 2012-01-20
4298
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4299
);
4300

            
cleanup test
Yuki Kimoto authored on 2011-08-16
4301
$dbi = DBIx::Custom->connect;
4302
eval { $dbi->execute("drop table $table1") };
4303
eval { $dbi->execute("drop table $table2") };
4304
$dbi->execute($create_table2);
4305
$dbi->execute($create_table1_type);
4306

            
4307
$infos = [];
4308
$dbi->user_table_info($user_table_info);
4309
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4310
  my ($self, $table, $table_info) = @_;
4311
  
4312
  if ($table =~ /^table\d/i) {
4313
     my $info = [$table, $table_info->{TABLE_NAME}];
4314
     push @$infos, $info;
4315
  }
cleanup test
Yuki Kimoto authored on 2011-08-16
4316
});
4317
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4318
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4319
  [
improved tests
Yuki Kimoto authored on 2012-03-01
4320
    [table_only($table1), table_only($table1)],
4321
    [table_only($table2), table_only($table2)],
4322
    [table_only($table3), table_only($table3)],
cleanup
Yuki Kimoto authored on 2012-01-20
4323
  ]
cleanup test
Yuki Kimoto authored on 2011-08-16
4324
);
4325

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4326
test 'type_rule into';
4327
eval { $dbi->execute("drop table $table1") };
4328
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4329
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
4330

            
4331

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4332
$dbi = DBIx::Custom->connect;
4333
eval { $dbi->execute("drop table $table1") };
4334
$dbi->execute($create_table1_type);
4335

            
cleanup
Yuki Kimoto authored on 2011-08-16
4336
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4337
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4338
  into1 => {
4339
    $date_typename => sub { '2010-' . $_[0] }
4340
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4341
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4342
$dbi->insert({$key1 => '01-01'}, table => $table1);
4343
$result = $dbi->select(table => $table1);
4344
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4345

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4365
$dbi = DBIx::Custom->connect;
4366
eval { $dbi->execute("drop table $table1") };
4367
$dbi->execute($create_table1_type);
4368
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4369
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4370
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4371
  into1 => [
4372
    [$date_typename, $datetime_typename] => sub {
4373
      my $value = shift;
4374
      $value =~ s/02/03/g;
4375
      return $value;
4376
    }
4377
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4378
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4379
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
4380
  "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
4381
  {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
4382
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4383
$row = $result->one;
4384
like($row->{$key1}, qr/^2010-01-03/);
4385
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4386

            
4387
$dbi = DBIx::Custom->connect;
4388
eval { $dbi->execute("drop table $table1") };
4389
$dbi->execute($create_table1_type);
4390
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4391
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4392
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4393
  into1 => [
4394
    [$date_typename, $datetime_typename] => sub {
4395
      my $value = shift;
4396
      $value =~ s/02/03/g;
4397
      return $value;
4398
    }
4399
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4400
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4401
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
4402
  "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
4403
  {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
4404
  table => $table1
cleanup test
Yuki Kimoto authored on 2011-08-15
4405
);
4406
$row = $result->one;
4407
like($row->{$key1}, qr/^2010-01-03/);
4408
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4409

            
4410
$dbi = DBIx::Custom->connect;
4411
eval { $dbi->execute("drop table $table1") };
4412
$dbi->execute($create_table1_type);
4413
$dbi->register_filter(convert => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4414
  my $value = shift || '';
4415
  $value =~ s/02/03/;
4416
  return $value;
cleanup test
Yuki Kimoto authored on 2011-08-15
4417
});
cleanup
Yuki Kimoto authored on 2011-08-16
4418
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4419
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4420
  from1 => {
4421
    $date_datatype => 'convert',
4422
  },
4423
  into1 => {
4424
      $date_typename => 'convert',
4425
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4426
);
4427
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
4428
$result = $dbi->select(table => $table1);
4429
like($result->fetch->[0], qr/^2010-03-03/);
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
4430
$result = $dbi->select(column => [$key1, $key1], table => $table1);
4431
$row = $result->fetch;
4432
like($row->[0], qr/^2010-03-03/);
4433
like($row->[1], qr/^2010-03-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4434

            
4435
test 'type_rule and filter order';
4436
$dbi = DBIx::Custom->connect;
4437
eval { $dbi->execute("drop table $table1") };
4438
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4439
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4440
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4441
  into1 => {
4442
    $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4443
  },
4444
  into2 => {
4445
    $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4446
  },
4447
  from1 => {
4448
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4449
  },
4450
  from2 => {
4451
    $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
4452
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4453
);
4454
$dbi->insert({$key1 => '2010-01-03'}, 
cleanup
Yuki Kimoto authored on 2012-01-20
4455
table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
cleanup test
Yuki Kimoto authored on 2011-08-15
4456
$result = $dbi->select(table => $table1);
4457
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4458
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4459

            
4460

            
4461
$dbi = DBIx::Custom->connect;
4462
eval { $dbi->execute("drop table $table1") };
4463
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4464
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4465
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4466
  from1 => {
4467
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4468
  },
4469
  from2 => {
4470
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4471
  },
cleanup test
Yuki Kimoto authored on 2011-08-15
4472
);
4473
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4474
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4475
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4476
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4477
  from1 => {
4478
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4479
  },
4480
  from2 => {
4481
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
4482
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4483
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4484
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4485
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4486

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4566
eval{$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4567
  into1 => {
4568
    $date_typename => 'pp'
4569
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4570
)};
4571
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4572

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4573
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4574
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4575
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4576
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4577
  $dbi->type_rule(
4578
    from1 => {
4579
      Date => sub { $_[0] * 2 },
4580
    }
4581
  );
cleanup test
Yuki Kimoto authored on 2011-08-10
4582
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4583
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4584

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4585
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4586
  $dbi->type_rule(
4587
    into1 => {
4588
      Date => sub { $_[0] * 2 },
4589
    }
4590
  );
cleanup test
Yuki Kimoto authored on 2011-08-15
4591
};
4592
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4593

            
4594
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4595
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4596
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4597
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4598
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4599
  from1 => {
4600
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4601
  },
4602
  into1 => {
4603
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4604
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4605
);
4606
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4607
$result = $dbi->select(table => $table1);
4608
$result->type_rule_off;
4609
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4610

            
4611
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4612
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4613
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4614
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4615
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4616
  from1 => {
4617
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4618
    $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4619
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4620
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4621
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
4622
$result = $dbi->select(table => $table1);
4623
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4624
  from1 => {
4625
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4626
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4627
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4628
$row = $result->one;
4629
like($row->{$key1}, qr/^2010-01-05/);
4630
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4631

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

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

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

            
4660
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4661
$result = $dbi->select(table => $table1);
4662
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4663
  from1 => [$date_datatype => 'five']
cleanup test
Yuki Kimoto authored on 2011-08-15
4664
);
4665
$row = $result->one;
4666
like($row->{$key1}, qr/^2010-01-05/);
4667
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4668

            
4669
$result = $dbi->select(table => $table1);
4670
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4671
  from1 => [$date_datatype => undef]
cleanup test
Yuki Kimoto authored on 2011-08-15
4672
);
4673
$row = $result->one;
4674
like($row->{$key1}, qr/^2010-01-03/);
4675
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4676

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4691
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4692
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4693
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4694
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4695
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4696
  from1 => {
4697
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4698
  },
cleanup test
Yuki Kimoto authored on 2011-08-15
4699
);
4700
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4701
$result = $dbi->select(table => $table1);
4702
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4703
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4704

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4729
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4730
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4731
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4732
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4733
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4734
  into1 => {
4735
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4736
  },
4737
  into2 => {
4738
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4739
  },
4740
  from1 => {
4741
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
4742
  },
4743
  from2 => {
4744
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4745
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4746
);
4747
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4748
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4749
like($result->type_rule1_off->fetch_one->[0], qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4750
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4751
like($result->type_rule1_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4752

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4753
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4754
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4755
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4756
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4757
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4758
  into1 => {
4759
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4760
  },
4761
  into2 => {
4762
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4763
  },
4764
  from1 => {
4765
    $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4766
  },
4767
  from2 => {
4768
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4769
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4770
);
4771
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4772
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4773
like($result->type_rule2_off->fetch_one->[0], qr/^2010-01-06/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4774
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4775
like($result->type_rule2_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4776

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4777
test 'join';
4778
$dbi = DBIx::Custom->connect;
4779
eval { $dbi->execute("drop table $table1") };
4780
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4781
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4782
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4783
eval { $dbi->execute("drop table $table2") };
4784
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4785
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4786
eval { $dbi->execute("drop table $table3") };
4787
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4788
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4789
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4790
  table => $table1,
improved tests
Yuki Kimoto authored on 2012-03-01
4791
  column => "$table1.$key1 as " . u("${table1}_$key1") . ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
4792
  where   => {"$table1.$key2" => 2},
4793
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4794
)->all;
improved tests
Yuki Kimoto authored on 2012-03-01
4795
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4796

            
4797
$dbi = DBIx::Custom->connect;
4798
eval { $dbi->execute("drop table $table1") };
4799
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4800
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4801
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4802
eval { $dbi->execute("drop table $table2") };
4803
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4804
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4805
eval { $dbi->execute("drop table $table3") };
4806
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4807
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4808
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4809
  table => $table1,
improved tests
Yuki Kimoto authored on 2012-03-01
4810
  column => "$table1.$key1 as " . u("${table1}_$key1") . ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
4811
  where   => {"$table1.$key2" => 2},
4812
  join  => {
4813
    clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4814
    table => [$table1, $table2]
4815
  }
added test
Yuki Kimoto authored on 2011-10-27
4816
)->all;
improved tests
Yuki Kimoto authored on 2012-03-01
4817
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
4818

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

            
4826
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4827
  table => $table1,
4828
  where   => {$key1 => 1},
4829
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4830
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4831
)->all;
4832
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4833

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

            
4843
$rows = $dbi->select(
improved tests
Yuki Kimoto authored on 2012-03-01
4844
  column => "$table1.$key1 as " . u2("${table1}__$key1"),
cleanup
Yuki Kimoto authored on 2012-01-20
4845
  table => $table1,
4846
  where   => {"$table3.$key4" => 4},
4847
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4848
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4849
)->all;
improved tests
Yuki Kimoto authored on 2012-03-01
4850
is_deeply($rows, [{u2"${table1}__$key1" => 1}]);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4851

            
4852
$dbi = DBIx::Custom->connect;
4853
eval { $dbi->execute("drop table $table1") };
4854
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4855
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4856
eval { $dbi->execute("drop table $table2") };
4857
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4858
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4859
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4860
  table => $table1,
fixed tests for fullqualifie...
Yuki Kimoto authored on 2012-03-02
4861
  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
4862
  where   => {"$table1.$key2" => 2},
fixed tests for fullqualifie...
Yuki Kimoto authored on 2012-03-02
4863
  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
4864
)->all;
fixed tests for fullqualifie...
Yuki Kimoto authored on 2012-03-02
4865
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
cleanup
Yuki Kimoto authored on 2012-01-20
4866
  'quote');
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4867

            
4868

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

            
4891
$dbi = DBIx::Custom->connect;
4892
eval { $dbi->execute("drop table $table1") };
4893
eval { $dbi->execute("drop table $table2") };
4894
$dbi->execute($create_table1);
4895
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4896
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4897
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4898
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4899
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4900
  table => $table1,
4901
  join => [
4902
    "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4903
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4904
);
4905
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4906
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4907
  table => $table1,
4908
  column => [{$table2 => [$key3]}],
4909
  join => [
4910
    "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4911
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4912
);
4913
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4914
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4915
  table => $table1,
4916
  column => [{$table2 => [$key3]}],
4917
  join => [
4918
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4919
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4920
);
4921
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4922

            
4923
$dbi = DBIx::Custom->connect;
4924
eval { $dbi->execute("drop table $table1") };
4925
eval { $dbi->execute("drop table $table2") };
4926
$dbi->execute($create_table1);
4927
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4928
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4929
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4930
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4931
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4932
  table => $table1,
4933
  column => [{$table2 => [$key3]}],
4934
  join => [
4935
    {
4936
      clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4937
      table => [$table1, $table2]
4938
    }
4939
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4940
);
4941
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4942

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

            
4960
$dbi = DBIx::Custom->connect;
4961
eval { $dbi->execute("drop table $table1") };
4962
eval { $dbi->execute("drop table $table2") };
4963
$dbi->execute($create_table1);
4964
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4965
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4966
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4967
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4968
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4969
  table => $table1,
4970
  column => [{$table2 => [$key3]}],
4971
  join => [
4972
    "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4973
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4974
);
4975
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4976

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4977
test 'columns';
4978
$dbi = MyDBI1->connect;
4979
$model = $dbi->model($table1);
4980

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4981
test 'count';
4982
$dbi = DBIx::Custom->connect;
4983
eval { $dbi->execute("drop table $table1") };
4984
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4985
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4986
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4987
is($dbi->count(table => $table1), 2);
4988
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4989
$model = $dbi->create_model(table => $table1);
4990
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4991

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4992
eval { $dbi->execute("drop table $table1") };
4993
eval { $dbi->execute("drop table $table2") };
4994
$dbi->execute($create_table1);
4995
$dbi->execute($create_table2);
4996
$model = $dbi->create_model(table => $table1, primary_key => $key1);
4997
$model->insert({$key1 => 1, $key2 => 2});
4998
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
4999
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
5000
$model->insert({$key1 => 1, $key3 => 3});
5001
is($model->count(id => 1), 1);
5002
is($model->count(where => {"$table2.$key3" => 3}), 1);
5003

            
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
5004
test 'table_alias option';
5005
$dbi = DBIx::Custom->connect;
5006
eval { $dbi->execute("drop table $table1") };
5007
$dbi->execute($create_table1_type);
5008
$dbi->insert({$key1 => '2010-01-01'}, table => $table1);
5009
$dbi->user_column_info($user_column_info);
5010
$dbi->type_rule(
5011
  into1 => {
5012
    $date_typename => sub { '2010-' . $_[0] }
5013
  }
5014
);
5015
$result = $dbi->execute(
5016
  "select * from $table1 TABLE1_ALIAS where :TABLE1_ALIAS.${key1}{=}",
5017
  {"TABLE1_ALIAS.${key1}" => '01-01'},
5018
  table_alias => {TABLE1_ALIAS => $table1}
5019
);
5020
like($result->one->{$key1}, qr/^2010-01-01/);
5021

            
5022
$dbi = DBIx::Custom->connect;
5023
eval { $dbi->execute("drop table $table1") };
5024
$dbi->execute($create_table1_type);
5025
$dbi->insert({$key1 => '2010-01-01'}, table => $table1);
5026
$dbi->user_column_info($user_column_info);
5027
$dbi->type_rule(
5028
  into2 => {
5029
    $date_typename => sub { '2010-' . $_[0] }
5030
  }
5031
);
5032
$result = $dbi->execute(
5033
  "select * from $table1 TABLE1_ALIAS where :TABLE1_ALIAS.${key1}{=}",
5034
  {"TABLE1_ALIAS.${key1}" => '01-01'},
5035
  table_alias => {TABLE1_ALIAS => $table1}
5036
);
5037
like($result->one->{$key1}, qr/^2010-01-01/);
5038

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