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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-15
117
require MyDBI1;
test cleanup
Yuki Kimoto authored on 2011-08-10
118
{
cleanup
Yuki Kimoto authored on 2012-01-20
119
  package MyDBI4;
test cleanup
Yuki Kimoto authored on 2011-08-10
120

            
cleanup
Yuki Kimoto authored on 2012-01-20
121
  use strict;
122
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
123

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
139
  use strict;
140
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
141

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
151
  sub insert {
152
    my ($self, $param) = @_;
153
    
154
    return $self->SUPER::insert($param);
155
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
156

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
161
  use strict;
162
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-15
163

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
166
  sub insert {
167
    my ($self, $param) = @_;
168
    
169
    return $self->SUPER::insert($param);
170
  }
test cleanup
Yuki Kimoto authored on 2011-08-15
171

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
176
  use strict;
177
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-15
178

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
181
  sub insert {
182
    my ($self, $param) = @_;
183
    
184
    return $self->SUPER::insert($param);
185
  }
test cleanup
Yuki Kimoto authored on 2011-08-15
186

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
191
  use strict;
192
  use warnings;
193

            
194
  use base 'MyModel2::Base1';
195

            
196
  sub insert {
197
    my ($self, $param) = @_;
198
    
199
    return $self->SUPER::insert($param);
200
  }
201

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

            
204

            
205
  package MyModel2::main::table1;
206

            
207
  use strict;
208
  use warnings;
209

            
210
  use base 'MyModel2::Base1';
211

            
212
  sub insert {
213
    my ($self, $param) = @_;
214
    
215
    return $self->SUPER::insert($param);
216
  }
217

            
218
  sub list { shift->select; }
219

            
220
  package MyModel2::main::table2;
221

            
222
  use strict;
223
  use warnings;
224

            
225
  use base 'MyModel2::Base1';
226

            
227
  sub insert {
228
    my ($self, $param) = @_;
229
    
230
    return $self->SUPER::insert($param);
231
  }
232

            
233
  sub list { shift->select; }
test cleanup
Yuki Kimoto authored on 2011-08-10
234
}
235
{
cleanup
Yuki Kimoto authored on 2012-01-20
236
   package MyDBI5;
test cleanup
Yuki Kimoto authored on 2011-08-10
237

            
cleanup
Yuki Kimoto authored on 2012-01-20
238
  use strict;
239
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
240

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

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

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

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

            
added test
Yuki Kimoto authored on 2011-08-16
316
# Get user table info
317
$dbi = DBIx::Custom->connect;
318
eval { $dbi->execute("drop table $table1") };
319
eval { $dbi->execute("drop table $table2") };
320
eval { $dbi->execute("drop table $table3") };
321
$dbi->execute($create_table1);
322
$dbi->execute($create_table2);
323
$dbi->execute($create_table3);
324
$user_table_info = $dbi->get_table_info(exclude => $dbi->exclude_table);
325

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

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
334
eval { $dbi->execute("drop table $table1") };
335
$dbi->execute($create_table1);
336
$model = $dbi->create_model(table => $table1);
337
$model->insert({$key1 => 1, $key2 => 2});
338
is_deeply($model->select($key1)->all, [{$key1 => 1}]);
339

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
348
@rows = ();
349
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
350
  push @rows, [@$row];
cleanup test
Yuki Kimoto authored on 2011-08-15
351
}
352
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
cleanup
Yuki Kimoto authored on 2011-08-15
353

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
374
test 'Insert query return value';
375
$source = "insert into $table1 {insert_param $key1 $key2}";
376
$query = $dbi->execute($source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
377
$ret_val = $dbi->execute($query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
378
ok($ret_val);
test cleanup
Yuki Kimoto authored on 2011-08-10
379

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
419
$source = "select * from $table1 where $key1 = :$key1 and {<> $key2} and {< $key3} and {> $key4} and {>= $key5}";
cleanup test
Yuki Kimoto authored on 2011-08-08
420
$query = $dbi->execute($source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
421
$result = $dbi->execute($query, {$key1 => 1, $key2 => 3, $key3 => 4, $key4 => 3, $key5 => 5});
cleanup test
Yuki Kimoto authored on 2011-08-08
422
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
423
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}], "basic tag1");
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 in progress
Yuki Kimoto authored on 2011-08-15
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} and {like $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
432
$query = $dbi->execute($source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
433
$result = $dbi->execute($query, {$key1 => 1, $key2 => '%2%'});
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 tag2");
cleanup test
Yuki Kimoto authored on 2011-08-08
436

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added tests
Yuki Kimoto authored on 2011-11-01
541
eval { $dbi->execute("drop table $table1") };
542
$dbi->execute($create_table1);
543
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
544
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
545
$result = $dbi->execute("select * from $table1");
546
$rows   = $result->all;
547
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
548

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

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

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
584
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
585
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
586
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
587
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
588
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
589
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
590
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
591

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

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

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

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

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

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

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

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

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

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

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

            
703
eval { $dbi->execute("drop table $table1") };
704
$dbi->execute($create_table1_2);
705
$param = {$key1 => 1};
706
$dbi->insert($param, table => $table1, ctime => $key2, updated_at => $key3);
707
$result = $dbi->select(table => $table1);
708
is_deeply($param, {$key1 => 1});
709
$row   = $result->one;
710
is($row->{$key1}, 1);
711
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
712
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
713
is($row->{$key2}, $row->{$key3});
714

            
715
eval { $dbi->execute("drop table $table1") };
716
$dbi->execute($create_table1_2);
717
$param = {$key1 => 1};
718
$dbi->insert($param, table => $table1, ctime => $key2, mtime => $key3);
719
$result = $dbi->select(table => $table1);
720
is_deeply($param, {$key1 => 1});
721
$row   = $result->one;
722
is($row->{$key1}, 1);
723
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
724
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
725
is($row->{$key2}, $row->{$key3});
726

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

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

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

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

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

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

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

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

            
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
823
eval { $dbi->execute("drop table $table1") };
824
$dbi->execute($create_table1);
825
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] , table => $table1);
826
$result = $dbi->execute("select * from $table1");
827
$rows   = $result->all;
828
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
829

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

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

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

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

            
882
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
883
  {$key2 => 3},
884
  table => $table1,
885
  primary_key => $key1,
886
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
887
);
888
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
889
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
890

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
891
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
892
  $dbi->update_or_insert(
893
    {$key2 => 3},
894
    table => $table1,
895
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
896
};
897

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

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

            
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
911
eval { $dbi->execute("drop table $table1") };
912
$dbi->execute($create_table1);
913
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
914
  {},
915
  table => $table1,
916
  primary_key => $key1,
917
  id => 1
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
918
);
919
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
920
is($row->{$key1}, 1);
921

            
922
eval { 
cleanup
Yuki Kimoto authored on 2012-01-20
923
  $affected = $dbi->update_or_insert(
924
    {},
925
    table => $table1,
926
    primary_key => $key1,
927
    id => 1
928
  );
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
929
};
930
is($affected, 0);
931

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
943
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
944
  $model->insert({$key1 => 1});
945
  $model->update_or_insert(
946
    {$key2 => 3},
947
    id => 1
948
  );
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
949
};
950
like($@, qr/one/);
951

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1281
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1282
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1283
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1284
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
1285
$rows = $dbi->select(table => $table1)->all;
1286
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1287

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1363
$rows = $dbi->select(table => $table1, where => {$key1 => 1})->all;
1364
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table and columns and where key");
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], where => {$key1 => 3})->all;
1367
is_deeply($rows, [{$key1 => 3}], "table and columns and where key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1368

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

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

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

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

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
1402
eval { $dbi->execute("drop table $table1") };
1403
$dbi->execute($create_table1);
1404
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1405
$row = $dbi->select($key1, table => $table1)->one;
1406
is_deeply($row, {$key1 => 1});
1407

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

            
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
1411
eval { $dbi->execute("drop table $table1") };
1412
$dbi->execute($create_table1);
1413
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1414
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
1415
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
1416

            
1417
$rows = $dbi->select(table => $table1, where => {$key1 => [1, 5]})->all;
1418
is_deeply($rows, [
1419
  {$key1 => 1, $key2 => 2},
1420
  {$key1 => 5, $key2 => 6}
1421
], "table");
1422

            
1423
$rows = $dbi->select(table => $table1, where => {$key1 => []})->all;
1424
is_deeply($rows, [], "table");
1425

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1455
test 'filters';
1456
$dbi = DBIx::Custom->new;
1457

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

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

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

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

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

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

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

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

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

            
1522

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1523
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1524
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1525
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1526
$dbi->execute($create_table1);
1527

            
1528
$dbi->begin_work;
1529

            
1530
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1531
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1532
  die "Error";
1533
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1534
};
1535

            
1536
$dbi->rollback if $@;
1537

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

            
1542
$dbi->begin_work;
1543

            
1544
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1545
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1546
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1547
};
1548

            
1549
$dbi->commit unless $@;
1550

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

            
1555
$dbi->dbh->{AutoCommit} = 0;
1556
eval{ $dbi->begin_work };
1557
ok($@, "exception");
1558
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1559

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

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

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

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

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

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

            
1621
is($dbi->one, 1, "first");
1622
is($dbi->two, 2, "second");
1623
is($dbi->twice(5), 10 , "second");
1624

            
1625
eval {$dbi->XXXXXX};
1626
ok($@, "not exists");
1627

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

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

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

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

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

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

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

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

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

            
1752
$result->filter({$key2 => 'twice'});
1753
$rows   = $result->all;
1754
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1755

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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1779
$dbi = DBIx::Custom->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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1911
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1912
  table => $table1,
1913
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1914
);
1915
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1916
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1917

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

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

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

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

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

            
1966
eval {
1967
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1968
           ->clause(['uuu']);
test cleanup
Yuki Kimoto authored on 2011-08-10
1969
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1970
  table => $table1,
1971
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1972
);
1973
};
1974
ok($@);
1975

            
1976
$where = $dbi->where;
1977
is("$where", '');
1978

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2148
eval {$dbi->where(ppp => 1) };
2149
like($@, qr/invalid/);
2150

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

            
2162

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

            
2174
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2175
$where->clause(['and', ":${key1}{=}"]);
2176
$where->param({$key1 => undef});
2177
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
2178
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2179
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2180

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

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

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

            
2201
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2202
  table => $table1,
2203
  where => $where
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2204
);
2205
$row = $result->all;
2206
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
2207

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2208
test 'register_tag_processor';
2209
$dbi = DBIx::Custom->connect;
2210
$dbi->register_tag_processor(
cleanup
Yuki Kimoto authored on 2012-01-20
2211
  a => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
2212
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2213
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2214

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2227
test 'more tests';
2228
$dbi = DBIx::Custom->connect;
2229
eval{$dbi->apply_filter('table', 'column', [])};
2230
like($@, qr/apply_filter/);
2231

            
2232
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
2233
like($@, qr/apply_filter/);
2234

            
2235
$dbi->apply_filter(
2236

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

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

            
2257
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2258
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2259
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2260
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2261
like($@, qr/not registered/);
2262
$dbi->method({one => sub { 1 }});
2263
is($dbi->one, 1);
2264

            
2265
eval{DBIx::Custom->connect(dsn => undef)};
2266
like($@, qr/_connect/);
2267

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

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

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

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2310
test 'option';
2311
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
2312
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
2313
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2314
ok($dbi->dbh->{PrintError});
2315
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2316
ok($dbi->dbh->{PrintError});
2317

            
2318
test 'DBIx::Custom::Result stash()';
2319
$result = DBIx::Custom::Result->new;
2320
is_deeply($result->stash, {}, 'default');
2321
$result->stash->{foo} = 1;
2322
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2323

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

            
cleanup
Yuki Kimoto authored on 2011-11-01
2336
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2337
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2338
  table => $table1,
2339
  primary_key => $key1,
2340
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2341
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2342
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2343

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2358
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2359
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2360
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2361
  {$key2 => 2, $key3 => 3},
2362
  primary_key => $key1, 
2363
  table => $table1,
2364
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2365
);
2366

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

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

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

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

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

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

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

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

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

            
2482
test 'model insert_at';
2483
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2484
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2485
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2486
$dbi->model($table1)->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2487
  {$key3 => 3},
2488
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2489
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2490
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2491
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2492
is($row->{$key1}, 1);
2493
is($row->{$key2}, 2);
2494
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2495

            
2496
test 'model update_at';
2497
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2498
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2499
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2500
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2501
$dbi->model($table1)->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2502
  {$key3 => 4},
2503
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2504
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2505
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2506
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2507
is($row->{$key1}, 1);
2508
is($row->{$key2}, 2);
2509
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2510

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

            
2522

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

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

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

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

            
2587
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2588
  column => [
2589
    $model->mycolumn([$key1]),
2590
    $model->column($table2 => [$key1])
2591
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2592
);
2593
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2594
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2595
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2596
  column => [
2597
    $model->mycolumn([$key1]),
2598
    {$table2 => [$key1]}
2599
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2600
);
2601
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2602
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2603

            
2604
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2605
  column => [
2606
    $model->mycolumn([$key1]),
2607
    ["$table2.$key1", as => "$table2.$key1"]
2608
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2609
);
2610
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2611
  {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2612

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

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

            
2632
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2633
  {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2634
  {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2635
];
2636
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2637
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
2638

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

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

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

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

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

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

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

            
2739

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2783
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2784
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2785
  {$key2 => 2, $key3 => 3},
2786
  primary_key => $key1, 
2787
  table => $table1,
2788
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2789
);
2790

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

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

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

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

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

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

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

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

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

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

            
2918

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

            
2934

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

            
cleanup
Yuki Kimoto authored on 2011-11-01
2947
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2948
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2949
  table => $table1,
2950
  primary_key => $key1,
2951
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2952
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2953
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2954

            
2955

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

            
2974

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

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

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

            
3014

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

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

            
3044
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3045
  column => [$model->column($table2 => [$key1, $key3])],
3046
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3047
);
3048
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3049
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3050

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3051
test 'separator';
3052
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3053
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3054
eval { $dbi->execute("drop table $table1") };
3055
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3056
$dbi->execute($create_table1);
3057
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
3058

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

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

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

            
3110

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3133
test 'available_datetype';
3134
$dbi = DBIx::Custom->connect;
3135
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
3136

            
3137

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

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

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

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

            
added tests
Yuki Kimoto authored on 2011-08-26
3166
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3167
  id => {key => "$table1.id"},
3168
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3169
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
3170
);
3171
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
3172

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

            
3180
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3181
  id => {key => "$table1.id"},
3182
  price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
3183
);
3184
is_deeply($param, {"$table1.price" => undef});
3185

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

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

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3198
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3199
  price => sub { '%' . $_[0] },
3200
  author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
3201
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3202
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
3203

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

            
3209
$where = $dbi->where;
3210
$where->clause(['and', ":${key1}{=}"]);
3211
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
3212
$where->param($param);
3213
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3214
$row = $result->all;
3215
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3216

            
3217
$where = $dbi->where;
3218
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
3219
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
3220
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
3221
$row = $result->all;
3222
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3223
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
3224
$row = $result->all;
3225
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3226

            
3227
$where = $dbi->where;
3228
$where->clause(['and', ":${key1}{=}"]);
3229
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
3230
$where->param($param);
3231
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
3232
$row = $result->all;
3233
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3234
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
3235
$row = $result->all;
3236
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3237

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

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

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

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

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

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

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

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

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

            
3302
$where = $dbi->where;
3303
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3304
  id => {key => "$table1.id"},
3305
  price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3306
);
3307
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
3308

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

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

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

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

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

            
- DBIx::Custom::Mapper::map ...
Yuki Kimoto authored on 2012-02-29
3348
$param = $dbi->mapper(param => {author => 'Ken',})->map(
3349
  author => ["$table1.author" => '%<value>%'],
3350
);
3351
is_deeply($param, {"$table1.author" => '%Ken%'});
3352

            
3353
$param = $dbi->mapper(param => {author => 'Ken'})->map(
3354
  author => ["$table1.author" => 'p'],
3355
);
3356
is_deeply($param, {"$table1.author" => 'p'});
3357

            
3358
$param = $dbi->mapper(param => {author => 'Ken',})->map(
3359
  author => {value => '%<value>%'}
3360
);
3361
is_deeply($param, {"author" => '%Ken%'});
3362

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

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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3424
test 'last_sql';
3425
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3426
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3427
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3428
$dbi->execute("select * from $table1");
micro optimization
Yuki Kimoto authored on 2011-11-18
3429
is($dbi->last_sql, " select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3430

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3625
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3626
@rows = ();
3627
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
3628
  push @rows, [@$row];
test cleanup
Yuki Kimoto authored on 2011-08-10
3629
}
3630
is_deeply(\@rows, [[1, 2], [3, 4]]);
3631

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

            
3639
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3640
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3641
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3642
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3643
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3644

            
3645
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3646
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3647
$rows = $result->fetch_all;
3648
is_deeply($rows, [[1, 2], [3, 4]]);
3649

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3654
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3655
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3656
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3657
$rows = $result->fetch_all;
3658
is_deeply($rows, [[3, 2], [9, 4]], "array");
3659

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2012-02-28
3672
test 'flat';
3673
$result = $dbi->select(table => $table1);
3674
$rows = [$result->flat];
3675
is_deeply($rows, [1, 2, 3, 4]);
3676

            
added EXPERIMETAL DBIx::Cust...
Yuki Kimoto authored on 2012-02-28
3677
test 'kv';
3678
$dbi = DBIx::Custom->connect;
3679
eval { $dbi->execute("drop table $table1") };
3680
$dbi->execute($create_table1);
3681
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3682
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3683

            
3684
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key1");
3685
$rows = $result->kv;
3686
is_deeply($rows, {0 => {$key2 => 2}, 3 => {$key2 => 4}});
3687

            
3688
$dbi = DBIx::Custom->connect;
3689
eval { $dbi->execute("drop table $table1") };
3690
$dbi->execute($create_table1);
3691
$dbi->insert({$key1 => 0, $key2 => 1}, table => $table1);
3692
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3693
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3694
$dbi->insert({$key1 => 3, $key2 => 5}, table => $table1);
3695

            
3696
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key2");
3697
$rows = $result->kv(multi => 1);
3698
is_deeply($rows, {
3699
  0 => [
3700
    {$key2 => 1},
3701
    {$key2 => 2}
3702
  ],
3703
  3 => [
3704
    {$key2 => 4},
3705
    {$key2 => 5}
3706
  ]
3707
});
3708

            
3709

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3805
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3806
  q => 'string'
test cleanup
Yuki Kimoto authored on 2011-08-10
3807
});
3808

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3812
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3813
  r => sub {} 
test cleanup
Yuki Kimoto authored on 2011-08-10
3814
});
3815

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

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

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

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

            
3830

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

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

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

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

            
3846
test 'variouse source';
3847
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3848
$query = $builder->build_query($source);
3849
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3850

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

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

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

            
3863
$source = "a {= b} }";
3864
eval{$builder->build_query($source)};
3865
like($@, qr/unexpected "}"/, "error : 1");
3866

            
3867
$source = "a {= {}";
3868
eval{$builder->build_query($source)};
3869
like($@, qr/unexpected "{"/, "error : 2");
3870

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3907
test 'dbi method from model';
3908
$dbi = MyDBI9->connect;
3909
eval { $dbi->execute("drop table $table1") };
3910
$dbi->execute($create_table1);
improved test
Yuki Kimoto authored on 2012-03-01
3911
$dbi->setup_model(@$setup_model_args);
cleanup test
Yuki Kimoto authored on 2011-08-15
3912
$model = $dbi->model($table1);
3913
eval{$model->execute("select * from $table1")};
3914
ok(!$@);
3915

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

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

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

            
3956
test 'create_model';
3957
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3958
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3959
eval { $dbi->execute("drop table $table1") };
3960
eval { $dbi->execute("drop table $table2") };
3961
$dbi->execute($create_table1);
3962
$dbi->execute($create_table2);
3963

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

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

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

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

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

            
4034

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

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

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

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

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

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

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

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

            
4121
$dbi = MyDBI4->connect;
4122
eval { $dbi->execute("drop table $table1") };
4123
$dbi->execute($create_table1);
4124
$model = $dbi->model($table1);
4125
$model->insert({$key1 => 'a', $key2 => 'b'});
4126
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4127
eval { $dbi->execute("drop table $table2") };
4128
$dbi->execute($create_table2);
4129
$model = $dbi->model($table2);
4130
$model->insert({$key1 => 'a'});
4131
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4132

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

            
4145
test 'primary_key';
4146
$dbi = MyDBI1->connect;
4147
$model = $dbi->model($table1);
4148
$model->primary_key([$key1, $key2]);
4149
is_deeply($model->primary_key, [$key1, $key2]);
4150

            
4151
test 'columns';
4152
$dbi = MyDBI1->connect;
4153
$model = $dbi->model($table1);
4154
$model->columns([$key1, $key2]);
4155
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4156

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4157
test 'setup_model';
4158
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
4159
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4160
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4161
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
4162

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4163
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4164
$dbi->execute($create_table2);
improved test
Yuki Kimoto authored on 2012-03-01
4165
$dbi->setup_model(@$setup_model_args);
cleanup test
Yuki Kimoto authored on 2011-08-15
4166
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
4167
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4168

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4169
test 'each_column';
4170
$dbi = DBIx::Custom->connect;
4171
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4172
eval { $dbi->execute("drop table $table1") };
4173
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4174
eval { $dbi->execute("drop table $table3") };
4175
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4176
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4177

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4198
test 'each_table';
4199
$dbi = DBIx::Custom->connect;
4200
eval { $dbi->execute("drop table $table1") };
4201
eval { $dbi->execute("drop table $table2") };
4202
$dbi->execute($create_table2);
4203
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4204

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

            
cleanup test
Yuki Kimoto authored on 2011-08-16
4222
$dbi = DBIx::Custom->connect;
4223
eval { $dbi->execute("drop table $table1") };
4224
eval { $dbi->execute("drop table $table2") };
4225
$dbi->execute($create_table2);
4226
$dbi->execute($create_table1_type);
4227

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4247
test 'type_rule into';
4248
eval { $dbi->execute("drop table $table1") };
4249
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4250
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
4251

            
4252

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4253
$dbi = DBIx::Custom->connect;
4254
eval { $dbi->execute("drop table $table1") };
4255
$dbi->execute($create_table1_type);
4256

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

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

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

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

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

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

            
4381

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4487
eval{$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4488
  into1 => {
4489
    $date_typename => 'pp'
4490
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4491
)};
4492
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4493

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4506
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4507
  $dbi->type_rule(
4508
    into1 => {
4509
      Date => sub { $_[0] * 2 },
4510
    }
4511
  );
cleanup test
Yuki Kimoto authored on 2011-08-15
4512
};
4513
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4514

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

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

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

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

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

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

            
4590
$result = $dbi->select(table => $table1);
4591
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4592
  from1 => [$date_datatype => undef]
cleanup test
Yuki Kimoto authored on 2011-08-15
4593
);
4594
$row = $result->one;
4595
like($row->{$key1}, qr/^2010-01-03/);
4596
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4597

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4626
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4627
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4628
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4629
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4630
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4631
  into1 => {
4632
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4633
  },
4634
  into2 => {
4635
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4636
  },
4637
  from1 => {
4638
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4639
  },
4640
  from2 => {
4641
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4642
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4643
);
4644
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4645
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4646
like($result->type_rule_off->fetch_one->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4647
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4648
like($result->type_rule_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4649

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4650
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4651
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4652
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4653
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4654
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4655
  into1 => {
4656
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4657
  },
4658
  into2 => {
4659
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4660
  },
4661
  from1 => {
4662
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
4663
  },
4664
  from2 => {
4665
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4666
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4667
);
4668
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4669
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4670
like($result->type_rule1_off->fetch_one->[0], qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4671
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4672
like($result->type_rule1_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4673

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

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

            
4718
$dbi = DBIx::Custom->connect;
4719
eval { $dbi->execute("drop table $table1") };
4720
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4721
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4722
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4723
eval { $dbi->execute("drop table $table2") };
4724
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4725
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4726
eval { $dbi->execute("drop table $table3") };
4727
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4728
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4729
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4730
  table => $table1,
4731
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4732
  where   => {"$table1.$key2" => 2},
4733
  join  => {
4734
    clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4735
    table => [$table1, $table2]
4736
  }
added test
Yuki Kimoto authored on 2011-10-27
4737
)->all;
4738
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4739

            
4740
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4741
  table => $table1,
4742
  where   => {$key1 => 1},
4743
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4744
)->all;
4745
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4746

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

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

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

            
4773
$dbi = DBIx::Custom->connect;
4774
eval { $dbi->execute("drop table $table1") };
4775
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4776
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4777
eval { $dbi->execute("drop table $table2") };
4778
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4779
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4780
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4781
  table => $table1,
4782
  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",
4783
  where   => {"$table1.$key2" => 2},
4784
  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
4785
)->all;
4786
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
cleanup
Yuki Kimoto authored on 2012-01-20
4787
  'quote');
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4788

            
4789

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

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

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4897
test 'columns';
4898
$dbi = MyDBI1->connect;
4899
$model = $dbi->model($table1);
4900

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

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

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