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

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

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

            
14
plan 'no_plan';
15

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
16
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
finished oracle test
Yuki Kimoto authored on 2011-08-15
17
sub test { print "# $_[0]\n" }
18

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
200
  use base 'MyModel2::Base1';
201

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

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

            
210

            
211
  package MyModel2::main::table1;
212

            
213
  use strict;
214
  use warnings;
215

            
216
  use base 'MyModel2::Base1';
217

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

            
224
  sub list { shift->select; }
225

            
226
  package MyModel2::main::table2;
227

            
228
  use strict;
229
  use warnings;
230

            
231
  use base 'MyModel2::Base1';
232

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

            
239
  sub list { shift->select; }
test cleanup
Yuki Kimoto authored on 2011-08-10
240
}
241
{
cleanup
Yuki Kimoto authored on 2012-01-20
242
   package MyDBI5;
test cleanup
Yuki Kimoto authored on 2011-08-10
243

            
cleanup
Yuki Kimoto authored on 2012-01-20
244
  use strict;
245
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
246

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
249
  sub connect {
250
    my $self = shift->SUPER::connect(@_);
251
    
252
    $self->include_model('MyModel4');
253
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
254
}
255
{
cleanup
Yuki Kimoto authored on 2012-01-20
256
  package MyDBI6;
257
  
258
  use base 'DBIx::Custom';
259
  
260
  sub connect {
261
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
262
    
cleanup
Yuki Kimoto authored on 2012-01-20
263
    $self->include_model('MyModel5');
test cleanup
Yuki Kimoto authored on 2011-08-10
264
    
cleanup
Yuki Kimoto authored on 2012-01-20
265
    return $self;
266
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
267
}
268
{
cleanup
Yuki Kimoto authored on 2012-01-20
269
  package MyDBI7;
270
  
271
  use base 'DBIx::Custom';
272
  
273
  sub connect {
274
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
275
    
cleanup
Yuki Kimoto authored on 2012-01-20
276
    $self->include_model('MyModel6');
test cleanup
Yuki Kimoto authored on 2011-08-10
277
    
cleanup
Yuki Kimoto authored on 2012-01-20
278
    
279
    return $self;
280
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
281
}
282
{
cleanup
Yuki Kimoto authored on 2012-01-20
283
  package MyDBI8;
284
  
285
  use base 'DBIx::Custom';
286
  
287
  sub connect {
288
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
289
    
cleanup
Yuki Kimoto authored on 2012-01-20
290
    $self->include_model('MyModel7');
test cleanup
Yuki Kimoto authored on 2011-08-10
291
    
cleanup
Yuki Kimoto authored on 2012-01-20
292
    return $self;
293
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
294
}
295

            
296
{
cleanup
Yuki Kimoto authored on 2012-01-20
297
  package MyDBI9;
298
  
299
  use base 'DBIx::Custom';
300
  
301
  sub connect {
302
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
303
    
cleanup
Yuki Kimoto authored on 2012-01-20
304
    $self->include_model('MyModel8');
test cleanup
Yuki Kimoto authored on 2011-08-10
305
    
cleanup
Yuki Kimoto authored on 2012-01-20
306
    return $self;
307
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
308
}
309

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
310
test 'execute reuse option';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
311
eval { $dbi->execute("drop table $table1") };
312
$dbi->execute($create_table1);
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
313
$reuse = {};
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
314
for my $i (1 .. 2) {
cleanup
Yuki Kimoto authored on 2012-01-20
315
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, reuse => $reuse);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
316
}
317
$rows = $dbi->select(table => $table1)->all;
318
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-11-18
319
ok(keys %$reuse);
320
ok((keys %$reuse)[0] !~ /\?/);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
321

            
added test
Yuki Kimoto authored on 2011-08-16
322
# Get user table info
323
$dbi = DBIx::Custom->connect;
324
eval { $dbi->execute("drop table $table1") };
325
eval { $dbi->execute("drop table $table2") };
326
eval { $dbi->execute("drop table $table3") };
327
$dbi->execute($create_table1);
328
$dbi->execute($create_table2);
329
$dbi->execute($create_table3);
330
$user_table_info = $dbi->get_table_info(exclude => $dbi->exclude_table);
331

            
cleanup test
Yuki Kimoto authored on 2011-08-15
332
# Create table
test cleanup
Yuki Kimoto authored on 2011-08-10
333
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
334
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
335
$dbi->execute($create_table1);
336
$model = $dbi->create_model(table => $table1);
337
$model->insert({$key1 => 1, $key2 => 2});
338
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-08-15
339

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
340
eval { $dbi->execute("drop table $table1") };
341
$dbi->execute($create_table1);
342
$model = $dbi->create_model(table => $table1);
343
$model->insert({$key1 => 1, $key2 => 2});
344
is_deeply($model->select($key1)->all, [{$key1 => 1}]);
345

            
cleanup test
Yuki Kimoto authored on 2011-08-15
346
test 'DBIx::Custom::Result test';
347
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
348
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
349
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
350
$source = "select $key1, $key2 from $table1";
351
$query = $dbi->create_query($source);
352
$result = $dbi->execute($query);
cleanup
Yuki Kimoto authored on 2011-08-15
353

            
cleanup test
Yuki Kimoto authored on 2011-08-15
354
@rows = ();
355
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
356
  push @rows, [@$row];
cleanup test
Yuki Kimoto authored on 2011-08-15
357
}
358
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
cleanup
Yuki Kimoto authored on 2011-08-15
359

            
cleanup test
Yuki Kimoto authored on 2011-08-15
360
$result = $dbi->execute($query);
361
@rows = ();
362
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
363
  push @rows, {%$row};
cleanup test
Yuki Kimoto authored on 2011-08-15
364
}
365
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
366

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
380
test 'Insert query return value';
381
$source = "insert into $table1 {insert_param $key1 $key2}";
382
$query = $dbi->execute($source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
383
$ret_val = $dbi->execute($query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
384
ok($ret_val);
test cleanup
Yuki Kimoto authored on 2011-08-10
385

            
cleanup test
Yuki Kimoto authored on 2011-08-15
386
test 'Direct query';
387
$dbi->delete_all(table => $table1);
388
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
test cleanup
Yuki Kimoto authored on 2011-11-01
389
$dbi->execute($insert_source, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
390
$result = $dbi->execute("select * from $table1");
391
$rows = $result->all;
392
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
393

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
399
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
400
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
401
$insert_query->filter({$key1 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
402
$dbi->execute($insert_query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
403
$result = $dbi->execute("select * from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
404
$rows = $result->filter({$key2 => 'three_times'})->all;
405
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
406

            
407
test 'Filter in';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
408
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
409
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
410
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
411
$dbi->execute($insert_query, {$key1 => 2, $key2 => 4});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
412
$select_source = "select * from $table1 where {in $table1.$key1 2} and {in $table1.$key2 2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
413
$select_query = $dbi->execute($select_source,{}, query => 1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
414
$select_query->filter({"$table1.$key1" => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
415
$result = $dbi->execute($select_query, {"$table1.$key1" => [1,5], "$table1.$key2" => [2,4]});
cleanup test
Yuki Kimoto authored on 2011-08-08
416
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
417
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
418

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
499
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
500
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
501
  $source,
502
  {"$table1.$key1" => 1, "$table1.$key2" => 1},
503
  filter => {"$table1.$key2" => sub { $_[0] * 2 }}
cleanup test
Yuki Kimoto authored on 2011-08-08
504
);
505
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
506
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
507

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
508
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
509
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
510
$dbi->insert({$key1 => '2011-10-14 12:19:18', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
511
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
512
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
513
  $source,
514
  {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
515
);
516

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
521
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
522
$dbi->insert({$key1 => 'a:b c:d', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
523
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
524
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
525
  $source,
526
  {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
527
);
528
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
529
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
530

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
538
test 'insert';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
539
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
540
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
541
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
542
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
543
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
544
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
545
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
546

            
added tests
Yuki Kimoto authored on 2011-11-01
547
eval { $dbi->execute("drop table $table1") };
548
$dbi->execute($create_table1);
549
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
550
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
551
$result = $dbi->execute("select * from $table1");
552
$rows   = $result->all;
553
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
554

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
555
$dbi->execute("delete from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
556
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
557
  twice       => sub { $_[0] * 2 },
558
  three_times => sub { $_[0] * 3 }
cleanup test
Yuki Kimoto authored on 2011-08-10
559
);
560
$dbi->default_bind_filter('twice');
test cleanup
Yuki Kimoto authored on 2011-11-01
561
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
cleanup test
Yuki Kimoto authored on 2011-08-15
562
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
563
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
564
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
565
$dbi->delete_all(table => $table1);
566
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
567
$result = $dbi->execute("select * from $table1");
568
$rows   = $result->all;
569
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-10
570
$dbi->default_bind_filter(undef);
571

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
582
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
583
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
584
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
test cleanup
Yuki Kimoto authored on 2011-11-01
585
$dbi->insert({select => 1}, table => 'table');
cleanup test
Yuki Kimoto authored on 2011-08-10
586
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
587
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
588
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
cleanup test
Yuki Kimoto authored on 2011-08-10
589

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
590
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
591
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
592
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
593
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
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 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
597

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
598
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
599
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
600
$dbi->insert({$key1 => \"'1'", $key2 => 2}, table => $table1);
601
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
602
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
603
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
604
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
605

            
updated pod
Yuki Kimoto authored on 2011-09-02
606
eval { $dbi->execute("drop table $table1") };
607
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
608
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
609
wrap => {$key1 => sub { "$_[0] - 1" }});
test cleanup
Yuki Kimoto authored on 2011-11-01
610
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
updated pod
Yuki Kimoto authored on 2011-09-02
611
$result = $dbi->execute("select * from $table1");
612
$rows   = $result->all;
613
is_deeply($rows, [{$key1 => 0, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
614

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
615
eval { $dbi->execute("drop table $table1") };
616
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
617
$dbi->insert_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
618
  $key1 => '5'
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
619
);
test cleanup
Yuki Kimoto authored on 2011-11-01
620
$dbi->insert({$key2 => 2}, table => $table1, timestamp => 1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
621
$result = $dbi->execute("select * from $table1");
622
$rows   = $result->all;
623
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
624

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
625
eval { $dbi->execute("drop table $table1") };
626
$dbi->execute($create_table1);
627
$dbi->insert_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
628
  [$key1, $key2] => sub { 5 }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
629
);
630
$dbi->insert(table => $table1, timestamp => 1);
631
$result = $dbi->execute("select * from $table1");
632
$rows   = $result->all;
633
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
634

            
635
eval { $dbi->execute("drop table $table1") };
636
$dbi->execute($create_table1);
637
$dbi->insert_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
638
  [$key1, $key2] => sub { "" . DBIx::Custom->new }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
639
);
640
$dbi->insert(table => $table1, timestamp => 1);
641
$result = $dbi->execute("select * from $table1");
642
$rows   = $result->all;
643
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
644

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
645
eval { $dbi->execute("drop table $table1") };
646
$dbi->execute($create_table1_2);
647
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
648
$dbi->insert($param, table => $table1, created_at => $key2);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
649
$result = $dbi->select(table => $table1);
650
is_deeply($param, {$key1 => 1});
651
$row   = $result->one;
652
is($row->{$key1}, 1);
653
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
654

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
655
eval { $dbi->execute("drop table $table1") };
656
$dbi->execute($create_table1_2);
657
$param = {$key1 => 1};
658
$dbi->insert($param, table => $table1, ctime => $key2);
659
$result = $dbi->select(table => $table1);
660
is_deeply($param, {$key1 => 1});
661
$row   = $result->one;
662
is($row->{$key1}, 1);
663
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
664

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
665
eval { $dbi->execute("drop table $table1") };
666
$dbi->execute($create_table1_2);
667
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
668
$dbi->insert($param, table => $table1, updated_at => $key3);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
669
$result = $dbi->select(table => $table1);
670
is_deeply($param, {$key1 => 1});
671
$row   = $result->one;
672
is($row->{$key1}, 1);
673
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
674

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
675
eval { $dbi->execute("drop table $table1") };
676
$dbi->execute($create_table1_2);
677
$param = {$key1 => 1};
678
$dbi->insert($param, table => $table1, mtime => $key3);
679
$result = $dbi->select(table => $table1);
680
is_deeply($param, {$key1 => 1});
681
$row   = $result->one;
682
is($row->{$key1}, 1);
683
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
684

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
685
eval { $dbi->execute("drop table $table1") };
686
$dbi->execute($create_table1_2);
687
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
688
$dbi->insert($param, table => $table1, created_at => $key2, updated_at => $key3);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
689
$result = $dbi->select(table => $table1);
690
is_deeply($param, {$key1 => 1});
691
$row   = $result->one;
692
is($row->{$key1}, 1);
693
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
694
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
695
is($row->{$key2}, $row->{$key3});
696

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
697
eval { $dbi->execute("drop table $table1") };
698
$dbi->execute($create_table1_2);
699
$param = {$key1 => 1};
700
$dbi->insert($param, table => $table1, created_at => $key2, mtime => $key3);
701
$result = $dbi->select(table => $table1);
702
is_deeply($param, {$key1 => 1});
703
$row   = $result->one;
704
is($row->{$key1}, 1);
705
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
706
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
707
is($row->{$key2}, $row->{$key3});
708

            
709
eval { $dbi->execute("drop table $table1") };
710
$dbi->execute($create_table1_2);
711
$param = {$key1 => 1};
712
$dbi->insert($param, table => $table1, ctime => $key2, updated_at => $key3);
713
$result = $dbi->select(table => $table1);
714
is_deeply($param, {$key1 => 1});
715
$row   = $result->one;
716
is($row->{$key1}, 1);
717
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
718
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
719
is($row->{$key2}, $row->{$key3});
720

            
721
eval { $dbi->execute("drop table $table1") };
722
$dbi->execute($create_table1_2);
723
$param = {$key1 => 1};
724
$dbi->insert($param, table => $table1, ctime => $key2, mtime => $key3);
725
$result = $dbi->select(table => $table1);
726
is_deeply($param, {$key1 => 1});
727
$row   = $result->one;
728
is($row->{$key1}, 1);
729
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
730
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
731
is($row->{$key2}, $row->{$key3});
732

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
733
eval { $dbi->execute("drop table $table1") };
734
$dbi->execute($create_table1_2);
735
$model = $dbi->create_model(table => $table1, created_at => $key2);
736
$param = {$key1 => 1};
737
$model->insert($param);
738
$result = $dbi->select(table => $table1);
739
is_deeply($param, {$key1 => 1});
740
$row   = $result->one;
741
is($row->{$key1}, 1);
742
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
743

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
744
eval { $dbi->execute("drop table $table1") };
745
$dbi->execute($create_table1_2);
746
$model = $dbi->create_model(table => $table1, ctime => $key2);
747
$param = {$key1 => 1};
748
$model->insert($param);
749
$result = $dbi->select(table => $table1);
750
is_deeply($param, {$key1 => 1});
751
$row   = $result->one;
752
is($row->{$key1}, 1);
753
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
754

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
755
eval { $dbi->execute("drop table $table1") };
756
$dbi->execute($create_table1_2);
757
$param = {$key1 => 1};
758
$model = $dbi->create_model(table => $table1, updated_at => $key3);
759
$model->insert($param);
760
$result = $dbi->select(table => $table1);
761
is_deeply($param, {$key1 => 1});
762
$row   = $result->one;
763
is($row->{$key1}, 1);
764
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
765

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
766
eval { $dbi->execute("drop table $table1") };
767
$dbi->execute($create_table1_2);
768
$param = {$key1 => 1};
769
$model = $dbi->create_model(table => $table1, mtime => $key3);
770
$model->insert($param);
771
$result = $dbi->select(table => $table1);
772
is_deeply($param, {$key1 => 1});
773
$row   = $result->one;
774
is($row->{$key1}, 1);
775
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
776

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
777
eval { $dbi->execute("drop table $table1") };
778
$dbi->execute($create_table1_2);
779
$param = {$key1 => 1};
780
$model = $dbi->create_model(table => $table1, created_at => $key2, updated_at => $key3);
781
$model->insert($param);
782
$result = $dbi->select(table => $table1);
783
is_deeply($param, {$key1 => 1});
784
$row   = $result->one;
785
is($row->{$key1}, 1);
786
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
787
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
788
is($row->{$key2}, $row->{$key3});
789

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

            
803
eval { $dbi->execute("drop table $table1") };
804
$dbi->execute($create_table1_2);
805
$param = {$key1 => 1};
806
$model = $dbi->create_model(table => $table1, ctime=> $key2, updated_at => $key3);
807
$model->insert($param);
808
$result = $dbi->select(table => $table1);
809
is_deeply($param, {$key1 => 1});
810
$row   = $result->one;
811
is($row->{$key1}, 1);
812
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
813
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
814
is($row->{$key2}, $row->{$key3});
815

            
816
eval { $dbi->execute("drop table $table1") };
817
$dbi->execute($create_table1_2);
818
$param = {$key1 => 1};
819
$model = $dbi->create_model(table => $table1, ctime=> $key2, mtime => $key3);
820
$model->insert($param);
821
$result = $dbi->select(table => $table1);
822
is_deeply($param, {$key1 => 1});
823
$row   = $result->one;
824
is($row->{$key1}, 1);
825
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
826
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
827
is($row->{$key2}, $row->{$key3});
828

            
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
829
eval { $dbi->execute("drop table $table1") };
830
$dbi->execute($create_table1);
831
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] , table => $table1);
832
$result = $dbi->execute("select * from $table1");
833
$rows   = $result->all;
834
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
835

            
836
eval { $dbi->execute("drop table $table1") };
837
$dbi->execute($create_table1_2);
838
$dbi->insert([{$key1 => 1}, {$key1 => 3}] ,
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
839
  table => $table1,
840
  updated_at => $key2,
841
  created_at => $key3
842
);
843
$result = $dbi->execute("select * from $table1");
844
$rows   = $result->all;
845
is($rows->[0]->{$key1}, 1);
846
is($rows->[1]->{$key1}, 3);
847
like($rows->[0]->{$key2}, qr/\d{2}:/);
848
like($rows->[1]->{$key2}, qr/\d{2}:/);
849
like($rows->[0]->{$key3}, qr/\d{2}:/);
850
like($rows->[1]->{$key3}, qr/\d{2}:/);
851

            
852
eval { $dbi->execute("drop table $table1") };
853
$dbi->execute($create_table1_2);
854
$dbi->insert([{$key1 => 1}, {$key1 => 3}] ,
855
  table => $table1,
856
  mtime => $key2,
857
  ctime => $key3
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
858
);
859
$result = $dbi->execute("select * from $table1");
860
$rows   = $result->all;
861
is($rows->[0]->{$key1}, 1);
862
is($rows->[1]->{$key1}, 3);
863
like($rows->[0]->{$key2}, qr/\d{2}:/);
864
like($rows->[1]->{$key2}, qr/\d{2}:/);
865
like($rows->[0]->{$key3}, qr/\d{2}:/);
866
like($rows->[1]->{$key3}, qr/\d{2}:/);
867

            
868
eval { $dbi->execute("drop table $table1") };
869
$dbi->execute($create_table1);
870
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] ,
cleanup
Yuki Kimoto authored on 2012-01-20
871
table => $table1, filter => {$key1 => sub { $_[0] * 2 }});
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
872
$result = $dbi->execute("select * from $table1");
873
$rows   = $result->all;
874
is_deeply($rows, [{$key1 => 2, $key2 => 2}, {$key1 => 6, $key2 => 4}], "basic");
875

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
876
test 'update_or_insert';
877
eval { $dbi->execute("drop table $table1") };
878
$dbi->execute($create_table1);
879
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
880
  {$key2 => 2},
881
  table => $table1,
882
  primary_key => $key1,
883
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
884
);
885
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
886
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
887

            
888
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
889
  {$key2 => 3},
890
  table => $table1,
891
  primary_key => $key1,
892
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
893
);
894
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
895
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
896

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
897
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
898
  $dbi->update_or_insert(
899
    {$key2 => 3},
900
    table => $table1,
901
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
902
};
903

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
906
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
907
  $dbi->insert({$key1 => 1}, table => $table1);
908
  $dbi->update_or_insert(
909
    {$key2 => 3},
910
    table => $table1,
911
    primary_key => $key1,
912
    id => 1
913
  );
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
914
};
915
like($@, qr/one/);
916

            
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
917
eval { $dbi->execute("drop table $table1") };
918
$dbi->execute($create_table1);
919
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
920
  {},
921
  table => $table1,
922
  primary_key => $key1,
923
  id => 1
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
924
);
925
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
926
is($row->{$key1}, 1);
927

            
928
eval { 
cleanup
Yuki Kimoto authored on 2012-01-20
929
  $affected = $dbi->update_or_insert(
930
    {},
931
    table => $table1,
932
    primary_key => $key1,
933
    id => 1
934
  );
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
935
};
936
is($affected, 0);
937

            
micro optimization
Yuki Kimoto authored on 2011-10-31
938
test 'model update_or_insert';
939
eval { $dbi->execute("drop table $table1") };
940
$dbi->execute($create_table1);
941
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
942
  table => $table1,
943
  primary_key => $key1
micro optimization
Yuki Kimoto authored on 2011-10-31
944
);
945
$model->update_or_insert({$key2 => 2}, id => 1);
946
$row = $model->select(id => 1)->one;
947
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
948

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
949
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
950
  $model->insert({$key1 => 1});
951
  $model->update_or_insert(
952
    {$key2 => 3},
953
    id => 1
954
  );
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
955
};
956
like($@, qr/one/);
957

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
958
test 'default_bind_filter';
959
$dbi->execute("delete from $table1");
960
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
961
  twice       => sub { $_[0] * 2 },
962
  three_times => sub { $_[0] * 3 }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
963
);
964
$dbi->default_bind_filter('twice');
cleanup
Yuki Kimoto authored on 2011-11-01
965
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
966
$result = $dbi->execute("select * from $table1");
967
$rows   = $result->all;
968
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
969
$dbi->default_bind_filter(undef);
970

            
test cleanup
Yuki Kimoto authored on 2011-08-10
971
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
972
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
973
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
974
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
975
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
976
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
977
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
978
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
979
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
980
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
981
  "basic");
added tests
Yuki Kimoto authored on 2011-11-01
982

            
983
eval { $dbi->execute("drop table $table1") };
984
$dbi->execute($create_table1_2);
985
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
986
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
987
$dbi->update(param => {$key2 => 11}, table => $table1, where => {$key1 => 1});
988
$result = $dbi->execute("select * from $table1 order by $key1");
989
$rows   = $result->all;
990
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
991
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
992
  "basic");
993
                
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
994
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
995
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
996
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
997
$dbi->update({$key2 => 12}, table => $table1, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
998
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
999
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1000
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1001
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1002
  "update key same as search key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1003

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1011
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
1012
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1013
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1014
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
1015
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
1016
            filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
1017
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1018
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1019
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1020
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1021
  "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1022

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1028
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1029
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1030
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1031
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1032
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1033
$where->param({$key1 => 1, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
1034
$dbi->update({$key1 => 3}, table => $table1, where => $where);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1035
$result = $dbi->select(table => $table1);
1036
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1037

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1038
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1039
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1040
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1041
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
1042
  {$key1 => 3},
1043
  table => $table1,
1044
  where => [
1045
    ['and', "$key1 = :$key1", "$key2 = :$key2"],
1046
    {$key1 => 1, $key2 => 2}
1047
  ]
test cleanup
Yuki Kimoto authored on 2011-08-10
1048
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1049
$result = $dbi->select(table => $table1);
1050
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1051

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1068
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1069
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1070
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1071
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
1072
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
1073
$dbi->insert({select => 1}, table => 'table');
1074
$dbi->update({update => 2}, table => 'table', where => {select => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1075
$result = $dbi->execute("select * from ${q}table$p");
1076
$rows   = $result->all;
1077
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
1078

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

            
1082
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1083
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1084
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
1085
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
1086
$dbi->insert({select => 1}, table => 'table');
1087
$dbi->update({update => 2}, table => 'table', where => {'table.select' => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1088
$result = $dbi->execute("select * from ${q}table$p");
1089
$rows   = $result->all;
1090
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
1091

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1092
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1093
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1094
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1095
$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
1096
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1097
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1098
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1099
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1100
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1101
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1102

            
updated pod
Yuki Kimoto authored on 2011-09-02
1103
eval { $dbi->execute("drop table $table1") };
1104
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1105
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1106
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1107
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
updated pod
Yuki Kimoto authored on 2011-09-02
1108
wrap => {$key2 => sub { "$_[0] - 1" }});
1109
$result = $dbi->execute("select * from $table1 order by $key1");
1110
$rows   = $result->all;
1111
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1112
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1113
  "basic");
updated pod
Yuki Kimoto authored on 2011-09-02
1114

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1115
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1116
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1117
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1118
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1119
$dbi->update({$key2 => \"'11'"}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1120
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1121
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1122
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1123
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1124
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1125

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1126
eval { $dbi->execute("drop table $table1") };
1127
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1128
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
1129
  $key1 => '5'
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1130
);
test cleanup
Yuki Kimoto authored on 2011-11-01
1131
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1132
$dbi->update(table => $table1, timestamp => 1, where => {$key2 => 2});
1133
$result = $dbi->execute("select * from $table1");
1134
$rows   = $result->all;
1135
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
1136

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1137
eval { $dbi->execute("drop table $table1") };
1138
$dbi->execute($create_table1);
1139
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
1140
  [$key1, $key2] => sub { '5' }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1141
);
test cleanup
Yuki Kimoto authored on 2011-11-01
1142
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1143
$dbi->update_all(table => $table1, timestamp => 1);
1144
$result = $dbi->execute("select * from $table1");
1145
$rows   = $result->all;
1146
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
1147

            
1148
eval { $dbi->execute("drop table $table1") };
1149
$dbi->execute($create_table1);
1150
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
1151
  [$key1, $key2] => sub { "" . DBIx::Custom->new }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1152
);
test cleanup
Yuki Kimoto authored on 2011-11-01
1153
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1154
$dbi->update_all(table => $table1, timestamp => 1);
1155
$result = $dbi->execute("select * from $table1");
1156
$rows   = $result->all;
1157
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
1158

            
micro optimization and
Yuki Kimoto authored on 2011-10-25
1159
eval { $dbi->execute("drop table $table1") };
1160
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1161
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1162
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
1163
$param = {$key2 => 11};
1164
$dbi->update($param, table => $table1, where => {$key1 => 1});
1165
is_deeply($param, {$key2 => 11});
1166
$result = $dbi->execute("select * from $table1 order by $key1");
1167
$rows   = $result->all;
1168
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1169
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1170
  "basic");
micro optimization and
Yuki Kimoto authored on 2011-10-25
1171

            
1172
eval { $dbi->execute("drop table $table1") };
1173
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1174
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1175
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
1176
$param = {$key2 => 11};
1177
$dbi->update($param, table => $table1, where => {$key2 => 2});
1178
is_deeply($param, {$key2 => 11});
1179
$result = $dbi->execute("select * from $table1 order by $key1");
1180
$rows   = $result->all;
1181
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1182
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1183
  "basic");
micro optimization and
Yuki Kimoto authored on 2011-10-25
1184

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1185
eval { $dbi->execute("drop table $table1") };
1186
$dbi->execute($create_table1_2);
1187
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1188
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1189
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key1 => 1});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1190
$result = $dbi->select(table => $table1);
1191
is_deeply($param, {$key3 => 4});
1192
$row   = $result->one;
1193
is($row->{$key3}, 4);
1194
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1195

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1196
eval { $dbi->execute("drop table $table1") };
1197
$dbi->execute($create_table1_2);
1198
$param = {$key3 => 4};
1199
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1200
$dbi->update($param, table => $table1, mtime => $key2, where => {$key1 => 1});
1201
$result = $dbi->select(table => $table1);
1202
is_deeply($param, {$key3 => 4});
1203
$row   = $result->one;
1204
is($row->{$key3}, 4);
1205
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1206

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1207
eval { $dbi->execute("drop table $table1") };
1208
$dbi->execute($create_table1_2);
1209
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1210
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1211
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key3 => 3});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1212
$result = $dbi->select(table => $table1);
1213
is_deeply($param, {$key3 => 4});
1214
$row   = $result->one;
1215
is($row->{$key3}, 4);
1216
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1217

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1218
eval { $dbi->execute("drop table $table1") };
1219
$dbi->execute($create_table1_2);
1220
$param = {$key3 => 4};
1221
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1222
$dbi->update($param, table => $table1, mtime => $key2, where => {$key3 => 3});
1223
$result = $dbi->select(table => $table1);
1224
is_deeply($param, {$key3 => 4});
1225
$row   = $result->one;
1226
is($row->{$key3}, 4);
1227
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1228

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
1229
eval { $dbi->execute("drop table $table1") };
1230
$dbi->execute($create_table1_2);
1231
$model = $dbi->create_model(table => $table1, updated_at => $key2);
1232
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1233
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
1234
$model->update($param, where => {$key1 => 1});
1235
$result = $dbi->select(table => $table1);
1236
is_deeply($param, {$key3 => 4});
1237
$row   = $result->one;
1238
is($row->{$key3}, 4);
1239
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1240

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1241
eval { $dbi->execute("drop table $table1") };
1242
$dbi->execute($create_table1_2);
1243
$model = $dbi->create_model(table => $table1, mtime => $key2);
1244
$param = {$key3 => 4};
1245
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1246
$model->update($param, where => {$key1 => 1});
1247
$result = $dbi->select(table => $table1);
1248
is_deeply($param, {$key3 => 4});
1249
$row   = $result->one;
1250
is($row->{$key3}, 4);
1251
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1252

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1253
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1254
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1255
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1256
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1257
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1258
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
1259
$dbi->update_all({$key2 => 10}, table => $table1, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1260
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1261
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1262
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1263
  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
1264
  "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1265

            
1266
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1267
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1268
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1269
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1270
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1271
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1272
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1273
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1274
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1275

            
cleanup test
Yuki Kimoto authored on 2011-08-15
1276
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
1277
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1278
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1279
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1280
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1281
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1282
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1283
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1284

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1287
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1288
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1289
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1290
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
1291
$rows = $dbi->select(table => $table1)->all;
1292
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1293

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1305
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1306
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1307
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1308
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1309
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
1310
  table => $table1,
1311
  where => [
1312
    ['and', "$key1 = :$key1", "$key2 = :$key2"],
1313
    {ke1 => 1, $key2 => 2}
1314
  ]
test cleanup
Yuki Kimoto authored on 2011-08-10
1315
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1316
$result = $dbi->select(table => $table1);
1317
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1318

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1319
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1320
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1321
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1322
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
1323
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1324
$rows   = $result->all;
1325
is_deeply($rows, [], "basic");
1326

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1336
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
1337
$dbi = DBIx::Custom->connect;
1338
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1339
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1340
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1341
$dbi->insert({select => 1}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1342
$dbi->delete(table => 'table', where => {select => 1});
1343
$result = $dbi->execute("select * from ${q}table$p");
1344
$rows   = $result->all;
1345
is_deeply($rows, [], "reserved word");
1346

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

            
1357
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1358
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1359
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1360
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1361
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1362
$rows = $dbi->select(table => $table1)->all;
1363
is_deeply($rows, [{$key1 => 1, $key2 => 2},
cleanup
Yuki Kimoto authored on 2012-01-20
1364
  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
1365

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1380
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1381
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
1382
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1383
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1384
  table => [$table1, $table2],
fixed test
Yuki Kimoto authored on 2012-03-01
1385
  column => "$table1.$key1 as " . u("${table1}_$key1")
1386
    . ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
1387
  where   => {"$table1.$key2" => 2},
1388
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1389
)->all;
fixed test
Yuki Kimoto authored on 2012-03-01
1390
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
1391

            
1392
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1393
  table => [$table1, $table2],
fixed test
Yuki Kimoto authored on 2012-03-01
1394
  column => ["$table1.$key1 as " . u("${table1}_$key1") . ", ${table2}.$key1 as " . u("${table2}_$key1"), $key2, $key3],
cleanup
Yuki Kimoto authored on 2012-01-20
1395
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1396
)->all;
fixed test
Yuki Kimoto authored on 2012-03-01
1397
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
1398

            
1399
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
1400
eval { $dbi->execute("drop table ${q}table$p") };
1401
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1402
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1403
$dbi->insert({select => 1, update => 2}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1404
$result = $dbi->select(table => 'table', where => {select => 1});
1405
$rows   = $result->all;
1406
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
1407

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
1408
eval { $dbi->execute("drop table $table1") };
1409
$dbi->execute($create_table1);
1410
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1411
$row = $dbi->select($key1, table => $table1)->one;
1412
is_deeply($row, {$key1 => 1});
1413

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

            
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
1417
eval { $dbi->execute("drop table $table1") };
1418
$dbi->execute($create_table1);
1419
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1420
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
1421
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
1422

            
1423
$rows = $dbi->select(table => $table1, where => {$key1 => [1, 5]})->all;
1424
is_deeply($rows, [
1425
  {$key1 => 1, $key2 => 2},
1426
  {$key1 => 5, $key2 => 6}
1427
], "table");
1428

            
1429
$rows = $dbi->select(table => $table1, where => {$key1 => []})->all;
1430
is_deeply($rows, [], "table");
1431

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1432
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1433
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1434
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1435
  twice       => sub { $_[0] * 2 },
1436
  three_times => sub { $_[0] * 3 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1437
);
1438
$dbi->default_fetch_filter('twice');
1439
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1440
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1441
$result = $dbi->select(table => $table1);
1442
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1443
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1444
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1445

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1446
$dbi->default_fetch_filter('twice');
1447
eval { $dbi->execute("drop table $table1") };
1448
$dbi->execute($create_table1);
1449
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1450
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1451
$result->filter({$key1 => 'three_times'});
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1452
$row = $result->fetch_one;
1453
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter");
1454

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1461
test 'filters';
1462
$dbi = DBIx::Custom->new;
1463

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1470
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1471
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1472
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1473
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1474
$dbi->begin_work;
1475
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1476
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1477
$dbi->rollback;
1478
$dbi->dbh->{AutoCommit} = 1;
1479

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

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

            
1484
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1485
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1486
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1487
$dbi->begin_work;
1488
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1489
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1490
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1491
$dbi->commit;
1492
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1493
$result = $dbi->select(table => $table1);
1494
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
cleanup
Yuki Kimoto authored on 2012-01-20
1495
  "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1496

            
1497
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1498
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1499
$dbi->execute($create_table1);
1500
{
cleanup
Yuki Kimoto authored on 2012-01-20
1501
  local $Carp::Verbose = 0;
1502
  eval{$dbi->execute("select * frm $table1")};
1503
  like($@, qr/\Qselect * frm $table1/, "fail prepare");
1504
  like($@, qr/\.t /, "fail : not verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1505
}
1506
{
cleanup
Yuki Kimoto authored on 2012-01-20
1507
  local $Carp::Verbose = 1;
1508
  eval{$dbi->execute("select * frm $table1")};
1509
  like($@, qr/Custom.*\.t /s, "fail : verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1510
}
1511

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

            
1517
{
cleanup
Yuki Kimoto authored on 2012-01-20
1518
  local $Carp::Verbose = 0;
1519
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1520
  like($@, qr/\Q.t /, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1521
}
1522
{
cleanup
Yuki Kimoto authored on 2012-01-20
1523
  local $Carp::Verbose = 1;
1524
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1525
  like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1526
}
1527

            
1528

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1529
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1530
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1531
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1532
$dbi->execute($create_table1);
1533

            
1534
$dbi->begin_work;
1535

            
1536
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1537
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1538
  die "Error";
1539
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1540
};
1541

            
1542
$dbi->rollback if $@;
1543

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

            
1548
$dbi->begin_work;
1549

            
1550
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1551
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1552
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1553
};
1554

            
1555
$dbi->commit unless $@;
1556

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

            
1561
$dbi->dbh->{AutoCommit} = 0;
1562
eval{ $dbi->begin_work };
1563
ok($@, "exception");
1564
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1565

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1566
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1567
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1568
$dbi->cache(1);
1569
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1570
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1571
$dbi->execute($source, {}, query => 1);
1572
is_deeply($dbi->{_cached}->{$source}, 
cleanup
Yuki Kimoto authored on 2012-01-20
1573
  {sql => " select * from $table1 where $key1 = ?  and $key2 = ? ", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1574

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1575
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1576
$dbi->execute($create_table1);
1577
$dbi->{_cached} = {};
1578
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1579
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1580
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1581

            
1582
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1583
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1584
$dbi->execute($create_table1);
1585
{
cleanup
Yuki Kimoto authored on 2012-01-20
1586
  local $Carp::Verbose = 0;
1587
  eval{$dbi->execute("select * frm $table1")};
1588
  like($@, qr/\Qselect * frm $table1/, "fail prepare");
1589
  like($@, qr/\.t /, "fail : not verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1590
}
1591
{
cleanup
Yuki Kimoto authored on 2012-01-20
1592
  local $Carp::Verbose = 1;
1593
  eval{$dbi->execute("select * frm $table1")};
1594
  like($@, qr/Custom.*\.t /s, "fail : verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1595
}
1596

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

            
1602
{
cleanup
Yuki Kimoto authored on 2012-01-20
1603
  local $Carp::Verbose = 0;
1604
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1605
  like($@, qr/\Q.t /, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1606
}
1607
{
cleanup
Yuki Kimoto authored on 2012-01-20
1608
  local $Carp::Verbose = 1;
1609
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1610
  like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1611
}
1612

            
1613
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1614
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1615
  one => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1616
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1617
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1618
  two => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1619
);
1620
$dbi->method({
cleanup
Yuki Kimoto authored on 2012-01-20
1621
  twice => sub {
1622
    my $self = shift;
1623
    return $_[0] * 2;
1624
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
1625
});
1626

            
1627
is($dbi->one, 1, "first");
1628
is($dbi->two, 2, "second");
1629
is($dbi->twice(5), 10 , "second");
1630

            
1631
eval {$dbi->XXXXXX};
1632
ok($@, "not exists");
1633

            
1634
test 'out filter';
1635
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1636
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1637
$dbi->execute($create_table1);
1638
$dbi->register_filter(twice => sub { $_[0] * 2 });
1639
$dbi->register_filter(three_times => sub { $_[0] * 3});
1640
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1641
  $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1642
            $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
1643
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1644
$result = $dbi->execute("select * from $table1");
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1645
$row   = $result->fetch_hash_one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1646
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1647
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1648
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1649
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1650

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1656
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1657
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1658
$dbi->execute($create_table1);
1659
$dbi->register_filter(twice => sub { $_[0] * 2 });
1660
$dbi->register_filter(three_times => sub { $_[0] * 3});
1661
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1662
  $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1663
            $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1664
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1665
  $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1666
); 
test cleanup
Yuki Kimoto authored on 2011-11-01
1667
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1668
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1669
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1670
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1671

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

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

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

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

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

            
1738
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1739
eval { $dbi->execute("drop table $table1") };
1740
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1741
$dbi->execute($create_table1);
1742
$dbi->execute($create_table2);
1743
$dbi->register_filter(twice => sub { $_[0] * 2 });
1744
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1745
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1746
  $table1, $key2 => {out => 'twice', in => 'twice'}
cleanup test
Yuki Kimoto authored on 2011-08-15
1747
);
1748
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1749
  $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1750
);
cleanup
Yuki Kimoto authored on 2011-11-01
1751
$dbi->insert({$key1 => 5, $key2 => 2}, table => $table1, filter => {$key2 => undef});
1752
$dbi->insert({$key1 => 5, $key3 => 6}, table => $table2, filter => {$key3 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1753
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1754
  table => [$table1, $table2],
1755
  column => [$key2, $key3],
1756
  where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
cleanup test
Yuki Kimoto authored on 2011-08-15
1757

            
1758
$result->filter({$key2 => 'twice'});
1759
$rows   = $result->all;
1760
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1761

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

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

            
1771
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1772
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1773
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1774
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1775
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1776
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1777

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1778
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1779
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1780
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1781
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1782
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1783
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1784

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

            
1791
test 'end_filter';
1792
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1793
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1794
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1795
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1796
$result = $dbi->select(table => $table1);
1797
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1798
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1799
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1800
is_deeply($row, [6, 40]);
1801

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1802
$dbi = DBIx::Custom->connect;
1803
eval { $dbi->execute("drop table $table1") };
1804
$dbi->execute($create_table1);
1805
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1806
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1807
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1808
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1809
$row = $result->fetch_one;
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1810
is_deeply($row, [6, 6, 40]);
1811

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1812
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1813
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1814
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1815
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1816
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1817
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1818
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1819
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1820
is_deeply($row, [6, 12]);
1821

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

            
1832
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1833
$result = $dbi->select(table => $table1);
1834
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1835
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1836
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1837
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1838

            
1839
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1840
$dbi->apply_filter($table1,
cleanup
Yuki Kimoto authored on 2012-01-20
1841
  $key1 => {end => sub { $_[0] * 3 } },
1842
  $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1843
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1844
$result = $dbi->select(table => $table1);
1845
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1846
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1847
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1848

            
1849
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1850
$dbi->apply_filter($table1,
cleanup
Yuki Kimoto authored on 2012-01-20
1851
  $key1 => {end => sub { $_[0] * 3 } },
1852
  $key2 => {end => 'five_times'}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1853
);
1854
$result = $dbi->select(table => $table1);
1855
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1856
$result->filter($key1 => undef);
1857
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1858
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1859
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1860

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1861
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1862
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1863
$result->filter($key1 => undef);
1864
$result->end_filter($key1 => undef);
1865
$row = $result->fetch;
1866
is_deeply($row, [1, 1, 40], 'apply_filter overwrite');
1867

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1868
test 'remove_end_filter and remove_filter';
1869
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1870
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1871
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1872
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1873
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1874
$row = $result
cleanup
Yuki Kimoto authored on 2012-01-20
1875
  ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
1876
  ->remove_filter
1877
  ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
1878
  ->remove_end_filter
1879
  ->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1880
is_deeply($row, [1, 2]);
1881

            
1882
test 'empty where select';
1883
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1884
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1885
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1886
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1887
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1888
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1889
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1890

            
1891
test 'select query option';
1892
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1893
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1894
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1895
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1896
ok(ref $query);
cleanup
Yuki Kimoto authored on 2011-11-01
1897
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1898
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1899
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1900
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1901
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1902
ok(ref $query);
test cleanup
Yuki Kimoto authored on 2011-08-10
1903

            
1904
test 'where';
1905
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1906
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1907
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1908
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1909
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1910
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1911
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1912

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

            
1917
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1918
  table => $table1,
1919
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1920
);
1921
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1922
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1923

            
1924
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1925
  table => $table1,
1926
  where => [
1927
    ['and', "$key1 = :$key1", "$key2 = :$key2"],
1928
    {$key1 => 1}
1929
  ]
test cleanup
Yuki Kimoto authored on 2011-08-10
1930
);
1931
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1932
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1933

            
1934
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1935
  ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1936
  ->param({$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1937
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1938
  table => $table1,
1939
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1940
);
1941
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1942
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1943

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

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

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

            
1972
eval {
1973
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1974
           ->clause(['uuu']);
test cleanup
Yuki Kimoto authored on 2011-08-10
1975
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1976
  table => $table1,
1977
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1978
);
1979
};
1980
ok($@);
1981

            
1982
$where = $dbi->where;
1983
is("$where", '');
1984

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

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

            
2005
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2006
  ->clause(['or', ("$key1 = :$key1") x 2])
2007
  ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
2008
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2009
  table => $table1,
2010
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2011
);
2012
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2013
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2014

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2154
eval {$dbi->where(ppp => 1) };
2155
like($@, qr/invalid/);
2156

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

            
2168

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

            
2180
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2181
$where->clause(['and', ":${key1}{=}"]);
2182
$where->param({$key1 => undef});
2183
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
2184
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2185
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2186

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

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

            
2198
$dbi = DBIx::Custom->connect;
2199
eval { $dbi->execute("drop table $table1") };
2200
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2201
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
2202
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2203
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2204
  ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
2205
  ->param({$key1 => 1});
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2206

            
2207
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2208
  table => $table1,
2209
  where => $where
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2210
);
2211
$row = $result->all;
2212
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
2213

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2214
test 'register_tag_processor';
2215
$dbi = DBIx::Custom->connect;
2216
$dbi->register_tag_processor(
cleanup
Yuki Kimoto authored on 2012-01-20
2217
  a => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
2218
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2219
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2220

            
2221
test 'register_tag';
2222
$dbi = DBIx::Custom->connect;
2223
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
2224
  b => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
2225
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2226
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2227

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2233
test 'more tests';
2234
$dbi = DBIx::Custom->connect;
2235
eval{$dbi->apply_filter('table', 'column', [])};
2236
like($@, qr/apply_filter/);
2237

            
2238
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
2239
like($@, qr/apply_filter/);
2240

            
2241
$dbi->apply_filter(
2242

            
2243
);
2244
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2245
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2246
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2247
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2248
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2249
$dbi->apply_filter($table1, $key2, 
cleanup
Yuki Kimoto authored on 2012-01-20
2250
                 {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2251
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
2252
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2253

            
2254
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2255
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2256
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2257
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2258
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2259
$dbi->apply_filter($table1, $key2, {});
2260
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
2261
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2262

            
2263
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2264
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2265
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2266
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2267
like($@, qr/not registered/);
2268
$dbi->method({one => sub { 1 }});
2269
is($dbi->one, 1);
2270

            
2271
eval{DBIx::Custom->connect(dsn => undef)};
2272
like($@, qr/_connect/);
2273

            
2274
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2275
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2276
$dbi->execute($create_table1);
2277
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
2278
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
2279
           filter => {$key1 => 'twice'});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2280
$row = $dbi->select(table => $table1)->one;
2281
is_deeply($row, {$key1 => 2, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
2282
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
2283
           filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
2284
like($@, qr//);
2285

            
2286
$dbi->register_filter(one => sub { });
2287
$dbi->default_fetch_filter('one');
2288
ok($dbi->default_fetch_filter);
2289
$dbi->default_bind_filter('one');
2290
ok($dbi->default_bind_filter);
2291
eval{$dbi->default_fetch_filter('no')};
2292
like($@, qr/not registered/);
2293
eval{$dbi->default_bind_filter('no')};
2294
like($@, qr/not registered/);
2295
$dbi->default_bind_filter(undef);
2296
ok(!defined $dbi->default_bind_filter);
2297
$dbi->default_fetch_filter(undef);
2298
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2299
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2300
like($@, qr/Tag not finished/);
2301

            
2302
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2303
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2304
$dbi->execute($create_table1);
2305
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2306
$result = $dbi->select(table => $table1);
2307
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2308
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2309
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2310
like($@, qr/not registered/);
2311
$result->default_filter(undef);
2312
ok(!defined $result->default_filter);
2313
$result->default_filter('one');
2314
is($result->default_filter->(), 1);
2315

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2316
test 'option';
2317
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
2318
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
2319
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2320
ok($dbi->dbh->{PrintError});
2321
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2322
ok($dbi->dbh->{PrintError});
2323

            
2324
test 'DBIx::Custom::Result stash()';
2325
$result = DBIx::Custom::Result->new;
2326
is_deeply($result->stash, {}, 'default');
2327
$result->stash->{foo} = 1;
2328
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2329

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2330
test 'delete_at';
2331
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2332
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2333
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2334
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2335
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2336
  table => $table1,
2337
  primary_key => [$key1, $key2],
2338
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2339
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2340
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2341

            
cleanup
Yuki Kimoto authored on 2011-11-01
2342
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2343
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2344
  table => $table1,
2345
  primary_key => $key1,
2346
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2347
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2348
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2349

            
2350
test 'insert_at';
2351
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2352
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2353
$dbi->execute($create_table1_2);
2354
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2355
  {$key3 => 3},
2356
  primary_key => [$key1, $key2], 
2357
  table => $table1,
2358
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2359
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2360
is($dbi->select(table => $table1)->one->{$key1}, 1);
2361
is($dbi->select(table => $table1)->one->{$key2}, 2);
2362
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2363

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2364
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2365
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2366
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2367
  {$key2 => 2, $key3 => 3},
2368
  primary_key => $key1, 
2369
  table => $table1,
2370
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2371
);
2372

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

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

            
2390
test 'update_at';
2391
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2392
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2393
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2394
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2395
$dbi->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2396
  {$key3 => 4},
2397
  table => $table1,
2398
  primary_key => [$key1, $key2],
2399
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2400
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2401
is($dbi->select(table => $table1)->one->{$key1}, 1);
2402
is($dbi->select(table => $table1)->one->{$key2}, 2);
2403
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2404

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2405
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2406
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2407
$dbi->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2408
  {$key3 => 4},
2409
  table => $table1,
2410
  primary_key => $key1,
2411
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2412
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2413
is($dbi->select(table => $table1)->one->{$key1}, 1);
2414
is($dbi->select(table => $table1)->one->{$key2}, 2);
2415
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2416

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

            
2431
test 'select_at';
2432
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2433
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2434
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2435
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2436
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2437
  table => $table1,
2438
  primary_key => [$key1, $key2],
2439
  where => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2440
);
2441
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2442
is($row->{$key1}, 1);
2443
is($row->{$key2}, 2);
2444
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2445

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2446
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2447
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2448
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2449
  table => $table1,
2450
  primary_key => $key1,
2451
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2452
);
2453
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2454
is($row->{$key1}, 1);
2455
is($row->{$key2}, 2);
2456
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2457

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2458
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2459
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2460
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2461
  table => $table1,
2462
  primary_key => [$key1, $key2],
2463
  where => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2464
);
2465
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2466
is($row->{$key1}, 1);
2467
is($row->{$key2}, 2);
2468
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2469

            
2470
test 'model delete_at';
2471
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2472
eval { $dbi->execute("drop table $table1") };
2473
eval { $dbi->execute("drop table $table2") };
2474
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2475
$dbi->execute($create_table1_2);
2476
$dbi->execute($create_table2_2);
2477
$dbi->execute($create_table3);
test cleanup
Yuki Kimoto authored on 2011-11-01
2478
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2479
$dbi->model($table1)->delete_at(where => [1, 2]);
2480
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2481
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2482
$dbi->model($table1)->delete_at(where => [1, 2]);
2483
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2484
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2485
$dbi->model($table3)->delete_at(where => [1, 2]);
2486
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2487

            
2488
test 'model insert_at';
2489
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2490
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2491
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2492
$dbi->model($table1)->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2493
  {$key3 => 3},
2494
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2495
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2496
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
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 update_at';
2503
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2504
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2505
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2506
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2507
$dbi->model($table1)->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2508
  {$key3 => 4},
2509
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2510
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2511
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2512
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2513
is($row->{$key1}, 1);
2514
is($row->{$key2}, 2);
2515
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2516

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

            
2528

            
2529
test 'mycolumn and column';
2530
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2531
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2532
eval { $dbi->execute("drop table $table1") };
2533
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2534
$dbi->execute($create_table1);
2535
$dbi->execute($create_table2);
2536
$dbi->separator('__');
improved test
Yuki Kimoto authored on 2012-03-01
2537
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
2538
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2539
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2540
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2541
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2542
  column => [$model->mycolumn, $model->column($table2)],
2543
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2544
);
2545
is_deeply($result->one,
improved test
Yuki Kimoto authored on 2012-03-01
2546
        {$key1 => 1, $key2 => 2, u2"${table2}__$key1" => 1, u2"${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2547

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2548
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2549
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2550
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2551
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2552
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2553
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2554
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2555
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2556
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2557
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2558
is($dbi->select(table => $table1)->one->{$key1}, 1);
2559
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2560

            
2561
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2562
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2563
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2564
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2565
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2566
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2567
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2568
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2569
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2570
is($dbi->select(table => $table1)->one->{$key1}, 1);
2571
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2572

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2573
test 'mycolumn';
2574
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2575
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2576
eval { $dbi->execute("drop table $table1") };
2577
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2578
$dbi->execute($create_table1);
2579
$dbi->execute($create_table2);
improved test
Yuki Kimoto authored on 2012-03-01
2580
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
2581
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2582
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2583
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2584
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2585
  column => [
2586
    $model->mycolumn,
2587
    $model->column($table2)
2588
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2589
);
2590
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2591
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2592

            
2593
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2594
  column => [
2595
    $model->mycolumn([$key1]),
2596
    $model->column($table2 => [$key1])
2597
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2598
);
2599
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2600
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2601
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2602
  column => [
2603
    $model->mycolumn([$key1]),
2604
    {$table2 => [$key1]}
2605
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2606
);
2607
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2608
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2609

            
2610
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2611
  column => [
2612
    $model->mycolumn([$key1]),
2613
    ["$table2.$key1", as => "$table2.$key1"]
2614
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2615
);
2616
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2617
  {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2618

            
2619
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2620
  column => [
2621
    $model->mycolumn([$key1]),
2622
    ["$table2.$key1" => "$table2.$key1"]
2623
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2624
);
2625
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2626
  {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2627

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2628
test 'merge_param';
2629
$dbi = DBIx::Custom->new;
2630
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2631
  {$key1 => 1, $key2 => 2, $key3 => 3},
2632
  {$key1 => 1, $key2 => 2},
2633
  {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2634
];
2635
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2636
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2637

            
2638
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2639
  {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2640
  {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2641
];
2642
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2643
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
2644

            
2645
test 'select() param option';
2646
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2647
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2648
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2649
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2650
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2651
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2652
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2653
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
2654
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
2655
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2656
  table => $table1,
improved test
Yuki Kimoto authored on 2012-03-01
2657
  column => "$table1.$key1 as " . u("${table1}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
2658
  where   => {"$table1.$key2" => 3},
2659
  join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
improved test
Yuki Kimoto authored on 2012-03-01
2660
            " $q$table2$p on $table1.$key1 = $q$table2$p.$key1"],
cleanup
Yuki Kimoto authored on 2012-01-20
2661
  param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2662
)->all;
improved test
Yuki Kimoto authored on 2012-03-01
2663
is_deeply($rows, [{u"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2664

            
cleanup
Yuki Kimoto authored on 2011-10-21
2665
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2666
  table => $table1,
improved test
Yuki Kimoto authored on 2012-03-01
2667
  column => "$table1.$key1 as " . u("${table1}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
2668
  where   => {"$table1.$key2" => 3},
2669
  join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
improved test
Yuki Kimoto authored on 2012-03-01
2670
           " $q$table2$p on $table1.$key1 = $q$table2$p.$key1",
cleanup
Yuki Kimoto authored on 2012-01-20
2671
  param => {"$table2.$key3" => 5}
cleanup
Yuki Kimoto authored on 2011-10-21
2672
)->all;
improved test
Yuki Kimoto authored on 2012-03-01
2673
is_deeply($rows, [{u"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup
Yuki Kimoto authored on 2011-10-21
2674

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2675
test 'select() string where';
2676
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2677
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2678
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2679
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2680
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2681
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2682
  table => $table1,
2683
  where => "$key1 = :$key1 and $key2 = :$key2",
2684
  where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2685
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2686
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2687

            
2688
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2689
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2690
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2691
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2692
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2693
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2694
  table => $table1,
2695
  where => [
2696
    "$key1 = :$key1 and $key2 = :$key2",
2697
    {$key1 => 1, $key2 => 2}
2698
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2699
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2700
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2701

            
cleanup
Yuki Kimoto authored on 2011-10-21
2702
$dbi = DBIx::Custom->connect;
2703
eval { $dbi->execute("drop table $table1") };
2704
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2705
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2706
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
2707
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2708
  table => $table1,
2709
  where => [
2710
    "$key1 = :$key1 and $key2 = :$key2",
2711
    {$key1 => 1, $key2 => 2}
2712
  ]
cleanup
Yuki Kimoto authored on 2011-10-21
2713
)->all;
2714
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2715

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

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

            
2745

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

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

            
2775
test 'insert id and primary_key option';
2776
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2777
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2778
$dbi->execute($create_table1_2);
2779
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2780
  {$key3 => 3},
2781
  primary_key => [$key1, $key2], 
2782
  table => $table1,
2783
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2784
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2785
is($dbi->select(table => $table1)->one->{$key1}, 1);
2786
is($dbi->select(table => $table1)->one->{$key2}, 2);
2787
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2788

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2789
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2790
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2791
  {$key2 => 2, $key3 => 3},
2792
  primary_key => $key1, 
2793
  table => $table1,
2794
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2795
);
2796

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2801
$dbi = DBIx::Custom->connect;
2802
eval { $dbi->execute("drop table $table1") };
2803
$dbi->execute($create_table1_2);
2804
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2805
  {$key3 => 3},
2806
  primary_key => [$key1, $key2], 
2807
  table => $table1,
2808
  id => 1,
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2809
);
2810
is($dbi->select(table => $table1)->one->{$key1}, 1);
2811
ok(!$dbi->select(table => $table1)->one->{$key2});
2812
is($dbi->select(table => $table1)->one->{$key3}, 3);
2813

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2814
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2815
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2816
$dbi->execute($create_table1_2);
2817
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2818
  {$key3 => 3},
2819
  primary_key => [$key1, $key2], 
2820
  table => $table1,
2821
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2822
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2823
is($dbi->select(table => $table1)->one->{$key1}, 1);
2824
is($dbi->select(table => $table1)->one->{$key2}, 2);
2825
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2826

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2827
$dbi = DBIx::Custom->connect;
2828
eval { $dbi->execute("drop table $table1") };
2829
$dbi->execute($create_table1_2);
2830
$param = {$key3 => 3, $key2 => 4};
2831
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2832
  $param,
2833
  primary_key => [$key1, $key2], 
2834
  table => $table1,
2835
  id => [1, 2],
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2836
);
2837
is($dbi->select(table => $table1)->one->{$key1}, 1);
2838
is($dbi->select(table => $table1)->one->{$key2}, 4);
2839
is($dbi->select(table => $table1)->one->{$key3}, 3);
2840
is_deeply($param, {$key3 => 3, $key2 => 4});
2841

            
added test
Yuki Kimoto authored on 2011-10-25
2842
$dbi = DBIx::Custom->connect;
2843
eval { $dbi->execute("drop table $table1") };
2844
$dbi->execute($create_table1_2);
2845
$param = {$key3 => 3, $key2 => 4};
2846
$query = $dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2847
  $param,
2848
  primary_key => [$key1, $key2], 
2849
  table => $table1,
2850
  id => [1, 2],
2851
  query => 1
added test
Yuki Kimoto authored on 2011-10-25
2852
);
micro optimization
Yuki Kimoto authored on 2011-11-16
2853
ok(ref $query);
added test
Yuki Kimoto authored on 2011-10-25
2854
is_deeply($param, {$key3 => 3, $key2 => 4});
2855

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2856
test 'model insert id and primary_key option';
2857
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2858
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2859
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2860
$dbi->model($table1)->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2861
  {$key3 => 3},
2862
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2863
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2864
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2865
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2866
is($row->{$key1}, 1);
2867
is($row->{$key2}, 2);
2868
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2869

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2898
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2899
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2900
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2901
  {$key3 => 4},
2902
  table => $table1,
2903
  primary_key => $key1,
2904
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2905
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2906
is($dbi->select(table => $table1)->one->{$key1}, 0);
2907
is($dbi->select(table => $table1)->one->{$key2}, 2);
2908
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2909

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

            
2924

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

            
2940

            
2941
test 'delete and id option';
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->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2947
  table => $table1,
2948
  primary_key => [$key1, $key2],
2949
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2950
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2951
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2952

            
cleanup
Yuki Kimoto authored on 2011-11-01
2953
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2954
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2955
  table => $table1,
2956
  primary_key => $key1,
2957
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2958
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2959
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2960

            
2961

            
2962
test 'model delete and id option';
2963
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2964
eval { $dbi->execute("drop table $table1") };
2965
eval { $dbi->execute("drop table $table2") };
2966
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2967
$dbi->execute($create_table1_2);
2968
$dbi->execute($create_table2_2);
2969
$dbi->execute($create_table3);
cleanup
Yuki Kimoto authored on 2011-11-01
2970
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2971
$dbi->model($table1)->delete(id => [1, 2]);
2972
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2973
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2974
$dbi->model($table1)->delete(id => [1, 2]);
2975
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2976
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2977
$dbi->model($table3)->delete(id => [1, 2]);
2978
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2979

            
2980

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2996
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2997
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2998
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2999
  table => $table1,
3000
  primary_key => $key1,
3001
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
3002
);
3003
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3004
is($row->{$key1}, 0);
3005
is($row->{$key2}, 2);
3006
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
3007

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3008
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3009
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3010
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3011
  table => $table1,
3012
  primary_key => [$key1, $key2],
3013
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
3014
);
3015
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3016
is($row->{$key1}, 1);
3017
is($row->{$key2}, 2);
3018
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
3019

            
3020

            
3021
test 'model select_at';
3022
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3023
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3024
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
3025
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3026
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3027
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3028
is($row->{$key1}, 1);
3029
is($row->{$key2}, 2);
3030
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
3031

            
3032
test 'column separator is default .';
3033
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3034
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3035
eval { $dbi->execute("drop table $table1") };
3036
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3037
$dbi->execute($create_table1);
3038
$dbi->execute($create_table2);
improved test
Yuki Kimoto authored on 2012-03-01
3039
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
3040
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3041
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3042
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3043
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3044
  column => [$model->column($table2)],
3045
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3046
);
3047
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3048
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
3049

            
3050
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3051
  column => [$model->column($table2 => [$key1, $key3])],
3052
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3053
);
3054
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3055
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3056

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3057
test 'separator';
3058
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3059
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3060
eval { $dbi->execute("drop table $table1") };
3061
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3062
$dbi->execute($create_table1);
3063
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
3064

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3065
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3066
  table => $table1,
3067
  join => [
3068
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3069
  ],
3070
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
3071
);
3072
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3073
  table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
3074
);
improved test
Yuki Kimoto authored on 2012-03-01
3075
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
3076
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3077
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3078
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3079
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3080
  column => [
3081
    $model->mycolumn,
3082
    {$table2 => [$key1, $key3]}
3083
  ],
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
        {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3088
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3089

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3090
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3091
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3092
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3093
  column => [
3094
    $model->mycolumn,
3095
    {$table2 => [$key1, $key3]}
3096
  ],
3097
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3098
);
3099
is_deeply($result->one,
improved test
Yuki Kimoto authored on 2012-03-01
3100
        {$key1 => 1, $key2 => 2, u2"${table2}__$key1" => 1, u2"${table2}__$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3101
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3102

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3103
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3104
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3105
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3106
  column => [
3107
    $model->mycolumn,
3108
    {$table2 => [$key1, $key3]}
3109
  ],
3110
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3111
);
3112
is_deeply($result->one,
improved test
Yuki Kimoto authored on 2012-03-01
3113
  {$key1 => 1, $key2 => 2, hy"$table2-$key1" => 1, hy"$table2-$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3114
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3115

            
3116

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3117
test 'filter_off';
3118
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3119
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3120
eval { $dbi->execute("drop table $table1") };
3121
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3122
$dbi->execute($create_table1);
3123
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
3124

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3125
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3126
  table => $table1,
3127
  join => [
3128
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3129
  ],
3130
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
3131
);
improved test
Yuki Kimoto authored on 2012-03-01
3132
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
3133
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3134
$model = $dbi->model($table1);
3135
$result = $model->select(column => $key1);
3136
$result->filter($key1 => sub { $_[0] * 2 });
3137
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
3138

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3139
test 'available_datetype';
3140
$dbi = DBIx::Custom->connect;
3141
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
3142

            
3143

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3144
test 'select prefix option';
3145
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3146
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3147
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3148
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3149
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3150
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
3151

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

            
added tests
Yuki Kimoto authored on 2011-08-26
3153
test 'mapper';
3154
$dbi = DBIx::Custom->connect;
3155
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3156
  id => {key => "$table1.id"},
3157
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3158
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
3159
);
3160
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3161
"$table1.price" => 1900});
added tests
Yuki Kimoto authored on 2011-08-26
3162

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3163
$dbi = DBIx::Custom->connect;
3164
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3165
  id => {key => "$table1.id"},
3166
  author => ["$table1.author" => $dbi->like_value],
3167
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3168
);
3169
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3170
"$table1.price" => 1900});
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3171

            
added tests
Yuki Kimoto authored on 2011-08-26
3172
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3173
  id => {key => "$table1.id"},
3174
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3175
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
3176
);
3177
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
3178

            
3179
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3180
  id => {key => "$table1.id"},
3181
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3182
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
added tests
Yuki Kimoto authored on 2011-08-26
3183
);
3184
is_deeply($param, {});
3185

            
3186
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3187
  id => {key => "$table1.id"},
3188
  price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
3189
);
3190
is_deeply($param, {"$table1.price" => undef});
3191

            
3192
$param = $dbi->mapper(param => {price => 'a'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3193
  id => {key => "$table1.id", condition => 'exists'},
3194
  price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
3195
);
3196
is_deeply($param, {"$table1.price" => '%a'});
3197

            
3198
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3199
  id => {key => "$table1.id"},
3200
  price => ["$table1.price", sub { '%' . $_[0] }]
added tests
Yuki Kimoto authored on 2011-08-26
3201
);
3202
is_deeply($param, {"$table1.price" => '%a'});
3203

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3204
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3205
  price => sub { '%' . $_[0] },
3206
  author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
3207
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3208
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
3209

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

            
3215
$where = $dbi->where;
3216
$where->clause(['and', ":${key1}{=}"]);
3217
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
3218
$where->param($param);
3219
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3220
$row = $result->all;
3221
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3222

            
3223
$where = $dbi->where;
3224
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
3225
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
3226
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
3227
$row = $result->all;
3228
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3229
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
3230
$row = $result->all;
3231
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3232

            
3233
$where = $dbi->where;
3234
$where->clause(['and', ":${key1}{=}"]);
3235
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
3236
$where->param($param);
3237
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
3238
$row = $result->all;
3239
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3240
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
3241
$row = $result->all;
3242
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3243

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3245
$where = $dbi->where;
3246
$where->clause(['and', ":${key1}{=}"]);
3247
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
cleanup
Yuki Kimoto authored on 2012-01-20
3248
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3249
$where->param($param);
3250
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3251
$row = $result->all;
3252
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3253

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

            
3262
$where = $dbi->where;
3263
$where->clause(['and', ":${key1}{=}"]);
3264
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
cleanup
Yuki Kimoto authored on 2012-01-20
3265
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3266
$where->param($param);
3267
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3268
$row = $result->all;
3269
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3270

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3272
$where = $dbi->where;
3273
$where->clause(['and', ":${key1}{=}"]);
3274
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
3275
$where->param($param);
3276
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3277
$row = $result->all;
3278
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3279

            
3280
$where = $dbi->where;
3281
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3282
  id => {key => "$table1.id"},
3283
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3284
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3285
);
3286
$where->param($param);
3287
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3288
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3289

            
3290
$where = $dbi->where;
3291
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3292
  id => {key => "$table1.id"},
3293
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3294
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3295
);
3296
$where->param($param);
3297
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
3298

            
3299
$where = $dbi->where;
3300
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3301
  id => {key => "$table1.id"},
3302
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3303
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3304
);
3305
$where->param($param);
3306
is_deeply($where->param, {});
3307

            
3308
$where = $dbi->where;
3309
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3310
  id => {key => "$table1.id"},
3311
  price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3312
);
3313
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
3314

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

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

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

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

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

            
- DBIx::Custom::Mapper::map ...
Yuki Kimoto authored on 2012-02-29
3354
$param = $dbi->mapper(param => {author => 'Ken',})->map(
3355
  author => ["$table1.author" => '%<value>%'],
3356
);
3357
is_deeply($param, {"$table1.author" => '%Ken%'});
3358

            
3359
$param = $dbi->mapper(param => {author => 'Ken'})->map(
3360
  author => ["$table1.author" => 'p'],
3361
);
3362
is_deeply($param, {"$table1.author" => 'p'});
3363

            
3364
$param = $dbi->mapper(param => {author => 'Ken',})->map(
3365
  author => {value => '%<value>%'}
3366
);
3367
is_deeply($param, {"author" => '%Ken%'});
3368

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3369
test 'order';
3370
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3371
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3372
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3373
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3374
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3375
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3376
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3377
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3378
$order->prepend($key1, "$key2 desc");
3379
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3380
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
3381
{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3382
$order->prepend("$key1 desc");
3383
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3384
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
cleanup
Yuki Kimoto authored on 2012-01-20
3385
{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3386

            
3387
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3388
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3389
$result = $dbi->select(table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
3390
column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
3391
append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3392
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
cleanup
Yuki Kimoto authored on 2012-01-20
3393
{"$table1-$key1" => 1, "$table1-$key2" => 1},
3394
{"$table1-$key1" => 2, "$table1-$key2" => 4},
3395
{"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3396

            
3397
test 'tag_parse';
3398
$dbi = DBIx::Custom->connect;
3399
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3400
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3401
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3402
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3403
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3404
ok($@);
3405

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3406
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3407
{
cleanup
Yuki Kimoto authored on 2012-01-20
3408
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3409
  $dbi = DBIx::Custom->connect;
3410
  eval { $dbi->execute("drop table $table1") };
3411
  $dbi->execute($create_table1);
3412
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3413
  eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3414
  ok($@);
3415
  eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) };
3416
  ok($@);
3417
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3418
}
3419

            
3420
{
cleanup
Yuki Kimoto authored on 2012-01-20
3421
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3422
  $dbi = DBIx::Custom->connect;
3423
  eval { $dbi->execute("drop table $table1") };
3424
  $dbi->execute($create_table1);
3425
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3426
  is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1);
3427
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3428
}
3429

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3430
test 'last_sql';
3431
$dbi = DBIx::Custom->connect;
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);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3434
$dbi->execute("select * from $table1");
micro optimization
Yuki Kimoto authored on 2011-11-18
3435
is($dbi->last_sql, " select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3436

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3468
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3469
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
3470
  $source,
3471
  {"$table1.$key1" => 1, "$table1.$key2" => 1},
3472
  filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3473
);
3474
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3475
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3476

            
3477
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3478
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3479
$dbi->execute($create_table1_highperformance);
3480
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3481
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3482
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3483
];
3484
{
cleanup
Yuki Kimoto authored on 2012-01-20
3485
  my $query;
3486
  for my $row (@$rows) {
3487
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3488
    $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3489
  }
3490
  is_deeply($dbi->select(table => $table1)->all,
3491
    [
3492
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3493
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3494
    ]
3495
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3496
}
3497

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3498
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3499
$dbi->execute($create_table1_highperformance);
3500
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3501
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3502
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3503
];
3504
{
cleanup
Yuki Kimoto authored on 2012-01-20
3505
  my $query;
3506
  my $sth;
3507
  for my $row (@$rows) {
3508
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3509
    $sth ||= $query->{sth};
3510
    $sth->execute(map { $row->{$_} } sort keys %$row);
3511
  }
3512
  is_deeply($dbi->select(table => $table1)->all,
3513
    [
3514
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3515
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3516
    ]
3517
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3518
}
3519

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3520
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3521
$dbi->execute($create_table1_highperformance);
3522
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3523
  {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
3524
  {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3525
];
3526
{
cleanup
Yuki Kimoto authored on 2012-01-20
3527
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3528
  my $query;
3529
  for my $row (@$rows) {
3530
    $query ||= $model->insert($row, query => 1);
3531
    $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3532
  }
3533
  is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3534
    [
3535
      {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3536
      {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
3537
    ]
3538
  );
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3539
}
3540

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3541
eval { $dbi->execute("drop table $table1") };
3542
$dbi->execute($create_table1);
3543
{
cleanup
Yuki Kimoto authored on 2012-01-20
3544
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3545
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3546
  eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3547
  like($@, qr/primary_key/);
3548
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3549
}
3550

            
3551
{
cleanup
Yuki Kimoto authored on 2012-01-20
3552
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3553
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3554
  $model->insert({$key1 => 1});
3555
  $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3556
    table => $table1, primary_key => $key1);
3557
  is($result->one->{$key1}, 1);
3558
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3559
}
3560

            
3561
eval { $dbi->execute("drop table $table1") };
3562
$dbi->execute($create_table1);
3563
{
cleanup
Yuki Kimoto authored on 2012-01-20
3564
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3565
  $model->insert({$key1 => 1});
3566
  eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3567
  is($result->one->{$key1}, 1);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3568
}
3569

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3570
test 'id option more';
3571
eval { $dbi->execute("drop table $table1") };
3572
$dbi->execute($create_table1_highperformance);
3573
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3574
  $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
3575
};
3576
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3577
$model->insert($row);
3578
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3579
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3580
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3581
  {$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
3582
);
3583

            
3584
eval { $dbi->execute("drop table $table1") };
3585
eval { $dbi->execute("drop table $table2") };
3586
$dbi->execute($create_table1);
3587
$dbi->execute($create_table2);
3588
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3589
$model->insert({$key1 => 1, $key2 => 2});
3590
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
3591
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3592
$model->insert({$key1 => 1, $key3 => 3});
3593
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3594
  column => {$table1 => ["$key2"]},
3595
  id => 1
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3596
);
3597
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3598

            
3599
eval { $dbi->execute("drop table $table1") };
3600
$dbi->execute($create_table1_highperformance);
3601
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3602
  $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
3603
};
3604
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3605
$model->insert($row);
3606
$query = $model->delete(id => 1, query => 1);
3607
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3608
is_deeply($dbi->select(table => $table1)->all, []);
3609

            
3610
eval { $dbi->execute("drop table $table1") };
3611
eval { $dbi->execute($create_table1_highperformance) };
3612
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3613
  $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
3614
};
3615
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3616
$model->insert($row);
3617
$query = $model->select(id => 1, query => 1);
3618
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3619
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3620
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3621
  {$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
3622
);
3623

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3624
test 'result';
3625
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3626
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3627
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3628
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3629
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3630

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3631
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3632
@rows = ();
3633
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
3634
  push @rows, [@$row];
test cleanup
Yuki Kimoto authored on 2011-08-10
3635
}
3636
is_deeply(\@rows, [[1, 2], [3, 4]]);
3637

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3638
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3639
@rows = ();
3640
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
3641
  push @rows, {%$row};
test cleanup
Yuki Kimoto authored on 2011-08-10
3642
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3643
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3644

            
3645
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3646
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3647
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3648
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3649
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3650

            
3651
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3652
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3653
$rows = $result->fetch_all;
3654
is_deeply($rows, [[1, 2], [3, 4]]);
3655

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3660
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3661
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3662
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3663
$rows = $result->fetch_all;
3664
is_deeply($rows, [[3, 2], [9, 4]], "array");
3665

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2012-02-28
3678
test 'flat';
3679
$result = $dbi->select(table => $table1);
3680
$rows = [$result->flat];
3681
is_deeply($rows, [1, 2, 3, 4]);
3682

            
added EXPERIMETAL DBIx::Cust...
Yuki Kimoto authored on 2012-02-28
3683
test 'kv';
3684
$dbi = DBIx::Custom->connect;
3685
eval { $dbi->execute("drop table $table1") };
3686
$dbi->execute($create_table1);
3687
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3688
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3689

            
3690
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key1");
3691
$rows = $result->kv;
3692
is_deeply($rows, {0 => {$key2 => 2}, 3 => {$key2 => 4}});
3693

            
3694
$dbi = DBIx::Custom->connect;
3695
eval { $dbi->execute("drop table $table1") };
3696
$dbi->execute($create_table1);
3697
$dbi->insert({$key1 => 0, $key2 => 1}, table => $table1);
3698
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3699
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3700
$dbi->insert({$key1 => 3, $key2 => 5}, table => $table1);
3701

            
3702
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key2");
3703
$rows = $result->kv(multi => 1);
3704
is_deeply($rows, {
3705
  0 => [
3706
    {$key2 => 1},
3707
    {$key2 => 2}
3708
  ],
3709
  3 => [
3710
    {$key2 => 4},
3711
    {$key2 => 5}
3712
  ]
3713
});
3714

            
3715

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3716
test 'DBIx::Custom::Result fetch_multi';
3717
eval { $dbi->execute("drop table $table1") };
3718
$dbi->execute($create_table1);
3719
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3720
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3721
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3722
$result = $dbi->select(table => $table1);
3723
$rows = $result->fetch_multi(2);
3724
is_deeply($rows, [[1, 2], [3, 4]]);
3725
$rows = $result->fetch_multi(2);
3726
is_deeply($rows, [[5, 6]]);
3727
$rows = $result->fetch_multi(2);
3728
ok(!$rows);
3729

            
3730
test 'DBIx::Custom::Result fetch_hash_multi';
3731
eval { $dbi->execute("drop table $table1") };
3732
$dbi->execute($create_table1);
3733
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3734
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3735
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3736
$result = $dbi->select(table => $table1);
3737
$rows = $result->fetch_hash_multi(2);
3738
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3739
$rows = $result->fetch_hash_multi(2);
3740
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3741
$rows = $result->fetch_hash_multi(2);
3742
ok(!$rows);
3743

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3744
test "query_builder";
3745
$datas = [
cleanup
Yuki Kimoto authored on 2012-01-20
3746
  # Basic tests
3747
  {   name            => 'placeholder basic',
3748
    source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
3749
    sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
3750
    columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3751
  },
3752
  {
3753
    name            => 'placeholder in',
3754
    source            => "{in k1 3}",
3755
    sql_expected    => "k1 in (?, ?, ?)",
3756
    columns_expected   => [qw/k1 k1 k1/]
3757
  },
3758
  
3759
  # Table name
3760
  {
3761
    name            => 'placeholder with table name',
3762
    source            => "{= a.k1} {= a.k2}",
3763
    sql_expected    => "a.k1 = ? a.k2 = ?",
3764
    columns_expected  => [qw/a.k1 a.k2/]
3765
  },
3766
  {   
3767
    name            => 'placeholder in with table name',
3768
    source            => "{in a.k1 2} {in b.k2 2}",
3769
    sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
3770
    columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3771
  },
3772
  {
3773
    name            => 'not contain tag',
3774
    source            => "aaa",
3775
    sql_expected    => "aaa",
3776
    columns_expected  => [],
3777
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3778
];
3779

            
3780
for (my $i = 0; $i < @$datas; $i++) {
cleanup
Yuki Kimoto authored on 2012-01-20
3781
  my $data = $datas->[$i];
3782
  my $dbi = DBIx::Custom->new;
3783
  my $builder = $dbi->query_builder;
3784
  my $query = $builder->build_query($data->{source});
3785
  is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3786
  is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3787
}
3788

            
cleanup
Yuki Kimoto authored on 2011-08-13
3789
$dbi = DBIx::Custom->new;
3790
$builder = $dbi->query_builder;
3791
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
3792
  p => sub {
3793
    my @args = @_;
3794
    
3795
    my $expand    = "? $args[0] $args[1]";
3796
    my $columns = [2];
3797
    return [$expand, $columns];
3798
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3799
);
3800

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3811
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3812
  q => 'string'
test cleanup
Yuki Kimoto authored on 2011-08-10
3813
});
3814

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3818
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3819
  r => sub {} 
test cleanup
Yuki Kimoto authored on 2011-08-10
3820
});
3821

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

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

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

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

            
3836

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

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

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

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

            
3852
test 'variouse source';
3853
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3854
$query = $builder->build_query($source);
3855
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3856

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

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

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

            
3869
$source = "a {= b} }";
3870
eval{$builder->build_query($source)};
3871
like($@, qr/unexpected "}"/, "error : 1");
3872

            
3873
$source = "a {= {}";
3874
eval{$builder->build_query($source)};
3875
like($@, qr/unexpected "{"/, "error : 2");
3876

            
3877
test 'select() sqlfilter option';
3878
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3879
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3880
eval { $dbi->execute("drop table $table1") };
3881
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3882
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3883
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3884
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3885
  table => $table1,
3886
  column => $key1,
3887
  sqlfilter => sub {
3888
    my $sql = shift;
3889
    $sql = "select * from ( $sql ) t where $key1 = 1";
3890
    return $sql;
3891
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3892
)->all;
3893
is_deeply($rows, [{$key1 => 1}]);
3894

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3895
test 'select() after_build_sql option';
3896
$dbi = DBIx::Custom->connect;
3897
$dbi->user_table_info($user_table_info);
3898
eval { $dbi->execute("drop table $table1") };
3899
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3900
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3901
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3902
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3903
  table => $table1,
3904
  column => $key1,
3905
  after_build_sql => sub {
3906
    my $sql = shift;
3907
    $sql = "select * from ( $sql ) t where $key1 = 1";
3908
    return $sql;
3909
  }
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3910
)->all;
3911
is_deeply($rows, [{$key1 => 1}]);
3912

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3913
test 'dbi method from model';
3914
$dbi = MyDBI9->connect;
3915
eval { $dbi->execute("drop table $table1") };
3916
$dbi->execute($create_table1);
improved test
Yuki Kimoto authored on 2012-03-01
3917
$dbi->setup_model(@$setup_model_args);
cleanup test
Yuki Kimoto authored on 2011-08-15
3918
$model = $dbi->model($table1);
3919
eval{$model->execute("select * from $table1")};
3920
ok(!$@);
3921

            
3922
test 'column table option';
3923
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3924
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3925
eval { $dbi->execute("drop table $table1") };
3926
$dbi->execute($create_table1);
3927
eval { $dbi->execute("drop table $table2") };
3928
$dbi->execute($create_table2);
improved test
Yuki Kimoto authored on 2012-03-01
3929
$dbi->setup_model(@$setup_model_args);
cleanup test
Yuki Kimoto authored on 2011-08-15
3930
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3931
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3932
$model = $dbi->model($table1);
3933
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3934
  column => [
improved test
Yuki Kimoto authored on 2012-03-01
3935
    $model->column($table2, {alias => u$table2_alias})
cleanup
Yuki Kimoto authored on 2012-01-20
3936
  ],
improved test
Yuki Kimoto authored on 2012-03-01
3937
  where => {u($table2_alias) . ".$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3938
);
3939
is_deeply($result->one, 
improved test
Yuki Kimoto authored on 2012-03-01
3940
        {u($table2_alias) . ".$key1" => 1, u($table2_alias) . ".$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3941

            
3942
$dbi->separator('__');
3943
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3944
  column => [
improved test
Yuki Kimoto authored on 2012-03-01
3945
    $model->column($table2, {alias => u$table2_alias})
cleanup
Yuki Kimoto authored on 2012-01-20
3946
  ],
improved test
Yuki Kimoto authored on 2012-03-01
3947
  where => {u($table2_alias) . ".$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3948
);
3949
is_deeply($result->one, 
improved test
Yuki Kimoto authored on 2012-03-01
3950
  {u(${table2_alias}) . "__$key1" => 1, u(${table2_alias}) . "__$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3951

            
3952
$dbi->separator('-');
3953
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3954
  column => [
improved test
Yuki Kimoto authored on 2012-03-01
3955
    $model->column($table2, {alias => u$table2_alias})
cleanup
Yuki Kimoto authored on 2012-01-20
3956
  ],
improved test
Yuki Kimoto authored on 2012-03-01
3957
  where => {u($table2_alias) . ".$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3958
);
3959
is_deeply($result->one, 
improved test
Yuki Kimoto authored on 2012-03-01
3960
  {u(${table2_alias}) . "-$key1" => 1, u(${table2_alias}) . "-$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3961

            
3962
test 'create_model';
3963
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3964
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3965
eval { $dbi->execute("drop table $table1") };
3966
eval { $dbi->execute("drop table $table2") };
3967
$dbi->execute($create_table1);
3968
$dbi->execute($create_table2);
3969

            
3970
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3971
  table => $table1,
3972
  join => [
3973
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3974
  ],
3975
  primary_key => [$key1]
cleanup test
Yuki Kimoto authored on 2011-08-15
3976
);
3977
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3978
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3979
);
3980
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3981
  table => $table3,
3982
  filter => [
3983
    $key1 => {in => sub { uc $_[0] }}
3984
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
3985
);
improved test
Yuki Kimoto authored on 2012-03-01
3986
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
3987
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3988
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3989
$model = $dbi->model($table1);
3990
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3991
  column => [$model->mycolumn, $model->column($table2)],
3992
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-15
3993
);
3994
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3995
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3996
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3997

            
3998
test 'model method';
3999
$dbi = DBIx::Custom->connect;
4000
eval { $dbi->execute("drop table $table2") };
4001
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4002
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4003
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
4004
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
4005
);
4006
$model->method(foo => sub { shift->select(@_) });
4007
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
4008

            
4009
test 'model helper';
4010
$dbi = DBIx::Custom->connect;
4011
eval { $dbi->execute("drop table $table2") };
4012
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4013
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
4014
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
4015
  table => $table2
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
4016
);
4017
$model->helper(foo => sub { shift->select(@_) });
4018
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
4019

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

            
4027
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4028
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
4029
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4030
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
4031
where $key1 = 1
4032
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
4033
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
4034
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
4035
$rows   = $result->all;
4036
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
4037
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
4038
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
4039

            
4040

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

            
4047
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4048
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
4049
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4050
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
4051
where $key1 = 1
4052
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
4053
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
4054
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
4055
$rows   = $result->all;
4056
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
4057
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
4058
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
4059

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

            
4066
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4067
$assign_clause = $dbi->update_param($param, {no_set => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
4068
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4069
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
4070
where $key1 = 1
4071
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
4072
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
4073
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
4074
$rows   = $result->all;
4075
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
4076
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
4077
  "update param no_set");
cleanup test
Yuki Kimoto authored on 2011-08-15
4078

            
cleanup
Yuki Kimoto authored on 2012-01-20
4079
          
cleanup test
Yuki Kimoto authored on 2011-08-15
4080
$dbi = DBIx::Custom->connect;
4081
eval { $dbi->execute("drop table $table1") };
4082
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4083
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
4084
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
4085

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4112
test 'Model class';
4113
$dbi = MyDBI1->connect;
4114
eval { $dbi->execute("drop table $table1") };
4115
$dbi->execute($create_table1);
4116
$model = $dbi->model($table1);
4117
$model->insert({$key1 => 'a', $key2 => 'b'});
4118
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4119
eval { $dbi->execute("drop table $table2") };
4120
$dbi->execute($create_table2);
4121
$model = $dbi->model($table2);
4122
$model->insert({$key1 => 'a'});
4123
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4124
is($dbi->models->{$table1}, $dbi->model($table1));
4125
is($dbi->models->{$table2}, $dbi->model($table2));
4126

            
4127
$dbi = MyDBI4->connect;
4128
eval { $dbi->execute("drop table $table1") };
4129
$dbi->execute($create_table1);
4130
$model = $dbi->model($table1);
4131
$model->insert({$key1 => 'a', $key2 => 'b'});
4132
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4133
eval { $dbi->execute("drop table $table2") };
4134
$dbi->execute($create_table2);
4135
$model = $dbi->model($table2);
4136
$model->insert({$key1 => 'a'});
4137
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4138

            
4139
$dbi = MyDBI5->connect;
4140
eval { $dbi->execute("drop table $table1") };
4141
eval { $dbi->execute("drop table $table2") };
4142
$dbi->execute($create_table1);
4143
$dbi->execute($create_table2);
4144
$model = $dbi->model($table2);
4145
$model->insert({$key1 => 'a'});
4146
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
4147
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4148
$model = $dbi->model($table1);
4149
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
4150

            
4151
test 'primary_key';
4152
$dbi = MyDBI1->connect;
4153
$model = $dbi->model($table1);
4154
$model->primary_key([$key1, $key2]);
4155
is_deeply($model->primary_key, [$key1, $key2]);
4156

            
4157
test 'columns';
4158
$dbi = MyDBI1->connect;
4159
$model = $dbi->model($table1);
4160
$model->columns([$key1, $key2]);
4161
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4162

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4163
test 'setup_model';
4164
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
4165
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4166
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4167
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
4168

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4169
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4170
$dbi->execute($create_table2);
improved test
Yuki Kimoto authored on 2012-03-01
4171
$dbi->setup_model(@$setup_model_args);
cleanup test
Yuki Kimoto authored on 2011-08-15
4172
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
4173
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4174

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4175
test 'each_column';
4176
$dbi = DBIx::Custom->connect;
4177
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4178
eval { $dbi->execute("drop table $table1") };
4179
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4180
eval { $dbi->execute("drop table $table3") };
4181
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4182
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4183

            
4184
$infos = [];
4185
$dbi->each_column(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4186
  my ($self, $table, $column, $cinfo) = @_;
4187
  
4188
  if ($table =~ /^table\d/i) {
4189
     my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
4190
     push @$infos, $info;
4191
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4192
});
4193
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4194
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4195
  [
improved tests
Yuki Kimoto authored on 2012-03-01
4196
    [table_only($table1), $key1, $key1],
4197
    [table_only($table1), $key2, $key2],
4198
    [table_only($table2), $key1, $key1],
4199
    [table_only($table2), $key3, $key3]
cleanup
Yuki Kimoto authored on 2012-01-20
4200
  ]
4201
  
cleanup test
Yuki Kimoto authored on 2011-08-10
4202
);
cleanup test
Yuki Kimoto authored on 2011-08-16
4203

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4204
test 'each_table';
4205
$dbi = DBIx::Custom->connect;
4206
eval { $dbi->execute("drop table $table1") };
4207
eval { $dbi->execute("drop table $table2") };
4208
$dbi->execute($create_table2);
4209
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4210

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4211
$infos = [];
4212
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4213
  my ($self, $table, $table_info) = @_;
4214
  
4215
  if ($table =~ /^table\d/i) {
4216
    my $info = [$table, $table_info->{TABLE_NAME}];
4217
    push @$infos, $info;
4218
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4219
});
4220
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4221
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4222
  [
improved tests
Yuki Kimoto authored on 2012-03-01
4223
    [table_only($table1), table_only($table1)],
4224
    [table_only($table2), table_only($table2)],
cleanup
Yuki Kimoto authored on 2012-01-20
4225
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4226
);
4227

            
cleanup test
Yuki Kimoto authored on 2011-08-16
4228
$dbi = DBIx::Custom->connect;
4229
eval { $dbi->execute("drop table $table1") };
4230
eval { $dbi->execute("drop table $table2") };
4231
$dbi->execute($create_table2);
4232
$dbi->execute($create_table1_type);
4233

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4253
test 'type_rule into';
4254
eval { $dbi->execute("drop table $table1") };
4255
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4256
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
4257

            
4258

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

            
cleanup
Yuki Kimoto authored on 2011-08-16
4263
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4264
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4265
  into1 => {
4266
    $date_typename => sub { '2010-' . $_[0] }
4267
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4268
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4269
$dbi->insert({$key1 => '01-01'}, table => $table1);
4270
$result = $dbi->select(table => $table1);
4271
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4272

            
4273
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4274
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4275
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4276
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4277
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4278
  into1 => [
4279
     [$date_typename, $datetime_typename] => sub {
4280
        my $value = shift;
4281
        $value =~ s/02/03/g;
4282
        return $value;
4283
     }
4284
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
4285
);
4286
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
4287
$result = $dbi->select(table => $table1);
4288
$row = $result->one;
4289
like($row->{$key1}, qr/^2010-01-03/);
4290
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4291

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4292
$dbi = DBIx::Custom->connect;
4293
eval { $dbi->execute("drop table $table1") };
4294
$dbi->execute($create_table1_type);
4295
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4296
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4297
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4298
  into1 => [
4299
    [$date_typename, $datetime_typename] => sub {
4300
      my $value = shift;
4301
      $value =~ s/02/03/g;
4302
      return $value;
4303
    }
4304
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4305
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4306
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
4307
  "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
4308
  {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
4309
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4310
$row = $result->one;
4311
like($row->{$key1}, qr/^2010-01-03/);
4312
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4313

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

            
4337
$dbi = DBIx::Custom->connect;
4338
eval { $dbi->execute("drop table $table1") };
4339
$dbi->execute($create_table1_type);
4340
$dbi->register_filter(convert => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4341
  my $value = shift || '';
4342
  $value =~ s/02/03/;
4343
  return $value;
cleanup test
Yuki Kimoto authored on 2011-08-15
4344
});
cleanup
Yuki Kimoto authored on 2011-08-16
4345
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4346
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4347
  from1 => {
4348
    $date_datatype => 'convert',
4349
  },
4350
  into1 => {
4351
      $date_typename => 'convert',
4352
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4353
);
4354
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
4355
$result = $dbi->select(table => $table1);
4356
like($result->fetch->[0], qr/^2010-03-03/);
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
4357
$result = $dbi->select(column => [$key1, $key1], table => $table1);
4358
$row = $result->fetch;
4359
like($row->[0], qr/^2010-03-03/);
4360
like($row->[1], qr/^2010-03-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4361

            
4362
test 'type_rule and filter order';
4363
$dbi = DBIx::Custom->connect;
4364
eval { $dbi->execute("drop table $table1") };
4365
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4366
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4367
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4368
  into1 => {
4369
    $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4370
  },
4371
  into2 => {
4372
    $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4373
  },
4374
  from1 => {
4375
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4376
  },
4377
  from2 => {
4378
    $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
4379
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4380
);
4381
$dbi->insert({$key1 => '2010-01-03'}, 
cleanup
Yuki Kimoto authored on 2012-01-20
4382
table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
cleanup test
Yuki Kimoto authored on 2011-08-15
4383
$result = $dbi->select(table => $table1);
4384
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4385
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4386

            
4387

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4414
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
4415
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
4416
eval { $dbi->execute("drop table $table1") };
4417
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4418
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4419
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4420
  from1 => {
4421
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4422
  },
4423
  into1 => {
4424
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4425
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4426
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4427
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4428
$result = $dbi->select(table => $table1, type_rule_off => 1);
4429
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4430

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4431
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4432
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4433
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4434
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4435
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4436
  from1 => {
4437
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4438
  },
4439
  into1 => {
4440
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4441
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4442
);
4443
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4444
$result = $dbi->select(table => $table1, type_rule_off => 1);
4445
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4446

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4493
eval{$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4494
  into1 => {
4495
    $date_typename => 'pp'
4496
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4497
)};
4498
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4499

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4500
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4501
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4502
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4503
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4504
  $dbi->type_rule(
4505
    from1 => {
4506
      Date => sub { $_[0] * 2 },
4507
    }
4508
  );
cleanup test
Yuki Kimoto authored on 2011-08-10
4509
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4510
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4511

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4512
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4513
  $dbi->type_rule(
4514
    into1 => {
4515
      Date => sub { $_[0] * 2 },
4516
    }
4517
  );
cleanup test
Yuki Kimoto authored on 2011-08-15
4518
};
4519
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4520

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

            
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
Yuki Kimoto authored on 2011-08-16
4541
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4542
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4543
  from1 => {
4544
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4545
    $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4546
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4547
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4548
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
4549
$result = $dbi->select(table => $table1);
4550
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4551
  from1 => {
4552
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4553
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4554
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4555
$row = $result->one;
4556
like($row->{$key1}, qr/^2010-01-05/);
4557
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4558

            
4559
$result = $dbi->select(table => $table1);
4560
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4561
  from1 => {
4562
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4563
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4564
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4565
$row = $result->one;
4566
like($row->{$key1}, qr/2010-01-05/);
4567
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4568

            
4569
$result = $dbi->select(table => $table1);
4570
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4571
  from1 => {
4572
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4573
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4574
);
4575
$row = $result->one;
4576
like($row->{$key1}, qr/2010-01-05/);
4577
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4578

            
4579
$result = $dbi->select(table => $table1);
4580
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4581
  from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
cleanup test
Yuki Kimoto authored on 2011-08-15
4582
);
4583
$row = $result->one;
4584
like($row->{$key1}, qr/2010-01-05/);
4585
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4586

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

            
4596
$result = $dbi->select(table => $table1);
4597
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4598
  from1 => [$date_datatype => undef]
cleanup test
Yuki Kimoto authored on 2011-08-15
4599
);
4600
$row = $result->one;
4601
like($row->{$key1}, qr/^2010-01-03/);
4602
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4603

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4632
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4633
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4634
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4635
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4636
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4637
  into1 => {
4638
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4639
  },
4640
  into2 => {
4641
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4642
  },
4643
  from1 => {
4644
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4645
  },
4646
  from2 => {
4647
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4648
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4649
);
4650
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4651
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4652
like($result->type_rule_off->fetch_one->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4653
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4654
like($result->type_rule_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
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
  into1 => {
4662
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4663
  },
4664
  into2 => {
4665
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4666
  },
4667
  from1 => {
4668
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
4669
  },
4670
  from2 => {
4671
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4672
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4673
);
4674
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4675
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4676
like($result->type_rule1_off->fetch_one->[0], qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4677
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4678
like($result->type_rule1_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4679

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4704
test 'join';
4705
$dbi = DBIx::Custom->connect;
4706
eval { $dbi->execute("drop table $table1") };
4707
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4708
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4709
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4710
eval { $dbi->execute("drop table $table2") };
4711
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4712
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4713
eval { $dbi->execute("drop table $table3") };
4714
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4715
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4716
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4717
  table => $table1,
improved tests
Yuki Kimoto authored on 2012-03-01
4718
  column => "$table1.$key1 as " . u("${table1}_$key1") . ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
4719
  where   => {"$table1.$key2" => 2},
4720
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4721
)->all;
improved tests
Yuki Kimoto authored on 2012-03-01
4722
is_deeply($rows, [{u"${table1}_$key1" => 1, u"${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4723

            
4724
$dbi = DBIx::Custom->connect;
4725
eval { $dbi->execute("drop table $table1") };
4726
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4727
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4728
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4729
eval { $dbi->execute("drop table $table2") };
4730
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4731
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4732
eval { $dbi->execute("drop table $table3") };
4733
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4734
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4735
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4736
  table => $table1,
improved tests
Yuki Kimoto authored on 2012-03-01
4737
  column => "$table1.$key1 as " . u("${table1}_$key1") . ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
4738
  where   => {"$table1.$key2" => 2},
4739
  join  => {
4740
    clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4741
    table => [$table1, $table2]
4742
  }
added test
Yuki Kimoto authored on 2011-10-27
4743
)->all;
improved tests
Yuki Kimoto authored on 2012-03-01
4744
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
4745

            
4746
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4747
  table => $table1,
4748
  where   => {$key1 => 1},
4749
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4750
)->all;
4751
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4752

            
4753
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4754
  table => $table1,
4755
  where   => {$key1 => 1},
4756
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4757
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4758
)->all;
4759
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4760

            
4761
$rows = $dbi->select(
improved tests
Yuki Kimoto authored on 2012-03-01
4762
  column => "$table3.$key4 as " . u2("${table3}__$key4"),
cleanup
Yuki Kimoto authored on 2012-01-20
4763
  table => $table1,
4764
  where   => {"$table1.$key1" => 1},
4765
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4766
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4767
)->all;
improved tests
Yuki Kimoto authored on 2012-03-01
4768
is_deeply($rows, [{u2"${table3}__$key4" => 4}]);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4769

            
4770
$rows = $dbi->select(
improved tests
Yuki Kimoto authored on 2012-03-01
4771
  column => "$table1.$key1 as " . u2("${table1}__$key1"),
cleanup
Yuki Kimoto authored on 2012-01-20
4772
  table => $table1,
4773
  where   => {"$table3.$key4" => 4},
4774
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4775
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4776
)->all;
improved tests
Yuki Kimoto authored on 2012-03-01
4777
is_deeply($rows, [{u2"${table1}__$key1" => 1}]);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4778

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

            
4795

            
4796
$dbi = DBIx::Custom->connect;
4797
eval { $dbi->execute("drop table $table1") };
4798
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4799
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4800
$sql = <<"EOS";
4801
left outer join (
cleanup
Yuki Kimoto authored on 2012-01-20
4802
select * from $table1 t1
4803
where t1.$key2 = (
4804
  select max(t2.$key2) from $table1 t2
4805
  where t1.$key1 = t2.$key1
4806
)
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4807
) $table3 on $table1.$key1 = $table3.$key1
4808
EOS
4809
$join = [$sql];
4810
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4811
  table => $table1,
4812
  column => "$table3.$key1 as ${table3}__$key1",
4813
  join  => $join
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4814
)->all;
4815
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4816

            
4817
$dbi = DBIx::Custom->connect;
4818
eval { $dbi->execute("drop table $table1") };
4819
eval { $dbi->execute("drop table $table2") };
4820
$dbi->execute($create_table1);
4821
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4822
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4823
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4824
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4825
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4826
  table => $table1,
4827
  join => [
4828
    "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4829
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4830
);
4831
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4832
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4833
  table => $table1,
4834
  column => [{$table2 => [$key3]}],
4835
  join => [
4836
    "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4837
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4838
);
4839
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4840
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4841
  table => $table1,
4842
  column => [{$table2 => [$key3]}],
4843
  join => [
4844
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4845
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4846
);
4847
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4848

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

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4869
$dbi = DBIx::Custom->connect;
4870
eval { $dbi->execute("drop table $table1") };
4871
eval { $dbi->execute("drop table $table2") };
4872
$dbi->execute($create_table1);
4873
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4874
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4875
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4876
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4877
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4878
  table => $table1,
4879
  column => [{$table2 => [$key3]}],
4880
  join => [
4881
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4882
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4883
);
4884
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4885

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4903
test 'columns';
4904
$dbi = MyDBI1->connect;
4905
$model = $dbi->model($table1);
4906

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4907
test 'count';
4908
$dbi = DBIx::Custom->connect;
4909
eval { $dbi->execute("drop table $table1") };
4910
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4911
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4912
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4913
is($dbi->count(table => $table1), 2);
4914
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4915
$model = $dbi->create_model(table => $table1);
4916
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4917

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4918
eval { $dbi->execute("drop table $table1") };
4919
eval { $dbi->execute("drop table $table2") };
4920
$dbi->execute($create_table1);
4921
$dbi->execute($create_table2);
4922
$model = $dbi->create_model(table => $table1, primary_key => $key1);
4923
$model->insert({$key1 => 1, $key2 => 2});
4924
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
4925
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4926
$model->insert({$key1 => 1, $key3 => 3});
4927
is($model->count(id => 1), 1);
4928
is($model->count(where => {"$table2.$key3" => 3}), 1);
4929

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