DBIx-Custom / t / common.t /
Newer Older
4969 lines | 161.842kb
added common test executing ...
Yuki Kimoto authored on 2011-08-07
1
use Test::More;
2
use strict;
3
use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
4
use Encode qw/encode_utf8/;
cleanup test
Yuki Kimoto authored on 2011-08-10
5
use FindBin;
cleanup
Yuki Kimoto authored on 2011-08-13
6
use Scalar::Util 'isweak';
cleanup test
Yuki Kimoto authored on 2011-08-10
7

            
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
8
$ENV{DBIX_CUSTOM_SUPPRESS_DEPRECATION} = '0.25';
9

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

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

            
16
plan 'no_plan';
17

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
200
  use base 'MyModel2::Base1';
201

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

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

            
210

            
211
  package MyModel2::main::table1;
212

            
213
  use strict;
214
  use warnings;
215

            
216
  use base 'MyModel2::Base1';
217

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

            
224
  sub list { shift->select; }
225

            
226
  package MyModel2::main::table2;
227

            
228
  use strict;
229
  use warnings;
230

            
231
  use base 'MyModel2::Base1';
232

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

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

            
241
  package MyModel2::dbix_custom::table1;
242

            
243
  use strict;
244
  use warnings;
245

            
246
  use base 'MyModel2::Base1';
247

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

            
254
  sub list { shift->select; }
255

            
256
  package MyModel2::dbix_custom::table2;
257

            
258
  use strict;
259
  use warnings;
260

            
261
  use base 'MyModel2::Base1';
262

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1560

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

            
1566
$dbi->begin_work;
1567

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

            
1574
$dbi->rollback if $@;
1575

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

            
1580
$dbi->begin_work;
1581

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

            
1587
$dbi->commit unless $@;
1588

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2200

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

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

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

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

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

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

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

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

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

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

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

            
2273
$dbi->apply_filter(
2274

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2560

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2777

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2956

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

            
2972

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

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

            
2993

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

            
3012

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

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

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

            
3052

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

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

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

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

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

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

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

            
3148

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

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

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

            
3175

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3747

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3868

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4072

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

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

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

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

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

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

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

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

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

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

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

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

            
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
4195
test 'columns';
4196
$dbi = MyDBI1->connect;
4197
$model = $dbi->model($table1);
4198
$model->columns([$key1, $key2]);
4199
is_deeply($model->columns, [$key1, $key2]);
4200

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4201
test 'setup_model';
4202
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
4203
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4204
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4205
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
4206

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4207
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4208
$dbi->execute($create_table2);
fixed setup method logic
Yuki Kimoto authored on 2012-03-02
4209
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
4210
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
4211
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4212

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4213
test 'each_column';
4214
$dbi = DBIx::Custom->connect;
4215
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4216
eval { $dbi->execute("drop table $table1") };
4217
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4218
eval { $dbi->execute("drop table $table3") };
4219
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4220
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4221

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4242
test 'each_table';
4243
$dbi = DBIx::Custom->connect;
4244
eval { $dbi->execute("drop table $table1") };
4245
eval { $dbi->execute("drop table $table2") };
4246
$dbi->execute($create_table2);
4247
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4248

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4291
test 'type_rule into';
4292
eval { $dbi->execute("drop table $table1") };
4293
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4294
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
4295

            
4296

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4297
$dbi = DBIx::Custom->connect;
4298
eval { $dbi->execute("drop table $table1") };
4299
$dbi->execute($create_table1_type);
4300

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

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

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

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

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

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

            
4425

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4531
eval{$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4532
  into1 => {
4533
    $date_typename => 'pp'
4534
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4535
)};
4536
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4537

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4550
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4551
  $dbi->type_rule(
4552
    into1 => {
4553
      Date => sub { $_[0] * 2 },
4554
    }
4555
  );
cleanup test
Yuki Kimoto authored on 2011-08-15
4556
};
4557
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4558

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

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

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

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

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

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

            
4634
$result = $dbi->select(table => $table1);
4635
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4636
  from1 => [$date_datatype => undef]
cleanup test
Yuki Kimoto authored on 2011-08-15
4637
);
4638
$row = $result->one;
4639
like($row->{$key1}, qr/^2010-01-03/);
4640
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4641

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

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

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

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

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

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

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

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

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

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

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

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

            
4833

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

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

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4942
test 'columns';
4943
$dbi = MyDBI1->connect;
4944
$model = $dbi->model($table1);
4945

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

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

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