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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-15
111
require MyDBI1;
test cleanup
Yuki Kimoto authored on 2011-08-10
112
{
cleanup
Yuki Kimoto authored on 2012-01-20
113
  package MyDBI4;
test cleanup
Yuki Kimoto authored on 2011-08-10
114

            
cleanup
Yuki Kimoto authored on 2012-01-20
115
  use strict;
116
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
117

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
120
  sub connect {
121
    my $self = shift->SUPER::connect(@_);
122
    
123
    $self->include_model(
124
      MyModel2 => [
125
          $table1,
126
          {class => $table2, name => $table2}
127
      ]
128
    );
129
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
130

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
133
  use strict;
134
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
135

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
145
  sub insert {
146
    my ($self, $param) = @_;
147
    
148
    return $self->SUPER::insert($param);
149
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
150

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
155
  use strict;
156
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-15
157

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
170
  use strict;
171
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-15
172

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
185
  use strict;
186
  use warnings;
187

            
188
  use base 'MyModel2::Base1';
189

            
190
  sub insert {
191
    my ($self, $param) = @_;
192
    
193
    return $self->SUPER::insert($param);
194
  }
195

            
196
  sub list { shift->select; }
test cleanup
Yuki Kimoto authored on 2011-08-10
197
}
198
{
cleanup
Yuki Kimoto authored on 2012-01-20
199
   package MyDBI5;
test cleanup
Yuki Kimoto authored on 2011-08-10
200

            
cleanup
Yuki Kimoto authored on 2012-01-20
201
  use strict;
202
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
203

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
206
  sub connect {
207
    my $self = shift->SUPER::connect(@_);
208
    
209
    $self->include_model('MyModel4');
210
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
211
}
212
{
cleanup
Yuki Kimoto authored on 2012-01-20
213
  package MyDBI6;
214
  
215
  use base 'DBIx::Custom';
216
  
217
  sub connect {
218
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
219
    
cleanup
Yuki Kimoto authored on 2012-01-20
220
    $self->include_model('MyModel5');
test cleanup
Yuki Kimoto authored on 2011-08-10
221
    
cleanup
Yuki Kimoto authored on 2012-01-20
222
    return $self;
223
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
224
}
225
{
cleanup
Yuki Kimoto authored on 2012-01-20
226
  package MyDBI7;
227
  
228
  use base 'DBIx::Custom';
229
  
230
  sub connect {
231
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
232
    
cleanup
Yuki Kimoto authored on 2012-01-20
233
    $self->include_model('MyModel6');
test cleanup
Yuki Kimoto authored on 2011-08-10
234
    
cleanup
Yuki Kimoto authored on 2012-01-20
235
    
236
    return $self;
237
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
238
}
239
{
cleanup
Yuki Kimoto authored on 2012-01-20
240
  package MyDBI8;
241
  
242
  use base 'DBIx::Custom';
243
  
244
  sub connect {
245
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
246
    
cleanup
Yuki Kimoto authored on 2012-01-20
247
    $self->include_model('MyModel7');
test cleanup
Yuki Kimoto authored on 2011-08-10
248
    
cleanup
Yuki Kimoto authored on 2012-01-20
249
    return $self;
250
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
251
}
252

            
253
{
cleanup
Yuki Kimoto authored on 2012-01-20
254
  package MyDBI9;
255
  
256
  use base 'DBIx::Custom';
257
  
258
  sub connect {
259
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
260
    
cleanup
Yuki Kimoto authored on 2012-01-20
261
    $self->include_model('MyModel8');
test cleanup
Yuki Kimoto authored on 2011-08-10
262
    
cleanup
Yuki Kimoto authored on 2012-01-20
263
    return $self;
264
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
265
}
266

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
267
test 'execute reuse option';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
268
eval { $dbi->execute("drop table $table1") };
269
$dbi->execute($create_table1);
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
270
$reuse = {};
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
271
for my $i (1 .. 2) {
cleanup
Yuki Kimoto authored on 2012-01-20
272
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, reuse => $reuse);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
273
}
274
$rows = $dbi->select(table => $table1)->all;
275
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-11-18
276
ok(keys %$reuse);
277
ok((keys %$reuse)[0] !~ /\?/);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
278

            
added test
Yuki Kimoto authored on 2011-08-16
279
# Get user table info
280
$dbi = DBIx::Custom->connect;
281
eval { $dbi->execute("drop table $table1") };
282
eval { $dbi->execute("drop table $table2") };
283
eval { $dbi->execute("drop table $table3") };
284
$dbi->execute($create_table1);
285
$dbi->execute($create_table2);
286
$dbi->execute($create_table3);
287
$user_table_info = $dbi->get_table_info(exclude => $dbi->exclude_table);
288

            
cleanup test
Yuki Kimoto authored on 2011-08-15
289
# Create table
test cleanup
Yuki Kimoto authored on 2011-08-10
290
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
291
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
292
$dbi->execute($create_table1);
293
$model = $dbi->create_model(table => $table1);
294
$model->insert({$key1 => 1, $key2 => 2});
295
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-08-15
296

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
297
eval { $dbi->execute("drop table $table1") };
298
$dbi->execute($create_table1);
299
$model = $dbi->create_model(table => $table1);
300
$model->insert({$key1 => 1, $key2 => 2});
301
is_deeply($model->select($key1)->all, [{$key1 => 1}]);
302

            
cleanup test
Yuki Kimoto authored on 2011-08-15
303
test 'DBIx::Custom::Result test';
304
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
305
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
306
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
307
$source = "select $key1, $key2 from $table1";
308
$query = $dbi->create_query($source);
309
$result = $dbi->execute($query);
cleanup
Yuki Kimoto authored on 2011-08-15
310

            
cleanup test
Yuki Kimoto authored on 2011-08-15
311
@rows = ();
312
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
313
  push @rows, [@$row];
cleanup test
Yuki Kimoto authored on 2011-08-15
314
}
315
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
cleanup
Yuki Kimoto authored on 2011-08-15
316

            
cleanup test
Yuki Kimoto authored on 2011-08-15
317
$result = $dbi->execute($query);
318
@rows = ();
319
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
320
  push @rows, {%$row};
cleanup test
Yuki Kimoto authored on 2011-08-15
321
}
322
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
323

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
337
test 'Insert query return value';
338
$source = "insert into $table1 {insert_param $key1 $key2}";
339
$query = $dbi->execute($source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
340
$ret_val = $dbi->execute($query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
341
ok($ret_val);
test cleanup
Yuki Kimoto authored on 2011-08-10
342

            
cleanup test
Yuki Kimoto authored on 2011-08-15
343
test 'Direct query';
344
$dbi->delete_all(table => $table1);
345
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
test cleanup
Yuki Kimoto authored on 2011-11-01
346
$dbi->execute($insert_source, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
347
$result = $dbi->execute("select * from $table1");
348
$rows = $result->all;
349
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
350

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
356
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
357
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
358
$insert_query->filter({$key1 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
359
$dbi->execute($insert_query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
360
$result = $dbi->execute("select * from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
361
$rows = $result->filter({$key2 => 'three_times'})->all;
362
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
363

            
364
test 'Filter in';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
365
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
366
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
367
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
368
$dbi->execute($insert_query, {$key1 => 2, $key2 => 4});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
369
$select_source = "select * from $table1 where {in $table1.$key1 2} and {in $table1.$key2 2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
370
$select_query = $dbi->execute($select_source,{}, query => 1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
371
$select_query->filter({"$table1.$key1" => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
372
$result = $dbi->execute($select_query, {"$table1.$key1" => [1,5], "$table1.$key2" => [2,4]});
cleanup test
Yuki Kimoto authored on 2011-08-08
373
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
374
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
375

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
456
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
457
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
458
  $source,
459
  {"$table1.$key1" => 1, "$table1.$key2" => 1},
460
  filter => {"$table1.$key2" => sub { $_[0] * 2 }}
cleanup test
Yuki Kimoto authored on 2011-08-08
461
);
462
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
463
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
464

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
465
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
466
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
467
$dbi->insert({$key1 => '2011-10-14 12:19:18', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
468
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
469
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
470
  $source,
471
  {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
472
);
473

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
478
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
479
$dbi->insert({$key1 => 'a:b c:d', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
480
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
481
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
482
  $source,
483
  {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
484
);
485
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
486
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
487

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
495
test 'insert';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
496
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
497
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
498
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
499
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
500
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
501
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
502
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
503

            
added tests
Yuki Kimoto authored on 2011-11-01
504
eval { $dbi->execute("drop table $table1") };
505
$dbi->execute($create_table1);
506
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
507
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
508
$result = $dbi->execute("select * from $table1");
509
$rows   = $result->all;
510
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
511

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
512
$dbi->execute("delete from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
513
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
514
  twice       => sub { $_[0] * 2 },
515
  three_times => sub { $_[0] * 3 }
cleanup test
Yuki Kimoto authored on 2011-08-10
516
);
517
$dbi->default_bind_filter('twice');
test cleanup
Yuki Kimoto authored on 2011-11-01
518
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
cleanup test
Yuki Kimoto authored on 2011-08-15
519
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
520
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
521
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
522
$dbi->delete_all(table => $table1);
523
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
524
$result = $dbi->execute("select * from $table1");
525
$rows   = $result->all;
526
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-10
527
$dbi->default_bind_filter(undef);
528

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
539
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
540
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
541
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
test cleanup
Yuki Kimoto authored on 2011-11-01
542
$dbi->insert({select => 1}, table => 'table');
cleanup test
Yuki Kimoto authored on 2011-08-10
543
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
544
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
545
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
cleanup test
Yuki Kimoto authored on 2011-08-10
546

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
547
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
548
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
549
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
550
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
551
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
552
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
553
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
554

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
555
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
556
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
557
$dbi->insert({$key1 => \"'1'", $key2 => 2}, table => $table1);
558
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
559
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
560
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
561
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
562

            
updated pod
Yuki Kimoto authored on 2011-09-02
563
eval { $dbi->execute("drop table $table1") };
564
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
565
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
566
wrap => {$key1 => sub { "$_[0] - 1" }});
test cleanup
Yuki Kimoto authored on 2011-11-01
567
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
updated pod
Yuki Kimoto authored on 2011-09-02
568
$result = $dbi->execute("select * from $table1");
569
$rows   = $result->all;
570
is_deeply($rows, [{$key1 => 0, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
571

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
572
eval { $dbi->execute("drop table $table1") };
573
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
574
$dbi->insert_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
575
  $key1 => '5'
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
576
);
test cleanup
Yuki Kimoto authored on 2011-11-01
577
$dbi->insert({$key2 => 2}, table => $table1, timestamp => 1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
578
$result = $dbi->execute("select * from $table1");
579
$rows   = $result->all;
580
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
581

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
582
eval { $dbi->execute("drop table $table1") };
583
$dbi->execute($create_table1);
584
$dbi->insert_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
585
  [$key1, $key2] => sub { 5 }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
586
);
587
$dbi->insert(table => $table1, timestamp => 1);
588
$result = $dbi->execute("select * from $table1");
589
$rows   = $result->all;
590
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
591

            
592
eval { $dbi->execute("drop table $table1") };
593
$dbi->execute($create_table1);
594
$dbi->insert_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
595
  [$key1, $key2] => sub { "" . DBIx::Custom->new }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
596
);
597
$dbi->insert(table => $table1, timestamp => 1);
598
$result = $dbi->execute("select * from $table1");
599
$rows   = $result->all;
600
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
601

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
602
eval { $dbi->execute("drop table $table1") };
603
$dbi->execute($create_table1_2);
604
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
605
$dbi->insert($param, table => $table1, created_at => $key2);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
606
$result = $dbi->select(table => $table1);
607
is_deeply($param, {$key1 => 1});
608
$row   = $result->one;
609
is($row->{$key1}, 1);
610
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
611

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
612
eval { $dbi->execute("drop table $table1") };
613
$dbi->execute($create_table1_2);
614
$param = {$key1 => 1};
615
$dbi->insert($param, table => $table1, ctime => $key2);
616
$result = $dbi->select(table => $table1);
617
is_deeply($param, {$key1 => 1});
618
$row   = $result->one;
619
is($row->{$key1}, 1);
620
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
621

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
622
eval { $dbi->execute("drop table $table1") };
623
$dbi->execute($create_table1_2);
624
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
625
$dbi->insert($param, table => $table1, updated_at => $key3);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
626
$result = $dbi->select(table => $table1);
627
is_deeply($param, {$key1 => 1});
628
$row   = $result->one;
629
is($row->{$key1}, 1);
630
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
631

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
632
eval { $dbi->execute("drop table $table1") };
633
$dbi->execute($create_table1_2);
634
$param = {$key1 => 1};
635
$dbi->insert($param, table => $table1, mtime => $key3);
636
$result = $dbi->select(table => $table1);
637
is_deeply($param, {$key1 => 1});
638
$row   = $result->one;
639
is($row->{$key1}, 1);
640
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
641

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

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

            
666
eval { $dbi->execute("drop table $table1") };
667
$dbi->execute($create_table1_2);
668
$param = {$key1 => 1};
669
$dbi->insert($param, table => $table1, ctime => $key2, updated_at => $key3);
670
$result = $dbi->select(table => $table1);
671
is_deeply($param, {$key1 => 1});
672
$row   = $result->one;
673
is($row->{$key1}, 1);
674
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
675
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
676
is($row->{$key2}, $row->{$key3});
677

            
678
eval { $dbi->execute("drop table $table1") };
679
$dbi->execute($create_table1_2);
680
$param = {$key1 => 1};
681
$dbi->insert($param, table => $table1, ctime => $key2, mtime => $key3);
682
$result = $dbi->select(table => $table1);
683
is_deeply($param, {$key1 => 1});
684
$row   = $result->one;
685
is($row->{$key1}, 1);
686
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
687
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
688
is($row->{$key2}, $row->{$key3});
689

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
690
eval { $dbi->execute("drop table $table1") };
691
$dbi->execute($create_table1_2);
692
$model = $dbi->create_model(table => $table1, created_at => $key2);
693
$param = {$key1 => 1};
694
$model->insert($param);
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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
712
eval { $dbi->execute("drop table $table1") };
713
$dbi->execute($create_table1_2);
714
$param = {$key1 => 1};
715
$model = $dbi->create_model(table => $table1, updated_at => $key3);
716
$model->insert($param);
717
$result = $dbi->select(table => $table1);
718
is_deeply($param, {$key1 => 1});
719
$row   = $result->one;
720
is($row->{$key1}, 1);
721
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
722

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
723
eval { $dbi->execute("drop table $table1") };
724
$dbi->execute($create_table1_2);
725
$param = {$key1 => 1};
726
$model = $dbi->create_model(table => $table1, mtime => $key3);
727
$model->insert($param);
728
$result = $dbi->select(table => $table1);
729
is_deeply($param, {$key1 => 1});
730
$row   = $result->one;
731
is($row->{$key1}, 1);
732
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
733

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

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

            
760
eval { $dbi->execute("drop table $table1") };
761
$dbi->execute($create_table1_2);
762
$param = {$key1 => 1};
763
$model = $dbi->create_model(table => $table1, ctime=> $key2, updated_at => $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->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
770
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
771
is($row->{$key2}, $row->{$key3});
772

            
773
eval { $dbi->execute("drop table $table1") };
774
$dbi->execute($create_table1_2);
775
$param = {$key1 => 1};
776
$model = $dbi->create_model(table => $table1, ctime=> $key2, mtime => $key3);
777
$model->insert($param);
778
$result = $dbi->select(table => $table1);
779
is_deeply($param, {$key1 => 1});
780
$row   = $result->one;
781
is($row->{$key1}, 1);
782
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
783
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
784
is($row->{$key2}, $row->{$key3});
785

            
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
786
eval { $dbi->execute("drop table $table1") };
787
$dbi->execute($create_table1);
788
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] , table => $table1);
789
$result = $dbi->execute("select * from $table1");
790
$rows   = $result->all;
791
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
792

            
793
eval { $dbi->execute("drop table $table1") };
794
$dbi->execute($create_table1_2);
795
$dbi->insert([{$key1 => 1}, {$key1 => 3}] ,
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
796
  table => $table1,
797
  updated_at => $key2,
798
  created_at => $key3
799
);
800
$result = $dbi->execute("select * from $table1");
801
$rows   = $result->all;
802
is($rows->[0]->{$key1}, 1);
803
is($rows->[1]->{$key1}, 3);
804
like($rows->[0]->{$key2}, qr/\d{2}:/);
805
like($rows->[1]->{$key2}, qr/\d{2}:/);
806
like($rows->[0]->{$key3}, qr/\d{2}:/);
807
like($rows->[1]->{$key3}, qr/\d{2}:/);
808

            
809
eval { $dbi->execute("drop table $table1") };
810
$dbi->execute($create_table1_2);
811
$dbi->insert([{$key1 => 1}, {$key1 => 3}] ,
812
  table => $table1,
813
  mtime => $key2,
814
  ctime => $key3
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
815
);
816
$result = $dbi->execute("select * from $table1");
817
$rows   = $result->all;
818
is($rows->[0]->{$key1}, 1);
819
is($rows->[1]->{$key1}, 3);
820
like($rows->[0]->{$key2}, qr/\d{2}:/);
821
like($rows->[1]->{$key2}, qr/\d{2}:/);
822
like($rows->[0]->{$key3}, qr/\d{2}:/);
823
like($rows->[1]->{$key3}, qr/\d{2}:/);
824

            
825
eval { $dbi->execute("drop table $table1") };
826
$dbi->execute($create_table1);
827
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] ,
cleanup
Yuki Kimoto authored on 2012-01-20
828
table => $table1, filter => {$key1 => sub { $_[0] * 2 }});
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
829
$result = $dbi->execute("select * from $table1");
830
$rows   = $result->all;
831
is_deeply($rows, [{$key1 => 2, $key2 => 2}, {$key1 => 6, $key2 => 4}], "basic");
832

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
833
test 'update_or_insert';
834
eval { $dbi->execute("drop table $table1") };
835
$dbi->execute($create_table1);
836
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
837
  {$key2 => 2},
838
  table => $table1,
839
  primary_key => $key1,
840
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
841
);
842
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
843
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
844

            
845
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
846
  {$key2 => 3},
847
  table => $table1,
848
  primary_key => $key1,
849
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
850
);
851
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
852
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
853

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
854
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
855
  $dbi->update_or_insert(
856
    {$key2 => 3},
857
    table => $table1,
858
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
859
};
860

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
863
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
864
  $dbi->insert({$key1 => 1}, table => $table1);
865
  $dbi->update_or_insert(
866
    {$key2 => 3},
867
    table => $table1,
868
    primary_key => $key1,
869
    id => 1
870
  );
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
871
};
872
like($@, qr/one/);
873

            
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
874
eval { $dbi->execute("drop table $table1") };
875
$dbi->execute($create_table1);
876
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
877
  {},
878
  table => $table1,
879
  primary_key => $key1,
880
  id => 1
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
881
);
882
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
883
is($row->{$key1}, 1);
884

            
885
eval { 
cleanup
Yuki Kimoto authored on 2012-01-20
886
  $affected = $dbi->update_or_insert(
887
    {},
888
    table => $table1,
889
    primary_key => $key1,
890
    id => 1
891
  );
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
892
};
893
is($affected, 0);
894

            
micro optimization
Yuki Kimoto authored on 2011-10-31
895
test 'model update_or_insert';
896
eval { $dbi->execute("drop table $table1") };
897
$dbi->execute($create_table1);
898
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
899
  table => $table1,
900
  primary_key => $key1
micro optimization
Yuki Kimoto authored on 2011-10-31
901
);
902
$model->update_or_insert({$key2 => 2}, id => 1);
903
$row = $model->select(id => 1)->one;
904
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
905

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
915
test 'default_bind_filter';
916
$dbi->execute("delete from $table1");
917
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
918
  twice       => sub { $_[0] * 2 },
919
  three_times => sub { $_[0] * 3 }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
920
);
921
$dbi->default_bind_filter('twice');
cleanup
Yuki Kimoto authored on 2011-11-01
922
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
923
$result = $dbi->execute("select * from $table1");
924
$rows   = $result->all;
925
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
926
$dbi->default_bind_filter(undef);
927

            
test cleanup
Yuki Kimoto authored on 2011-08-10
928
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
929
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
930
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
931
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
932
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
933
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
934
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
935
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
936
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
937
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
938
  "basic");
added tests
Yuki Kimoto authored on 2011-11-01
939

            
940
eval { $dbi->execute("drop table $table1") };
941
$dbi->execute($create_table1_2);
942
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
943
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
944
$dbi->update(param => {$key2 => 11}, table => $table1, where => {$key1 => 1});
945
$result = $dbi->execute("select * from $table1 order by $key1");
946
$rows   = $result->all;
947
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
948
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
949
  "basic");
950
                
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
951
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
952
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
953
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
954
$dbi->update({$key2 => 12}, table => $table1, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
955
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
956
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
957
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
958
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
959
  "update key same as search key");
test cleanup
Yuki Kimoto authored on 2011-08-10
960

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
968
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
969
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
970
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
971
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
972
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
973
            filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
974
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
975
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
976
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
977
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
978
  "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
979

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
985
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
986
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
987
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
988
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
989
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
990
$where->param({$key1 => 1, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
991
$dbi->update({$key1 => 3}, table => $table1, where => $where);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
992
$result = $dbi->select(table => $table1);
993
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
994

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
995
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
996
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
997
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
998
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
999
  {$key1 => 3},
1000
  table => $table1,
1001
  where => [
1002
    ['and', "$key1 = :$key1", "$key2 = :$key2"],
1003
    {$key1 => 1, $key2 => 2}
1004
  ]
test cleanup
Yuki Kimoto authored on 2011-08-10
1005
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1006
$result = $dbi->select(table => $table1);
1007
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1008

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1009
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1010
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1011
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1012
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1013
$where->clause(['and', "$key2 = :$key2"]);
1014
$where->param({$key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
1015
$dbi->update({$key1 => 3}, table => $table1, where => $where);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1016
$result = $dbi->select(table => $table1);
1017
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1018

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1025
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1026
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1027
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1028
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
1029
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
1030
$dbi->insert({select => 1}, table => 'table');
1031
$dbi->update({update => 2}, table => 'table', where => {select => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1032
$result = $dbi->execute("select * from ${q}table$p");
1033
$rows   = $result->all;
1034
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
1035

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

            
1039
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1040
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1041
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
1042
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
1043
$dbi->insert({select => 1}, table => 'table');
1044
$dbi->update({update => 2}, table => 'table', where => {'table.select' => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1045
$result = $dbi->execute("select * from ${q}table$p");
1046
$rows   = $result->all;
1047
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
1048

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1049
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1050
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1051
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1052
$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
1053
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1054
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1055
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1056
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1057
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1058
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1059

            
updated pod
Yuki Kimoto authored on 2011-09-02
1060
eval { $dbi->execute("drop table $table1") };
1061
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1062
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1063
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1064
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
updated pod
Yuki Kimoto authored on 2011-09-02
1065
wrap => {$key2 => sub { "$_[0] - 1" }});
1066
$result = $dbi->execute("select * from $table1 order by $key1");
1067
$rows   = $result->all;
1068
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1069
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1070
  "basic");
updated pod
Yuki Kimoto authored on 2011-09-02
1071

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1072
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1073
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1074
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1075
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1076
$dbi->update({$key2 => \"'11'"}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1077
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1078
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1079
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1080
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1081
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1082

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1083
eval { $dbi->execute("drop table $table1") };
1084
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1085
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
1086
  $key1 => '5'
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1087
);
test cleanup
Yuki Kimoto authored on 2011-11-01
1088
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1089
$dbi->update(table => $table1, timestamp => 1, where => {$key2 => 2});
1090
$result = $dbi->execute("select * from $table1");
1091
$rows   = $result->all;
1092
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
1093

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1094
eval { $dbi->execute("drop table $table1") };
1095
$dbi->execute($create_table1);
1096
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
1097
  [$key1, $key2] => sub { '5' }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1098
);
test cleanup
Yuki Kimoto authored on 2011-11-01
1099
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1100
$dbi->update_all(table => $table1, timestamp => 1);
1101
$result = $dbi->execute("select * from $table1");
1102
$rows   = $result->all;
1103
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
1104

            
1105
eval { $dbi->execute("drop table $table1") };
1106
$dbi->execute($create_table1);
1107
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
1108
  [$key1, $key2] => sub { "" . DBIx::Custom->new }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1109
);
test cleanup
Yuki Kimoto authored on 2011-11-01
1110
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1111
$dbi->update_all(table => $table1, timestamp => 1);
1112
$result = $dbi->execute("select * from $table1");
1113
$rows   = $result->all;
1114
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
1115

            
micro optimization and
Yuki Kimoto authored on 2011-10-25
1116
eval { $dbi->execute("drop table $table1") };
1117
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1118
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1119
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
1120
$param = {$key2 => 11};
1121
$dbi->update($param, table => $table1, where => {$key1 => 1});
1122
is_deeply($param, {$key2 => 11});
1123
$result = $dbi->execute("select * from $table1 order by $key1");
1124
$rows   = $result->all;
1125
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1126
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1127
  "basic");
micro optimization and
Yuki Kimoto authored on 2011-10-25
1128

            
1129
eval { $dbi->execute("drop table $table1") };
1130
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1131
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1132
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
1133
$param = {$key2 => 11};
1134
$dbi->update($param, table => $table1, where => {$key2 => 2});
1135
is_deeply($param, {$key2 => 11});
1136
$result = $dbi->execute("select * from $table1 order by $key1");
1137
$rows   = $result->all;
1138
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1139
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1140
  "basic");
micro optimization and
Yuki Kimoto authored on 2011-10-25
1141

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1142
eval { $dbi->execute("drop table $table1") };
1143
$dbi->execute($create_table1_2);
1144
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1145
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1146
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key1 => 1});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1147
$result = $dbi->select(table => $table1);
1148
is_deeply($param, {$key3 => 4});
1149
$row   = $result->one;
1150
is($row->{$key3}, 4);
1151
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1152

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1153
eval { $dbi->execute("drop table $table1") };
1154
$dbi->execute($create_table1_2);
1155
$param = {$key3 => 4};
1156
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1157
$dbi->update($param, table => $table1, mtime => $key2, where => {$key1 => 1});
1158
$result = $dbi->select(table => $table1);
1159
is_deeply($param, {$key3 => 4});
1160
$row   = $result->one;
1161
is($row->{$key3}, 4);
1162
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1163

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1164
eval { $dbi->execute("drop table $table1") };
1165
$dbi->execute($create_table1_2);
1166
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1167
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1168
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key3 => 3});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1169
$result = $dbi->select(table => $table1);
1170
is_deeply($param, {$key3 => 4});
1171
$row   = $result->one;
1172
is($row->{$key3}, 4);
1173
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1174

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1175
eval { $dbi->execute("drop table $table1") };
1176
$dbi->execute($create_table1_2);
1177
$param = {$key3 => 4};
1178
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1179
$dbi->update($param, table => $table1, mtime => $key2, where => {$key3 => 3});
1180
$result = $dbi->select(table => $table1);
1181
is_deeply($param, {$key3 => 4});
1182
$row   = $result->one;
1183
is($row->{$key3}, 4);
1184
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1185

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1210
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1211
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1212
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1213
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1214
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1215
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
1216
$dbi->update_all({$key2 => 10}, table => $table1, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1217
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1218
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1219
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1220
  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
1221
  "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1222

            
1223
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1224
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1225
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1226
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1227
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1228
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1229
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1230
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1231
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1232

            
cleanup test
Yuki Kimoto authored on 2011-08-15
1233
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
1234
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1235
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1236
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1237
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1238
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1239
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1240
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1241

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1244
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1245
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1246
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1247
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
1248
$rows = $dbi->select(table => $table1)->all;
1249
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1250

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1251
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1252
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1253
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1254
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1255
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1256
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1257
$where->param({ke1 => 1, $key2 => 2});
1258
$dbi->delete(table => $table1, where => $where);
1259
$result = $dbi->select(table => $table1);
1260
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1261

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1276
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1277
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1278
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1279
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
1280
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1281
$rows   = $result->all;
1282
is_deeply($rows, [], "basic");
1283

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1293
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
1294
$dbi = DBIx::Custom->connect;
1295
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1296
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1297
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1298
$dbi->insert({select => 1}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1299
$dbi->delete(table => 'table', where => {select => 1});
1300
$result = $dbi->execute("select * from ${q}table$p");
1301
$rows   = $result->all;
1302
is_deeply($rows, [], "reserved word");
1303

            
1304
test 'delete_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1305
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1306
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1307
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1308
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1309
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1310
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1311
$rows   = $result->all;
1312
is_deeply($rows, [], "basic");
1313

            
1314
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1315
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1316
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1317
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1318
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1319
$rows = $dbi->select(table => $table1)->all;
1320
is_deeply($rows, [{$key1 => 1, $key2 => 2},
cleanup
Yuki Kimoto authored on 2012-01-20
1321
  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
1322

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1337
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1338
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
1339
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1340
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1341
  table => [$table1, $table2],
fixed test
Yuki Kimoto authored on 2012-03-01
1342
  column => "$table1.$key1 as " . u("${table1}_$key1")
1343
    . ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
1344
  where   => {"$table1.$key2" => 2},
1345
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1346
)->all;
fixed test
Yuki Kimoto authored on 2012-03-01
1347
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
1348

            
1349
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1350
  table => [$table1, $table2],
fixed test
Yuki Kimoto authored on 2012-03-01
1351
  column => ["$table1.$key1 as " . u("${table1}_$key1") . ", ${table2}.$key1 as " . u("${table2}_$key1"), $key2, $key3],
cleanup
Yuki Kimoto authored on 2012-01-20
1352
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1353
)->all;
fixed test
Yuki Kimoto authored on 2012-03-01
1354
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
1355

            
1356
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
1357
eval { $dbi->execute("drop table ${q}table$p") };
1358
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1359
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1360
$dbi->insert({select => 1, update => 2}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1361
$result = $dbi->select(table => 'table', where => {select => 1});
1362
$rows   = $result->all;
1363
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
1364

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
1365
eval { $dbi->execute("drop table $table1") };
1366
$dbi->execute($create_table1);
1367
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1368
$row = $dbi->select($key1, table => $table1)->one;
1369
is_deeply($row, {$key1 => 1});
1370

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

            
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
1374
eval { $dbi->execute("drop table $table1") };
1375
$dbi->execute($create_table1);
1376
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1377
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
1378
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
1379

            
1380
$rows = $dbi->select(table => $table1, where => {$key1 => [1, 5]})->all;
1381
is_deeply($rows, [
1382
  {$key1 => 1, $key2 => 2},
1383
  {$key1 => 5, $key2 => 6}
1384
], "table");
1385

            
1386
$rows = $dbi->select(table => $table1, where => {$key1 => []})->all;
1387
is_deeply($rows, [], "table");
1388

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1389
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1390
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1391
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1392
  twice       => sub { $_[0] * 2 },
1393
  three_times => sub { $_[0] * 3 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1394
);
1395
$dbi->default_fetch_filter('twice');
1396
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1397
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1398
$result = $dbi->select(table => $table1);
1399
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1400
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1401
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1402

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1403
$dbi->default_fetch_filter('twice');
1404
eval { $dbi->execute("drop table $table1") };
1405
$dbi->execute($create_table1);
1406
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1407
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1408
$result->filter({$key1 => 'three_times'});
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1409
$row = $result->fetch_one;
1410
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter");
1411

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1418
test 'filters';
1419
$dbi = DBIx::Custom->new;
1420

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1427
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1428
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1429
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1430
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1431
$dbi->begin_work;
1432
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1433
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1434
$dbi->rollback;
1435
$dbi->dbh->{AutoCommit} = 1;
1436

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

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

            
1441
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1442
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1443
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1444
$dbi->begin_work;
1445
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1446
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1447
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1448
$dbi->commit;
1449
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1450
$result = $dbi->select(table => $table1);
1451
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
cleanup
Yuki Kimoto authored on 2012-01-20
1452
  "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1453

            
1454
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1455
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1456
$dbi->execute($create_table1);
1457
{
cleanup
Yuki Kimoto authored on 2012-01-20
1458
  local $Carp::Verbose = 0;
1459
  eval{$dbi->execute("select * frm $table1")};
1460
  like($@, qr/\Qselect * frm $table1/, "fail prepare");
1461
  like($@, qr/\.t /, "fail : not verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1462
}
1463
{
cleanup
Yuki Kimoto authored on 2012-01-20
1464
  local $Carp::Verbose = 1;
1465
  eval{$dbi->execute("select * frm $table1")};
1466
  like($@, qr/Custom.*\.t /s, "fail : verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1467
}
1468

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

            
1474
{
cleanup
Yuki Kimoto authored on 2012-01-20
1475
  local $Carp::Verbose = 0;
1476
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1477
  like($@, qr/\Q.t /, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1478
}
1479
{
cleanup
Yuki Kimoto authored on 2012-01-20
1480
  local $Carp::Verbose = 1;
1481
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1482
  like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1483
}
1484

            
1485

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1486
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1487
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1488
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1489
$dbi->execute($create_table1);
1490

            
1491
$dbi->begin_work;
1492

            
1493
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1494
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1495
  die "Error";
1496
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1497
};
1498

            
1499
$dbi->rollback if $@;
1500

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

            
1505
$dbi->begin_work;
1506

            
1507
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1508
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1509
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1510
};
1511

            
1512
$dbi->commit unless $@;
1513

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

            
1518
$dbi->dbh->{AutoCommit} = 0;
1519
eval{ $dbi->begin_work };
1520
ok($@, "exception");
1521
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1522

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1523
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1524
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1525
$dbi->cache(1);
1526
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1527
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1528
$dbi->execute($source, {}, query => 1);
1529
is_deeply($dbi->{_cached}->{$source}, 
cleanup
Yuki Kimoto authored on 2012-01-20
1530
  {sql => " select * from $table1 where $key1 = ?  and $key2 = ? ", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1531

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1532
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1533
$dbi->execute($create_table1);
1534
$dbi->{_cached} = {};
1535
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1536
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1537
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1538

            
1539
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1540
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1541
$dbi->execute($create_table1);
1542
{
cleanup
Yuki Kimoto authored on 2012-01-20
1543
  local $Carp::Verbose = 0;
1544
  eval{$dbi->execute("select * frm $table1")};
1545
  like($@, qr/\Qselect * frm $table1/, "fail prepare");
1546
  like($@, qr/\.t /, "fail : not verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1547
}
1548
{
cleanup
Yuki Kimoto authored on 2012-01-20
1549
  local $Carp::Verbose = 1;
1550
  eval{$dbi->execute("select * frm $table1")};
1551
  like($@, qr/Custom.*\.t /s, "fail : verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1552
}
1553

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

            
1559
{
cleanup
Yuki Kimoto authored on 2012-01-20
1560
  local $Carp::Verbose = 0;
1561
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1562
  like($@, qr/\Q.t /, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1563
}
1564
{
cleanup
Yuki Kimoto authored on 2012-01-20
1565
  local $Carp::Verbose = 1;
1566
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1567
  like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1568
}
1569

            
1570
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1571
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1572
  one => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1573
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1574
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1575
  two => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1576
);
1577
$dbi->method({
cleanup
Yuki Kimoto authored on 2012-01-20
1578
  twice => sub {
1579
    my $self = shift;
1580
    return $_[0] * 2;
1581
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
1582
});
1583

            
1584
is($dbi->one, 1, "first");
1585
is($dbi->two, 2, "second");
1586
is($dbi->twice(5), 10 , "second");
1587

            
1588
eval {$dbi->XXXXXX};
1589
ok($@, "not exists");
1590

            
1591
test 'out filter';
1592
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1593
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1594
$dbi->execute($create_table1);
1595
$dbi->register_filter(twice => sub { $_[0] * 2 });
1596
$dbi->register_filter(three_times => sub { $_[0] * 3});
1597
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1598
  $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1599
            $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
1600
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1601
$result = $dbi->execute("select * from $table1");
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1602
$row   = $result->fetch_hash_one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1603
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1604
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1605
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1606
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1607

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1613
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1614
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1615
$dbi->execute($create_table1);
1616
$dbi->register_filter(twice => sub { $_[0] * 2 });
1617
$dbi->register_filter(three_times => sub { $_[0] * 3});
1618
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1619
  $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1620
            $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1621
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1622
  $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1623
); 
test cleanup
Yuki Kimoto authored on 2011-11-01
1624
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1625
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1626
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1627
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1628

            
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->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1634
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1635
);
cleanup
Yuki Kimoto authored on 2011-11-01
1636
$dbi->insert({$key1 => 1, $key2 => 2},table => $table1, filter => {$key1 => undef});
1637
$dbi->update({$key1 => 2}, table => $table1, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1638
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1639
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1640
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
test cleanup
Yuki Kimoto authored on 2011-08-10
1641

            
1642
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1643
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1644
$dbi->execute($create_table1);
1645
$dbi->register_filter(twice => sub { $_[0] * 2 });
1646
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1647
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1648
);
cleanup
Yuki Kimoto authored on 2011-11-01
1649
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1=> undef});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1650
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1651
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1652
$rows   = $result->all;
1653
is_deeply($rows, [], "delete");
1654

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

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

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

            
1695
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1696
eval { $dbi->execute("drop table $table1") };
1697
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1698
$dbi->execute($create_table1);
1699
$dbi->execute($create_table2);
1700
$dbi->register_filter(twice => sub { $_[0] * 2 });
1701
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1702
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1703
  $table1, $key2 => {out => 'twice', in => 'twice'}
cleanup test
Yuki Kimoto authored on 2011-08-15
1704
);
1705
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1706
  $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1707
);
cleanup
Yuki Kimoto authored on 2011-11-01
1708
$dbi->insert({$key1 => 5, $key2 => 2}, table => $table1, filter => {$key2 => undef});
1709
$dbi->insert({$key1 => 5, $key3 => 6}, table => $table2, filter => {$key3 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1710
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1711
  table => [$table1, $table2],
1712
  column => [$key2, $key3],
1713
  where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
cleanup test
Yuki Kimoto authored on 2011-08-15
1714

            
1715
$result->filter({$key2 => 'twice'});
1716
$rows   = $result->all;
1717
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1718

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

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

            
1728
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1729
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1730
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1731
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1732
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1733
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1734

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1735
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1736
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1737
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1738
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1739
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1740
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1741

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

            
1748
test 'end_filter';
1749
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1750
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1751
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1752
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1753
$result = $dbi->select(table => $table1);
1754
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1755
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1756
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1757
is_deeply($row, [6, 40]);
1758

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1759
$dbi = DBIx::Custom->connect;
1760
eval { $dbi->execute("drop table $table1") };
1761
$dbi->execute($create_table1);
1762
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1763
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1764
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1765
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1766
$row = $result->fetch_one;
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1767
is_deeply($row, [6, 6, 40]);
1768

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1769
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1770
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1771
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1772
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1773
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1774
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1775
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1776
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1777
is_deeply($row, [6, 12]);
1778

            
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
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1784
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1785
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1786
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1787
is_deeply($row, [6, 12]);
1788

            
1789
$dbi->register_filter(five_times => sub { $_[0] * 5 });
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 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1793
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1794
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1795

            
1796
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1797
$dbi->apply_filter($table1,
cleanup
Yuki Kimoto authored on 2012-01-20
1798
  $key1 => {end => sub { $_[0] * 3 } },
1799
  $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1800
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1801
$result = $dbi->select(table => $table1);
1802
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1803
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1804
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1805

            
1806
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1807
$dbi->apply_filter($table1,
cleanup
Yuki Kimoto authored on 2012-01-20
1808
  $key1 => {end => sub { $_[0] * 3 } },
1809
  $key2 => {end => 'five_times'}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1810
);
1811
$result = $dbi->select(table => $table1);
1812
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1813
$result->filter($key1 => undef);
1814
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1815
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1816
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1817

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1818
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1819
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1820
$result->filter($key1 => undef);
1821
$result->end_filter($key1 => undef);
1822
$row = $result->fetch;
1823
is_deeply($row, [1, 1, 40], 'apply_filter overwrite');
1824

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

            
1839
test 'empty where select';
1840
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1841
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1842
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1843
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1844
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1845
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1846
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1847

            
1848
test 'select query option';
1849
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1850
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1851
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1852
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1853
ok(ref $query);
cleanup
Yuki Kimoto authored on 2011-11-01
1854
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1855
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1856
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1857
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1858
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1859
ok(ref $query);
test cleanup
Yuki Kimoto authored on 2011-08-10
1860

            
1861
test 'where';
1862
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1863
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1864
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1865
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1866
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1867
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1868
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1869

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

            
1874
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1875
  table => $table1,
1876
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1877
);
1878
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1879
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1880

            
1881
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1882
  table => $table1,
1883
  where => [
1884
    ['and', "$key1 = :$key1", "$key2 = :$key2"],
1885
    {$key1 => 1}
1886
  ]
test cleanup
Yuki Kimoto authored on 2011-08-10
1887
);
1888
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1889
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1890

            
1891
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1892
  ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1893
  ->param({$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1894
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1895
  table => $table1,
1896
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1897
);
1898
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1899
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1900

            
1901
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1902
  ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1903
  ->param({});
test cleanup
Yuki Kimoto authored on 2011-08-10
1904
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1905
  table => $table1,
1906
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1907
);
1908
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1909
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1910

            
1911
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1912
  ->clause(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"])
1913
  ->param({$key1 => [0, 3], $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1914
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1915
  table => $table1,
1916
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1917
); 
1918
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1919
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1920

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

            
1929
eval {
1930
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1931
           ->clause(['uuu']);
test cleanup
Yuki Kimoto authored on 2011-08-10
1932
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1933
  table => $table1,
1934
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1935
);
1936
};
1937
ok($@);
1938

            
1939
$where = $dbi->where;
1940
is("$where", '');
1941

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2092
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2093
  ->clause(['and', "{> $key1}", "{< $key1}" ])
2094
  ->param({$key1 => [0, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2095
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2096
  table => $table1,
2097
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2098
);
2099
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2100
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
2101

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

            
2111
eval {$dbi->where(ppp => 1) };
2112
like($@, qr/invalid/);
2113

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

            
2125

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

            
2137
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2138
$where->clause(['and', ":${key1}{=}"]);
2139
$where->param({$key1 => undef});
2140
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
2141
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2142
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2143

            
2144
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2145
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2146
$where->param({$key1 => [undef, undef]});
2147
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2148
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2149
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2150
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2151
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2152
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2153

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

            
2155
$dbi = DBIx::Custom->connect;
2156
eval { $dbi->execute("drop table $table1") };
2157
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2158
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
2159
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2160
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2161
  ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
2162
  ->param({$key1 => 1});
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2163

            
2164
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2165
  table => $table1,
2166
  where => $where
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2167
);
2168
$row = $result->all;
2169
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
2170

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2171
test 'register_tag_processor';
2172
$dbi = DBIx::Custom->connect;
2173
$dbi->register_tag_processor(
cleanup
Yuki Kimoto authored on 2012-01-20
2174
  a => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
2175
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2176
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2177

            
2178
test 'register_tag';
2179
$dbi = DBIx::Custom->connect;
2180
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
2181
  b => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
2182
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2183
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2184

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2190
test 'more tests';
2191
$dbi = DBIx::Custom->connect;
2192
eval{$dbi->apply_filter('table', 'column', [])};
2193
like($@, qr/apply_filter/);
2194

            
2195
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
2196
like($@, qr/apply_filter/);
2197

            
2198
$dbi->apply_filter(
2199

            
2200
);
2201
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2202
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2203
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2204
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2205
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2206
$dbi->apply_filter($table1, $key2, 
cleanup
Yuki Kimoto authored on 2012-01-20
2207
                 {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2208
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
2209
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2210

            
2211
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2212
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2213
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2214
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2215
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2216
$dbi->apply_filter($table1, $key2, {});
2217
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
2218
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2219

            
2220
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2221
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2222
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2223
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2224
like($@, qr/not registered/);
2225
$dbi->method({one => sub { 1 }});
2226
is($dbi->one, 1);
2227

            
2228
eval{DBIx::Custom->connect(dsn => undef)};
2229
like($@, qr/_connect/);
2230

            
2231
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2232
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2233
$dbi->execute($create_table1);
2234
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
2235
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
2236
           filter => {$key1 => 'twice'});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2237
$row = $dbi->select(table => $table1)->one;
2238
is_deeply($row, {$key1 => 2, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
2239
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
2240
           filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
2241
like($@, qr//);
2242

            
2243
$dbi->register_filter(one => sub { });
2244
$dbi->default_fetch_filter('one');
2245
ok($dbi->default_fetch_filter);
2246
$dbi->default_bind_filter('one');
2247
ok($dbi->default_bind_filter);
2248
eval{$dbi->default_fetch_filter('no')};
2249
like($@, qr/not registered/);
2250
eval{$dbi->default_bind_filter('no')};
2251
like($@, qr/not registered/);
2252
$dbi->default_bind_filter(undef);
2253
ok(!defined $dbi->default_bind_filter);
2254
$dbi->default_fetch_filter(undef);
2255
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2256
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2257
like($@, qr/Tag not finished/);
2258

            
2259
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2260
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2261
$dbi->execute($create_table1);
2262
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2263
$result = $dbi->select(table => $table1);
2264
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2265
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2266
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2267
like($@, qr/not registered/);
2268
$result->default_filter(undef);
2269
ok(!defined $result->default_filter);
2270
$result->default_filter('one');
2271
is($result->default_filter->(), 1);
2272

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2273
test 'option';
2274
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
2275
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
2276
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2277
ok($dbi->dbh->{PrintError});
2278
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2279
ok($dbi->dbh->{PrintError});
2280

            
2281
test 'DBIx::Custom::Result stash()';
2282
$result = DBIx::Custom::Result->new;
2283
is_deeply($result->stash, {}, 'default');
2284
$result->stash->{foo} = 1;
2285
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2286

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2287
test 'delete_at';
2288
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2289
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2290
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2291
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2292
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2293
  table => $table1,
2294
  primary_key => [$key1, $key2],
2295
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2296
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2297
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2298

            
cleanup
Yuki Kimoto authored on 2011-11-01
2299
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2300
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2301
  table => $table1,
2302
  primary_key => $key1,
2303
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2304
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2305
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2306

            
2307
test 'insert_at';
2308
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2309
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2310
$dbi->execute($create_table1_2);
2311
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2312
  {$key3 => 3},
2313
  primary_key => [$key1, $key2], 
2314
  table => $table1,
2315
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2316
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2317
is($dbi->select(table => $table1)->one->{$key1}, 1);
2318
is($dbi->select(table => $table1)->one->{$key2}, 2);
2319
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2320

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2321
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2322
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2323
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2324
  {$key2 => 2, $key3 => 3},
2325
  primary_key => $key1, 
2326
  table => $table1,
2327
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2328
);
2329

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

            
2334
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2335
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2336
$dbi->execute($create_table1_2);
2337
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2338
  {$key3 => 3},
2339
  primary_key => [$key1, $key2], 
2340
  table => $table1,
2341
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2342
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2343
is($dbi->select(table => $table1)->one->{$key1}, 1);
2344
is($dbi->select(table => $table1)->one->{$key2}, 2);
2345
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2346

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2415
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2416
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2417
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2418
  table => $table1,
2419
  primary_key => [$key1, $key2],
2420
  where => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2421
);
2422
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2423
is($row->{$key1}, 1);
2424
is($row->{$key2}, 2);
2425
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2426

            
2427
test 'model delete_at';
2428
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2429
eval { $dbi->execute("drop table $table1") };
2430
eval { $dbi->execute("drop table $table2") };
2431
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2432
$dbi->execute($create_table1_2);
2433
$dbi->execute($create_table2_2);
2434
$dbi->execute($create_table3);
test cleanup
Yuki Kimoto authored on 2011-11-01
2435
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2436
$dbi->model($table1)->delete_at(where => [1, 2]);
2437
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2438
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2439
$dbi->model($table1)->delete_at(where => [1, 2]);
2440
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2441
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2442
$dbi->model($table3)->delete_at(where => [1, 2]);
2443
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2444

            
2445
test 'model insert_at';
2446
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2447
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2448
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2449
$dbi->model($table1)->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2450
  {$key3 => 3},
2451
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2452
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2453
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2454
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2455
is($row->{$key1}, 1);
2456
is($row->{$key2}, 2);
2457
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2458

            
2459
test 'model update_at';
2460
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2461
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2462
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2463
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2464
$dbi->model($table1)->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2465
  {$key3 => 4},
2466
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2467
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2468
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2469
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2470
is($row->{$key1}, 1);
2471
is($row->{$key2}, 2);
2472
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2473

            
2474
test 'model select_at';
2475
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2476
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2477
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2478
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2479
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2480
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2481
is($row->{$key1}, 1);
2482
is($row->{$key2}, 2);
2483
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2484

            
2485

            
2486
test 'mycolumn and column';
2487
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2488
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2489
eval { $dbi->execute("drop table $table1") };
2490
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2491
$dbi->execute($create_table1);
2492
$dbi->execute($create_table2);
2493
$dbi->separator('__');
improved test
Yuki Kimoto authored on 2012-03-01
2494
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
2495
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2496
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2497
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2498
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2499
  column => [$model->mycolumn, $model->column($table2)],
2500
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2501
);
2502
is_deeply($result->one,
improved test
Yuki Kimoto authored on 2012-03-01
2503
        {$key1 => 1, $key2 => 2, u2"${table2}__$key1" => 1, u2"${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2504

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2505
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2506
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2507
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2508
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2509
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2510
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2511
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2512
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2513
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2514
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2515
is($dbi->select(table => $table1)->one->{$key1}, 1);
2516
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2517

            
2518
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2519
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2520
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2521
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2522
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2523
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2524
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2525
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2526
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2527
is($dbi->select(table => $table1)->one->{$key1}, 1);
2528
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2529

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

            
2550
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2551
  column => [
2552
    $model->mycolumn([$key1]),
2553
    $model->column($table2 => [$key1])
2554
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2555
);
2556
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2557
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2558
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2559
  column => [
2560
    $model->mycolumn([$key1]),
2561
    {$table2 => [$key1]}
2562
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2563
);
2564
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2565
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2566

            
2567
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2568
  column => [
2569
    $model->mycolumn([$key1]),
2570
    ["$table2.$key1", as => "$table2.$key1"]
2571
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2572
);
2573
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2574
  {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2575

            
2576
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2577
  column => [
2578
    $model->mycolumn([$key1]),
2579
    ["$table2.$key1" => "$table2.$key1"]
2580
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2581
);
2582
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2583
  {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2584

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2585
test 'merge_param';
2586
$dbi = DBIx::Custom->new;
2587
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2588
  {$key1 => 1, $key2 => 2, $key3 => 3},
2589
  {$key1 => 1, $key2 => 2},
2590
  {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2591
];
2592
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2593
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2594

            
2595
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2596
  {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2597
  {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2598
];
2599
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2600
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
2601

            
2602
test 'select() param option';
2603
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2604
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2605
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2606
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2607
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2608
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2609
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2610
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
2611
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
2612
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2613
  table => $table1,
improved test
Yuki Kimoto authored on 2012-03-01
2614
  column => "$table1.$key1 as " . u("${table1}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
2615
  where   => {"$table1.$key2" => 3},
2616
  join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
improved test
Yuki Kimoto authored on 2012-03-01
2617
            " $q$table2$p on $table1.$key1 = $q$table2$p.$key1"],
cleanup
Yuki Kimoto authored on 2012-01-20
2618
  param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2619
)->all;
improved test
Yuki Kimoto authored on 2012-03-01
2620
is_deeply($rows, [{u"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2621

            
cleanup
Yuki Kimoto authored on 2011-10-21
2622
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2623
  table => $table1,
improved test
Yuki Kimoto authored on 2012-03-01
2624
  column => "$table1.$key1 as " . u("${table1}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
2625
  where   => {"$table1.$key2" => 3},
2626
  join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
improved test
Yuki Kimoto authored on 2012-03-01
2627
           " $q$table2$p on $table1.$key1 = $q$table2$p.$key1",
cleanup
Yuki Kimoto authored on 2012-01-20
2628
  param => {"$table2.$key3" => 5}
cleanup
Yuki Kimoto authored on 2011-10-21
2629
)->all;
improved test
Yuki Kimoto authored on 2012-03-01
2630
is_deeply($rows, [{u"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup
Yuki Kimoto authored on 2011-10-21
2631

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2632
test 'select() string where';
2633
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2634
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2635
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2636
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2637
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2638
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2639
  table => $table1,
2640
  where => "$key1 = :$key1 and $key2 = :$key2",
2641
  where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2642
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2643
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2644

            
2645
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2646
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2647
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2648
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2649
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2650
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2651
  table => $table1,
2652
  where => [
2653
    "$key1 = :$key1 and $key2 = :$key2",
2654
    {$key1 => 1, $key2 => 2}
2655
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2656
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2657
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2658

            
cleanup
Yuki Kimoto authored on 2011-10-21
2659
$dbi = DBIx::Custom->connect;
2660
eval { $dbi->execute("drop table $table1") };
2661
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2662
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2663
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
2664
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2665
  table => $table1,
2666
  where => [
2667
    "$key1 = :$key1 and $key2 = :$key2",
2668
    {$key1 => 1, $key2 => 2}
2669
  ]
cleanup
Yuki Kimoto authored on 2011-10-21
2670
)->all;
2671
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2672

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

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

            
2702

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

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

            
2732
test 'insert id and primary_key option';
2733
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2734
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2735
$dbi->execute($create_table1_2);
2736
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2737
  {$key3 => 3},
2738
  primary_key => [$key1, $key2], 
2739
  table => $table1,
2740
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2741
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2742
is($dbi->select(table => $table1)->one->{$key1}, 1);
2743
is($dbi->select(table => $table1)->one->{$key2}, 2);
2744
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2745

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2746
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2747
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2748
  {$key2 => 2, $key3 => 3},
2749
  primary_key => $key1, 
2750
  table => $table1,
2751
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2752
);
2753

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2758
$dbi = DBIx::Custom->connect;
2759
eval { $dbi->execute("drop table $table1") };
2760
$dbi->execute($create_table1_2);
2761
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2762
  {$key3 => 3},
2763
  primary_key => [$key1, $key2], 
2764
  table => $table1,
2765
  id => 1,
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2766
);
2767
is($dbi->select(table => $table1)->one->{$key1}, 1);
2768
ok(!$dbi->select(table => $table1)->one->{$key2});
2769
is($dbi->select(table => $table1)->one->{$key3}, 3);
2770

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

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2784
$dbi = DBIx::Custom->connect;
2785
eval { $dbi->execute("drop table $table1") };
2786
$dbi->execute($create_table1_2);
2787
$param = {$key3 => 3, $key2 => 4};
2788
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2789
  $param,
2790
  primary_key => [$key1, $key2], 
2791
  table => $table1,
2792
  id => [1, 2],
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2793
);
2794
is($dbi->select(table => $table1)->one->{$key1}, 1);
2795
is($dbi->select(table => $table1)->one->{$key2}, 4);
2796
is($dbi->select(table => $table1)->one->{$key3}, 3);
2797
is_deeply($param, {$key3 => 3, $key2 => 4});
2798

            
added test
Yuki Kimoto authored on 2011-10-25
2799
$dbi = DBIx::Custom->connect;
2800
eval { $dbi->execute("drop table $table1") };
2801
$dbi->execute($create_table1_2);
2802
$param = {$key3 => 3, $key2 => 4};
2803
$query = $dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2804
  $param,
2805
  primary_key => [$key1, $key2], 
2806
  table => $table1,
2807
  id => [1, 2],
2808
  query => 1
added test
Yuki Kimoto authored on 2011-10-25
2809
);
micro optimization
Yuki Kimoto authored on 2011-11-16
2810
ok(ref $query);
added test
Yuki Kimoto authored on 2011-10-25
2811
is_deeply($param, {$key3 => 3, $key2 => 4});
2812

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

            
2827
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2828
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2829
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2830
$dbi->model($table1)->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2831
  {$key3 => 3},
2832
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2833
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2834
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2835
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2836
is($row->{$key1}, 1);
2837
is($row->{$key2}, 2);
2838
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2839

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2855
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2856
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2857
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2858
  {$key3 => 4},
2859
  table => $table1,
2860
  primary_key => $key1,
2861
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2862
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2863
is($dbi->select(table => $table1)->one->{$key1}, 0);
2864
is($dbi->select(table => $table1)->one->{$key2}, 2);
2865
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2866

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

            
2881

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

            
2897

            
2898
test 'delete and id option';
2899
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2900
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2901
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2902
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2903
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2904
  table => $table1,
2905
  primary_key => [$key1, $key2],
2906
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2907
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2908
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2909

            
cleanup
Yuki Kimoto authored on 2011-11-01
2910
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2911
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2912
  table => $table1,
2913
  primary_key => $key1,
2914
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2915
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2916
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2917

            
2918

            
2919
test 'model delete 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") };
2922
eval { $dbi->execute("drop table $table2") };
2923
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2924
$dbi->execute($create_table1_2);
2925
$dbi->execute($create_table2_2);
2926
$dbi->execute($create_table3);
cleanup
Yuki Kimoto authored on 2011-11-01
2927
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2928
$dbi->model($table1)->delete(id => [1, 2]);
2929
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2930
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2931
$dbi->model($table1)->delete(id => [1, 2]);
2932
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2933
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2934
$dbi->model($table3)->delete(id => [1, 2]);
2935
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2936

            
2937

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2965
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2966
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2967
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2968
  table => $table1,
2969
  primary_key => [$key1, $key2],
2970
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2971
);
2972
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2973
is($row->{$key1}, 1);
2974
is($row->{$key2}, 2);
2975
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2976

            
2977

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

            
2989
test 'column separator is default .';
2990
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2991
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2992
eval { $dbi->execute("drop table $table1") };
2993
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2994
$dbi->execute($create_table1);
2995
$dbi->execute($create_table2);
improved test
Yuki Kimoto authored on 2012-03-01
2996
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
2997
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2998
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2999
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3000
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3001
  column => [$model->column($table2)],
3002
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3003
);
3004
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3005
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
3006

            
3007
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3008
  column => [$model->column($table2 => [$key1, $key3])],
3009
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3010
);
3011
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3012
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3013

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3014
test 'separator';
3015
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3016
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3017
eval { $dbi->execute("drop table $table1") };
3018
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3019
$dbi->execute($create_table1);
3020
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
3021

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3022
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3023
  table => $table1,
3024
  join => [
3025
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3026
  ],
3027
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
3028
);
3029
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3030
  table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
3031
);
improved test
Yuki Kimoto authored on 2012-03-01
3032
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
3033
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3034
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3035
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3036
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3037
  column => [
3038
    $model->mycolumn,
3039
    {$table2 => [$key1, $key3]}
3040
  ],
3041
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3042
);
3043
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3044
        {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3045
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3046

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3047
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3048
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3049
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3050
  column => [
3051
    $model->mycolumn,
3052
    {$table2 => [$key1, $key3]}
3053
  ],
3054
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3055
);
3056
is_deeply($result->one,
improved test
Yuki Kimoto authored on 2012-03-01
3057
        {$key1 => 1, $key2 => 2, u2"${table2}__$key1" => 1, u2"${table2}__$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3058
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3059

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3060
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3061
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3062
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3063
  column => [
3064
    $model->mycolumn,
3065
    {$table2 => [$key1, $key3]}
3066
  ],
3067
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3068
);
3069
is_deeply($result->one,
improved test
Yuki Kimoto authored on 2012-03-01
3070
  {$key1 => 1, $key2 => 2, hy"$table2-$key1" => 1, hy"$table2-$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3071
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3072

            
3073

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3074
test 'filter_off';
3075
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3076
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3077
eval { $dbi->execute("drop table $table1") };
3078
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3079
$dbi->execute($create_table1);
3080
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
3081

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3082
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3083
  table => $table1,
3084
  join => [
3085
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3086
  ],
3087
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
3088
);
improved test
Yuki Kimoto authored on 2012-03-01
3089
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
3090
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3091
$model = $dbi->model($table1);
3092
$result = $model->select(column => $key1);
3093
$result->filter($key1 => sub { $_[0] * 2 });
3094
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
3095

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3096
test 'available_datetype';
3097
$dbi = DBIx::Custom->connect;
3098
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
3099

            
3100

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3101
test 'select prefix option';
3102
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3103
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3104
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3105
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3106
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3107
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
3108

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

            
added tests
Yuki Kimoto authored on 2011-08-26
3110
test 'mapper';
3111
$dbi = DBIx::Custom->connect;
3112
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3113
  id => {key => "$table1.id"},
3114
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3115
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
3116
);
3117
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3118
"$table1.price" => 1900});
added tests
Yuki Kimoto authored on 2011-08-26
3119

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3120
$dbi = DBIx::Custom->connect;
3121
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3122
  id => {key => "$table1.id"},
3123
  author => ["$table1.author" => $dbi->like_value],
3124
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3125
);
3126
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3127
"$table1.price" => 1900});
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3128

            
added tests
Yuki Kimoto authored on 2011-08-26
3129
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3130
  id => {key => "$table1.id"},
3131
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3132
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
3133
);
3134
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
3135

            
3136
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3137
  id => {key => "$table1.id"},
3138
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3139
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
added tests
Yuki Kimoto authored on 2011-08-26
3140
);
3141
is_deeply($param, {});
3142

            
3143
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3144
  id => {key => "$table1.id"},
3145
  price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
3146
);
3147
is_deeply($param, {"$table1.price" => undef});
3148

            
3149
$param = $dbi->mapper(param => {price => 'a'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3150
  id => {key => "$table1.id", condition => 'exists'},
3151
  price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
3152
);
3153
is_deeply($param, {"$table1.price" => '%a'});
3154

            
3155
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3156
  id => {key => "$table1.id"},
3157
  price => ["$table1.price", sub { '%' . $_[0] }]
added tests
Yuki Kimoto authored on 2011-08-26
3158
);
3159
is_deeply($param, {"$table1.price" => '%a'});
3160

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3161
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3162
  price => sub { '%' . $_[0] },
3163
  author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
3164
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3165
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
3166

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

            
3172
$where = $dbi->where;
3173
$where->clause(['and', ":${key1}{=}"]);
3174
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
3175
$where->param($param);
3176
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3177
$row = $result->all;
3178
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3179

            
3180
$where = $dbi->where;
3181
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
3182
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
3183
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
3184
$row = $result->all;
3185
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3186
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
3187
$row = $result->all;
3188
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3189

            
3190
$where = $dbi->where;
3191
$where->clause(['and', ":${key1}{=}"]);
3192
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
3193
$where->param($param);
3194
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
3195
$row = $result->all;
3196
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3197
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
3198
$row = $result->all;
3199
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3200

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3202
$where = $dbi->where;
3203
$where->clause(['and', ":${key1}{=}"]);
3204
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
cleanup
Yuki Kimoto authored on 2012-01-20
3205
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3206
$where->param($param);
3207
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3208
$row = $result->all;
3209
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3210

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

            
3219
$where = $dbi->where;
3220
$where->clause(['and', ":${key1}{=}"]);
3221
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
cleanup
Yuki Kimoto authored on 2012-01-20
3222
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3223
$where->param($param);
3224
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3225
$row = $result->all;
3226
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3227

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3229
$where = $dbi->where;
3230
$where->clause(['and', ":${key1}{=}"]);
3231
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
3232
$where->param($param);
3233
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3234
$row = $result->all;
3235
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3236

            
3237
$where = $dbi->where;
3238
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3239
  id => {key => "$table1.id"},
3240
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3241
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3242
);
3243
$where->param($param);
3244
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3245
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3246

            
3247
$where = $dbi->where;
3248
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3249
  id => {key => "$table1.id"},
3250
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3251
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3252
);
3253
$where->param($param);
3254
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
3255

            
3256
$where = $dbi->where;
3257
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3258
  id => {key => "$table1.id"},
3259
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3260
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3261
);
3262
$where->param($param);
3263
is_deeply($where->param, {});
3264

            
3265
$where = $dbi->where;
3266
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3267
  id => {key => "$table1.id"},
3268
  price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3269
);
3270
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
3271

            
3272
$where = $dbi->where;
3273
$param = $dbi->mapper(param => {price => 'a'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3274
  id => {key => "$table1.id", condition => 'exists'},
3275
  price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3276
);
3277
is_deeply($param, {"$table1.price" => '%a'});
3278

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

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

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

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

            
- DBIx::Custom::Mapper::map ...
Yuki Kimoto authored on 2012-02-29
3311
$param = $dbi->mapper(param => {author => 'Ken',})->map(
3312
  author => ["$table1.author" => '%<value>%'],
3313
);
3314
is_deeply($param, {"$table1.author" => '%Ken%'});
3315

            
3316
$param = $dbi->mapper(param => {author => 'Ken'})->map(
3317
  author => ["$table1.author" => 'p'],
3318
);
3319
is_deeply($param, {"$table1.author" => 'p'});
3320

            
3321
$param = $dbi->mapper(param => {author => 'Ken',})->map(
3322
  author => {value => '%<value>%'}
3323
);
3324
is_deeply($param, {"author" => '%Ken%'});
3325

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3326
test 'order';
3327
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3328
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3329
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3330
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3331
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3332
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3333
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3334
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3335
$order->prepend($key1, "$key2 desc");
3336
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3337
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
3338
{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3339
$order->prepend("$key1 desc");
3340
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3341
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
cleanup
Yuki Kimoto authored on 2012-01-20
3342
{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3343

            
3344
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3345
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3346
$result = $dbi->select(table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
3347
column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
3348
append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3349
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
cleanup
Yuki Kimoto authored on 2012-01-20
3350
{"$table1-$key1" => 1, "$table1-$key2" => 1},
3351
{"$table1-$key1" => 2, "$table1-$key2" => 4},
3352
{"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3353

            
3354
test 'tag_parse';
3355
$dbi = DBIx::Custom->connect;
3356
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3357
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3358
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3359
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3360
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3361
ok($@);
3362

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3363
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3364
{
cleanup
Yuki Kimoto authored on 2012-01-20
3365
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3366
  $dbi = DBIx::Custom->connect;
3367
  eval { $dbi->execute("drop table $table1") };
3368
  $dbi->execute($create_table1);
3369
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3370
  eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3371
  ok($@);
3372
  eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) };
3373
  ok($@);
3374
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3375
}
3376

            
3377
{
cleanup
Yuki Kimoto authored on 2012-01-20
3378
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3379
  $dbi = DBIx::Custom->connect;
3380
  eval { $dbi->execute("drop table $table1") };
3381
  $dbi->execute($create_table1);
3382
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3383
  is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1);
3384
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3385
}
3386

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3387
test 'last_sql';
3388
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3389
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3390
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3391
$dbi->execute("select * from $table1");
micro optimization
Yuki Kimoto authored on 2011-11-18
3392
is($dbi->last_sql, " select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3393

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3425
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3426
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
3427
  $source,
3428
  {"$table1.$key1" => 1, "$table1.$key2" => 1},
3429
  filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3430
);
3431
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3432
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3433

            
3434
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3435
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3436
$dbi->execute($create_table1_highperformance);
3437
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3438
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3439
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3440
];
3441
{
cleanup
Yuki Kimoto authored on 2012-01-20
3442
  my $query;
3443
  for my $row (@$rows) {
3444
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3445
    $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3446
  }
3447
  is_deeply($dbi->select(table => $table1)->all,
3448
    [
3449
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3450
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3451
    ]
3452
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3453
}
3454

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3455
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3456
$dbi->execute($create_table1_highperformance);
3457
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3458
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3459
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3460
];
3461
{
cleanup
Yuki Kimoto authored on 2012-01-20
3462
  my $query;
3463
  my $sth;
3464
  for my $row (@$rows) {
3465
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3466
    $sth ||= $query->{sth};
3467
    $sth->execute(map { $row->{$_} } sort keys %$row);
3468
  }
3469
  is_deeply($dbi->select(table => $table1)->all,
3470
    [
3471
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3472
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3473
    ]
3474
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3475
}
3476

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

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3498
eval { $dbi->execute("drop table $table1") };
3499
$dbi->execute($create_table1);
3500
{
cleanup
Yuki Kimoto authored on 2012-01-20
3501
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3502
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3503
  eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3504
  like($@, qr/primary_key/);
3505
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3506
}
3507

            
3508
{
cleanup
Yuki Kimoto authored on 2012-01-20
3509
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3510
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3511
  $model->insert({$key1 => 1});
3512
  $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3513
    table => $table1, primary_key => $key1);
3514
  is($result->one->{$key1}, 1);
3515
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3516
}
3517

            
3518
eval { $dbi->execute("drop table $table1") };
3519
$dbi->execute($create_table1);
3520
{
cleanup
Yuki Kimoto authored on 2012-01-20
3521
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3522
  $model->insert({$key1 => 1});
3523
  eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3524
  is($result->one->{$key1}, 1);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3525
}
3526

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3527
test 'id option more';
3528
eval { $dbi->execute("drop table $table1") };
3529
$dbi->execute($create_table1_highperformance);
3530
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3531
  $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
3532
};
3533
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3534
$model->insert($row);
3535
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3536
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3537
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3538
  {$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
3539
);
3540

            
3541
eval { $dbi->execute("drop table $table1") };
3542
eval { $dbi->execute("drop table $table2") };
3543
$dbi->execute($create_table1);
3544
$dbi->execute($create_table2);
3545
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3546
$model->insert({$key1 => 1, $key2 => 2});
3547
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
3548
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3549
$model->insert({$key1 => 1, $key3 => 3});
3550
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3551
  column => {$table1 => ["$key2"]},
3552
  id => 1
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3553
);
3554
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3555

            
3556
eval { $dbi->execute("drop table $table1") };
3557
$dbi->execute($create_table1_highperformance);
3558
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3559
  $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
3560
};
3561
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3562
$model->insert($row);
3563
$query = $model->delete(id => 1, query => 1);
3564
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3565
is_deeply($dbi->select(table => $table1)->all, []);
3566

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3581
test 'result';
3582
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3583
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3584
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3585
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3586
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3587

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3588
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3589
@rows = ();
3590
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
3591
  push @rows, [@$row];
test cleanup
Yuki Kimoto authored on 2011-08-10
3592
}
3593
is_deeply(\@rows, [[1, 2], [3, 4]]);
3594

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3595
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3596
@rows = ();
3597
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
3598
  push @rows, {%$row};
test cleanup
Yuki Kimoto authored on 2011-08-10
3599
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3600
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3601

            
3602
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3603
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3604
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3605
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3606
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3607

            
3608
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3609
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3610
$rows = $result->fetch_all;
3611
is_deeply($rows, [[1, 2], [3, 4]]);
3612

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3617
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3618
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3619
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3620
$rows = $result->fetch_all;
3621
is_deeply($rows, [[3, 2], [9, 4]], "array");
3622

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2012-02-28
3635
test 'flat';
3636
$result = $dbi->select(table => $table1);
3637
$rows = [$result->flat];
3638
is_deeply($rows, [1, 2, 3, 4]);
3639

            
added EXPERIMETAL DBIx::Cust...
Yuki Kimoto authored on 2012-02-28
3640
test 'kv';
3641
$dbi = DBIx::Custom->connect;
3642
eval { $dbi->execute("drop table $table1") };
3643
$dbi->execute($create_table1);
3644
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3645
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3646

            
3647
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key1");
3648
$rows = $result->kv;
3649
is_deeply($rows, {0 => {$key2 => 2}, 3 => {$key2 => 4}});
3650

            
3651
$dbi = DBIx::Custom->connect;
3652
eval { $dbi->execute("drop table $table1") };
3653
$dbi->execute($create_table1);
3654
$dbi->insert({$key1 => 0, $key2 => 1}, table => $table1);
3655
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3656
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3657
$dbi->insert({$key1 => 3, $key2 => 5}, table => $table1);
3658

            
3659
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key2");
3660
$rows = $result->kv(multi => 1);
3661
is_deeply($rows, {
3662
  0 => [
3663
    {$key2 => 1},
3664
    {$key2 => 2}
3665
  ],
3666
  3 => [
3667
    {$key2 => 4},
3668
    {$key2 => 5}
3669
  ]
3670
});
3671

            
3672

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3673
test 'DBIx::Custom::Result fetch_multi';
3674
eval { $dbi->execute("drop table $table1") };
3675
$dbi->execute($create_table1);
3676
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3677
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3678
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3679
$result = $dbi->select(table => $table1);
3680
$rows = $result->fetch_multi(2);
3681
is_deeply($rows, [[1, 2], [3, 4]]);
3682
$rows = $result->fetch_multi(2);
3683
is_deeply($rows, [[5, 6]]);
3684
$rows = $result->fetch_multi(2);
3685
ok(!$rows);
3686

            
3687
test 'DBIx::Custom::Result fetch_hash_multi';
3688
eval { $dbi->execute("drop table $table1") };
3689
$dbi->execute($create_table1);
3690
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3691
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3692
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3693
$result = $dbi->select(table => $table1);
3694
$rows = $result->fetch_hash_multi(2);
3695
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3696
$rows = $result->fetch_hash_multi(2);
3697
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3698
$rows = $result->fetch_hash_multi(2);
3699
ok(!$rows);
3700

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3701
test "query_builder";
3702
$datas = [
cleanup
Yuki Kimoto authored on 2012-01-20
3703
  # Basic tests
3704
  {   name            => 'placeholder basic',
3705
    source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
3706
    sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
3707
    columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3708
  },
3709
  {
3710
    name            => 'placeholder in',
3711
    source            => "{in k1 3}",
3712
    sql_expected    => "k1 in (?, ?, ?)",
3713
    columns_expected   => [qw/k1 k1 k1/]
3714
  },
3715
  
3716
  # Table name
3717
  {
3718
    name            => 'placeholder with table name',
3719
    source            => "{= a.k1} {= a.k2}",
3720
    sql_expected    => "a.k1 = ? a.k2 = ?",
3721
    columns_expected  => [qw/a.k1 a.k2/]
3722
  },
3723
  {   
3724
    name            => 'placeholder in with table name',
3725
    source            => "{in a.k1 2} {in b.k2 2}",
3726
    sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
3727
    columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3728
  },
3729
  {
3730
    name            => 'not contain tag',
3731
    source            => "aaa",
3732
    sql_expected    => "aaa",
3733
    columns_expected  => [],
3734
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3735
];
3736

            
3737
for (my $i = 0; $i < @$datas; $i++) {
cleanup
Yuki Kimoto authored on 2012-01-20
3738
  my $data = $datas->[$i];
3739
  my $dbi = DBIx::Custom->new;
3740
  my $builder = $dbi->query_builder;
3741
  my $query = $builder->build_query($data->{source});
3742
  is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3743
  is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3744
}
3745

            
cleanup
Yuki Kimoto authored on 2011-08-13
3746
$dbi = DBIx::Custom->new;
3747
$builder = $dbi->query_builder;
3748
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
3749
  p => sub {
3750
    my @args = @_;
3751
    
3752
    my $expand    = "? $args[0] $args[1]";
3753
    my $columns = [2];
3754
    return [$expand, $columns];
3755
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3756
);
3757

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3768
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3769
  q => 'string'
test cleanup
Yuki Kimoto authored on 2011-08-10
3770
});
3771

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3775
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3776
  r => sub {} 
test cleanup
Yuki Kimoto authored on 2011-08-10
3777
});
3778

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

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

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

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

            
3793

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

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

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

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

            
3809
test 'variouse source';
3810
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3811
$query = $builder->build_query($source);
3812
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3813

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

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

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

            
3826
$source = "a {= b} }";
3827
eval{$builder->build_query($source)};
3828
like($@, qr/unexpected "}"/, "error : 1");
3829

            
3830
$source = "a {= {}";
3831
eval{$builder->build_query($source)};
3832
like($@, qr/unexpected "{"/, "error : 2");
3833

            
3834
test 'select() sqlfilter option';
3835
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3836
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3837
eval { $dbi->execute("drop table $table1") };
3838
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3839
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3840
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3841
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3842
  table => $table1,
3843
  column => $key1,
3844
  sqlfilter => sub {
3845
    my $sql = shift;
3846
    $sql = "select * from ( $sql ) t where $key1 = 1";
3847
    return $sql;
3848
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3849
)->all;
3850
is_deeply($rows, [{$key1 => 1}]);
3851

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3852
test 'select() after_build_sql option';
3853
$dbi = DBIx::Custom->connect;
3854
$dbi->user_table_info($user_table_info);
3855
eval { $dbi->execute("drop table $table1") };
3856
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3857
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3858
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3859
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3860
  table => $table1,
3861
  column => $key1,
3862
  after_build_sql => sub {
3863
    my $sql = shift;
3864
    $sql = "select * from ( $sql ) t where $key1 = 1";
3865
    return $sql;
3866
  }
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3867
)->all;
3868
is_deeply($rows, [{$key1 => 1}]);
3869

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3870
test 'dbi method from model';
3871
$dbi = MyDBI9->connect;
3872
eval { $dbi->execute("drop table $table1") };
3873
$dbi->execute($create_table1);
improved test
Yuki Kimoto authored on 2012-03-01
3874
$dbi->setup_model(@$setup_model_args);
cleanup test
Yuki Kimoto authored on 2011-08-15
3875
$model = $dbi->model($table1);
3876
eval{$model->execute("select * from $table1")};
3877
ok(!$@);
3878

            
3879
test 'column table option';
3880
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3881
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3882
eval { $dbi->execute("drop table $table1") };
3883
$dbi->execute($create_table1);
3884
eval { $dbi->execute("drop table $table2") };
3885
$dbi->execute($create_table2);
improved test
Yuki Kimoto authored on 2012-03-01
3886
$dbi->setup_model(@$setup_model_args);
cleanup test
Yuki Kimoto authored on 2011-08-15
3887
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3888
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3889
$model = $dbi->model($table1);
3890
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3891
  column => [
improved test
Yuki Kimoto authored on 2012-03-01
3892
    $model->column($table2, {alias => u$table2_alias})
cleanup
Yuki Kimoto authored on 2012-01-20
3893
  ],
improved test
Yuki Kimoto authored on 2012-03-01
3894
  where => {u($table2_alias) . ".$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3895
);
3896
is_deeply($result->one, 
improved test
Yuki Kimoto authored on 2012-03-01
3897
        {u($table2_alias) . ".$key1" => 1, u($table2_alias) . ".$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3898

            
3899
$dbi->separator('__');
3900
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3901
  column => [
improved test
Yuki Kimoto authored on 2012-03-01
3902
    $model->column($table2, {alias => u$table2_alias})
cleanup
Yuki Kimoto authored on 2012-01-20
3903
  ],
improved test
Yuki Kimoto authored on 2012-03-01
3904
  where => {u($table2_alias) . ".$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3905
);
3906
is_deeply($result->one, 
improved test
Yuki Kimoto authored on 2012-03-01
3907
  {u(${table2_alias}) . "__$key1" => 1, u(${table2_alias}) . "__$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3908

            
3909
$dbi->separator('-');
3910
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3911
  column => [
improved test
Yuki Kimoto authored on 2012-03-01
3912
    $model->column($table2, {alias => u$table2_alias})
cleanup
Yuki Kimoto authored on 2012-01-20
3913
  ],
improved test
Yuki Kimoto authored on 2012-03-01
3914
  where => {u($table2_alias) . ".$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3915
);
3916
is_deeply($result->one, 
improved test
Yuki Kimoto authored on 2012-03-01
3917
  {u(${table2_alias}) . "-$key1" => 1, u(${table2_alias}) . "-$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3918

            
3919
test 'create_model';
3920
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3921
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3922
eval { $dbi->execute("drop table $table1") };
3923
eval { $dbi->execute("drop table $table2") };
3924
$dbi->execute($create_table1);
3925
$dbi->execute($create_table2);
3926

            
3927
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3928
  table => $table1,
3929
  join => [
3930
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3931
  ],
3932
  primary_key => [$key1]
cleanup test
Yuki Kimoto authored on 2011-08-15
3933
);
3934
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3935
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3936
);
3937
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3938
  table => $table3,
3939
  filter => [
3940
    $key1 => {in => sub { uc $_[0] }}
3941
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
3942
);
improved test
Yuki Kimoto authored on 2012-03-01
3943
$dbi->setup_model(@$setup_model_args);
test cleanup
Yuki Kimoto authored on 2011-11-01
3944
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3945
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3946
$model = $dbi->model($table1);
3947
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3948
  column => [$model->mycolumn, $model->column($table2)],
3949
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-15
3950
);
3951
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3952
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3953
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3954

            
3955
test 'model method';
3956
$dbi = DBIx::Custom->connect;
3957
eval { $dbi->execute("drop table $table2") };
3958
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3959
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3960
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3961
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3962
);
3963
$model->method(foo => sub { shift->select(@_) });
3964
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3965

            
3966
test 'model helper';
3967
$dbi = DBIx::Custom->connect;
3968
eval { $dbi->execute("drop table $table2") };
3969
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3970
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3971
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3972
  table => $table2
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3973
);
3974
$model->helper(foo => sub { shift->select(@_) });
3975
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3976

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

            
3984
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3985
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3986
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3987
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3988
where $key1 = 1
3989
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3990
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3991
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3992
$rows   = $result->all;
3993
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3994
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3995
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
3996

            
3997

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

            
4004
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4005
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
4006
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4007
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
4008
where $key1 = 1
4009
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
4010
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
4011
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
4012
$rows   = $result->all;
4013
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
4014
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
4015
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
4016

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4069
test 'Model class';
4070
$dbi = MyDBI1->connect;
4071
eval { $dbi->execute("drop table $table1") };
4072
$dbi->execute($create_table1);
4073
$model = $dbi->model($table1);
4074
$model->insert({$key1 => 'a', $key2 => 'b'});
4075
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4076
eval { $dbi->execute("drop table $table2") };
4077
$dbi->execute($create_table2);
4078
$model = $dbi->model($table2);
4079
$model->insert({$key1 => 'a'});
4080
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4081
is($dbi->models->{$table1}, $dbi->model($table1));
4082
is($dbi->models->{$table2}, $dbi->model($table2));
4083

            
4084
$dbi = MyDBI4->connect;
4085
eval { $dbi->execute("drop table $table1") };
4086
$dbi->execute($create_table1);
4087
$model = $dbi->model($table1);
4088
$model->insert({$key1 => 'a', $key2 => 'b'});
4089
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4090
eval { $dbi->execute("drop table $table2") };
4091
$dbi->execute($create_table2);
4092
$model = $dbi->model($table2);
4093
$model->insert({$key1 => 'a'});
4094
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4095

            
4096
$dbi = MyDBI5->connect;
4097
eval { $dbi->execute("drop table $table1") };
4098
eval { $dbi->execute("drop table $table2") };
4099
$dbi->execute($create_table1);
4100
$dbi->execute($create_table2);
4101
$model = $dbi->model($table2);
4102
$model->insert({$key1 => 'a'});
4103
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
4104
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4105
$model = $dbi->model($table1);
4106
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
4107

            
4108
test 'primary_key';
4109
$dbi = MyDBI1->connect;
4110
$model = $dbi->model($table1);
4111
$model->primary_key([$key1, $key2]);
4112
is_deeply($model->primary_key, [$key1, $key2]);
4113

            
4114
test 'columns';
4115
$dbi = MyDBI1->connect;
4116
$model = $dbi->model($table1);
4117
$model->columns([$key1, $key2]);
4118
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4119

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4120
test 'setup_model';
4121
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
4122
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4123
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4124
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
4125

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4126
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4127
$dbi->execute($create_table2);
improved test
Yuki Kimoto authored on 2012-03-01
4128
$dbi->setup_model(@$setup_model_args);
cleanup test
Yuki Kimoto authored on 2011-08-15
4129
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
4130
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4131

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4132
test 'each_column';
4133
$dbi = DBIx::Custom->connect;
4134
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4135
eval { $dbi->execute("drop table $table1") };
4136
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4137
eval { $dbi->execute("drop table $table3") };
4138
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4139
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4140

            
4141
$infos = [];
4142
$dbi->each_column(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4143
  my ($self, $table, $column, $cinfo) = @_;
4144
  
4145
  if ($table =~ /^table\d/i) {
4146
     my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
4147
     push @$infos, $info;
4148
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4149
});
4150
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4151
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4152
  [
4153
    [$table1, $key1, $key1],
4154
    [$table1, $key2, $key2],
4155
    [$table2, $key1, $key1],
4156
    [$table2, $key3, $key3]
4157
  ]
4158
  
cleanup test
Yuki Kimoto authored on 2011-08-10
4159
);
cleanup test
Yuki Kimoto authored on 2011-08-16
4160

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4161
test 'each_table';
4162
$dbi = DBIx::Custom->connect;
4163
eval { $dbi->execute("drop table $table1") };
4164
eval { $dbi->execute("drop table $table2") };
4165
$dbi->execute($create_table2);
4166
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4167

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4168
$infos = [];
4169
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4170
  my ($self, $table, $table_info) = @_;
4171
  
4172
  if ($table =~ /^table\d/i) {
4173
    my $info = [$table, $table_info->{TABLE_NAME}];
4174
    push @$infos, $info;
4175
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4176
});
4177
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4178
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4179
  [
4180
    [$table1, $table1],
4181
    [$table2, $table2],
4182
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4183
);
4184

            
cleanup test
Yuki Kimoto authored on 2011-08-16
4185
$dbi = DBIx::Custom->connect;
4186
eval { $dbi->execute("drop table $table1") };
4187
eval { $dbi->execute("drop table $table2") };
4188
$dbi->execute($create_table2);
4189
$dbi->execute($create_table1_type);
4190

            
4191
$infos = [];
4192
$dbi->user_table_info($user_table_info);
4193
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4194
  my ($self, $table, $table_info) = @_;
4195
  
4196
  if ($table =~ /^table\d/i) {
4197
     my $info = [$table, $table_info->{TABLE_NAME}];
4198
     push @$infos, $info;
4199
  }
cleanup test
Yuki Kimoto authored on 2011-08-16
4200
});
4201
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4202
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4203
  [
4204
    [$table1, $table1],
4205
    [$table2, $table2],
4206
    [$table3, $table3],
4207
  ]
cleanup test
Yuki Kimoto authored on 2011-08-16
4208
);
4209

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4210
test 'type_rule into';
4211
eval { $dbi->execute("drop table $table1") };
4212
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4213
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
4214

            
4215

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4216
$dbi = DBIx::Custom->connect;
4217
eval { $dbi->execute("drop table $table1") };
4218
$dbi->execute($create_table1_type);
4219

            
cleanup
Yuki Kimoto authored on 2011-08-16
4220
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4221
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4222
  into1 => {
4223
    $date_typename => sub { '2010-' . $_[0] }
4224
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4225
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4226
$dbi->insert({$key1 => '01-01'}, table => $table1);
4227
$result = $dbi->select(table => $table1);
4228
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4229

            
4230
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4231
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4232
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4233
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4234
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4235
  into1 => [
4236
     [$date_typename, $datetime_typename] => sub {
4237
        my $value = shift;
4238
        $value =~ s/02/03/g;
4239
        return $value;
4240
     }
4241
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
4242
);
4243
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
4244
$result = $dbi->select(table => $table1);
4245
$row = $result->one;
4246
like($row->{$key1}, qr/^2010-01-03/);
4247
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4248

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4249
$dbi = DBIx::Custom->connect;
4250
eval { $dbi->execute("drop table $table1") };
4251
$dbi->execute($create_table1_type);
4252
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4253
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4254
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4255
  into1 => [
4256
    [$date_typename, $datetime_typename] => sub {
4257
      my $value = shift;
4258
      $value =~ s/02/03/g;
4259
      return $value;
4260
    }
4261
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4262
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4263
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
4264
  "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
4265
  {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
4266
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4267
$row = $result->one;
4268
like($row->{$key1}, qr/^2010-01-03/);
4269
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4270

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

            
4294
$dbi = DBIx::Custom->connect;
4295
eval { $dbi->execute("drop table $table1") };
4296
$dbi->execute($create_table1_type);
4297
$dbi->register_filter(convert => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4298
  my $value = shift || '';
4299
  $value =~ s/02/03/;
4300
  return $value;
cleanup test
Yuki Kimoto authored on 2011-08-15
4301
});
cleanup
Yuki Kimoto authored on 2011-08-16
4302
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4303
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4304
  from1 => {
4305
    $date_datatype => 'convert',
4306
  },
4307
  into1 => {
4308
      $date_typename => 'convert',
4309
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4310
);
4311
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
4312
$result = $dbi->select(table => $table1);
4313
like($result->fetch->[0], qr/^2010-03-03/);
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
4314
$result = $dbi->select(column => [$key1, $key1], table => $table1);
4315
$row = $result->fetch;
4316
like($row->[0], qr/^2010-03-03/);
4317
like($row->[1], qr/^2010-03-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4318

            
4319
test 'type_rule and filter order';
4320
$dbi = DBIx::Custom->connect;
4321
eval { $dbi->execute("drop table $table1") };
4322
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4323
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4324
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4325
  into1 => {
4326
    $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4327
  },
4328
  into2 => {
4329
    $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4330
  },
4331
  from1 => {
4332
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4333
  },
4334
  from2 => {
4335
    $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
4336
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4337
);
4338
$dbi->insert({$key1 => '2010-01-03'}, 
cleanup
Yuki Kimoto authored on 2012-01-20
4339
table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
cleanup test
Yuki Kimoto authored on 2011-08-15
4340
$result = $dbi->select(table => $table1);
4341
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4342
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4343

            
4344

            
4345
$dbi = DBIx::Custom->connect;
4346
eval { $dbi->execute("drop table $table1") };
4347
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4348
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4349
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4350
  from1 => {
4351
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4352
  },
4353
  from2 => {
4354
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4355
  },
cleanup test
Yuki Kimoto authored on 2011-08-15
4356
);
4357
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4358
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4359
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4360
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4361
  from1 => {
4362
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4363
  },
4364
  from2 => {
4365
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
4366
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4367
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4368
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4369
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4370

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4371
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
4372
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
4373
eval { $dbi->execute("drop table $table1") };
4374
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4375
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4376
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4377
  from1 => {
4378
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4379
  },
4380
  into1 => {
4381
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4382
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4383
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4384
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4385
$result = $dbi->select(table => $table1, type_rule_off => 1);
4386
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4387

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4388
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4389
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4390
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4391
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4392
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4393
  from1 => {
4394
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4395
  },
4396
  into1 => {
4397
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4398
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4399
);
4400
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4401
$result = $dbi->select(table => $table1, type_rule_off => 1);
4402
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4403

            
4404
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4405
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4406
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4407
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4408
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4409
  from1 => {
4410
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4411
  },
4412
  into1 => {
4413
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4414
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4415
);
4416
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4417
$result = $dbi->select(table => $table1);
4418
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4419

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4450
eval{$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4451
  into1 => {
4452
    $date_typename => 'pp'
4453
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4454
)};
4455
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4456

            
cleanup test
Yuki Kimoto authored on 2011-08-10
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 test
Yuki Kimoto authored on 2011-08-10
4460
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4461
  $dbi->type_rule(
4462
    from1 => {
4463
      Date => sub { $_[0] * 2 },
4464
    }
4465
  );
cleanup test
Yuki Kimoto authored on 2011-08-10
4466
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4467
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4468

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4469
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4470
  $dbi->type_rule(
4471
    into1 => {
4472
      Date => sub { $_[0] * 2 },
4473
    }
4474
  );
cleanup test
Yuki Kimoto authored on 2011-08-15
4475
};
4476
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4477

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

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

            
4516
$result = $dbi->select(table => $table1);
4517
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4518
  from1 => {
4519
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4520
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4521
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4522
$row = $result->one;
4523
like($row->{$key1}, qr/2010-01-05/);
4524
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4525

            
4526
$result = $dbi->select(table => $table1);
4527
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4528
  from1 => {
4529
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4530
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4531
);
4532
$row = $result->one;
4533
like($row->{$key1}, qr/2010-01-05/);
4534
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4535

            
4536
$result = $dbi->select(table => $table1);
4537
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4538
  from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
cleanup test
Yuki Kimoto authored on 2011-08-15
4539
);
4540
$row = $result->one;
4541
like($row->{$key1}, qr/2010-01-05/);
4542
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4543

            
4544
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4545
$result = $dbi->select(table => $table1);
4546
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4547
  from1 => [$date_datatype => 'five']
cleanup test
Yuki Kimoto authored on 2011-08-15
4548
);
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 => [$date_datatype => undef]
cleanup test
Yuki Kimoto authored on 2011-08-15
4556
);
4557
$row = $result->one;
4558
like($row->{$key1}, qr/^2010-01-03/);
4559
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4560

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4589
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4590
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4591
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4592
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4593
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4594
  into1 => {
4595
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4596
  },
4597
  into2 => {
4598
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4599
  },
4600
  from1 => {
4601
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4602
  },
4603
  from2 => {
4604
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4605
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4606
);
4607
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4608
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4609
like($result->type_rule_off->fetch_one->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4610
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4611
like($result->type_rule_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4612

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4613
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4614
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4615
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4616
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4617
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4618
  into1 => {
4619
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4620
  },
4621
  into2 => {
4622
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4623
  },
4624
  from1 => {
4625
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
4626
  },
4627
  from2 => {
4628
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4629
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4630
);
4631
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4632
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4633
like($result->type_rule1_off->fetch_one->[0], qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4634
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4635
like($result->type_rule1_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4636

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4637
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4638
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4639
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4640
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4641
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4642
  into1 => {
4643
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4644
  },
4645
  into2 => {
4646
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4647
  },
4648
  from1 => {
4649
    $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4650
  },
4651
  from2 => {
4652
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4653
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4654
);
4655
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4656
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4657
like($result->type_rule2_off->fetch_one->[0], qr/^2010-01-06/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4658
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4659
like($result->type_rule2_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4660

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4661
test 'join';
4662
$dbi = DBIx::Custom->connect;
4663
eval { $dbi->execute("drop table $table1") };
4664
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4665
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4666
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4667
eval { $dbi->execute("drop table $table2") };
4668
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4669
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4670
eval { $dbi->execute("drop table $table3") };
4671
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4672
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4673
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4674
  table => $table1,
4675
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4676
  where   => {"$table1.$key2" => 2},
4677
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4678
)->all;
4679
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4680

            
4681
$dbi = DBIx::Custom->connect;
4682
eval { $dbi->execute("drop table $table1") };
4683
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4684
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4685
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4686
eval { $dbi->execute("drop table $table2") };
4687
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4688
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4689
eval { $dbi->execute("drop table $table3") };
4690
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4691
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4692
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4693
  table => $table1,
4694
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4695
  where   => {"$table1.$key2" => 2},
4696
  join  => {
4697
    clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4698
    table => [$table1, $table2]
4699
  }
added test
Yuki Kimoto authored on 2011-10-27
4700
)->all;
4701
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
4702

            
4703
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4704
  table => $table1,
4705
  where   => {$key1 => 1},
4706
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4707
)->all;
4708
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4709

            
4710
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4711
  table => $table1,
4712
  where   => {$key1 => 1},
4713
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4714
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4715
)->all;
4716
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4717

            
4718
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4719
  column => "$table3.$key4 as ${table3}__$key4",
4720
  table => $table1,
4721
  where   => {"$table1.$key1" => 1},
4722
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4723
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4724
)->all;
4725
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4726

            
4727
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4728
  column => "$table1.$key1 as ${table1}__$key1",
4729
  table => $table1,
4730
  where   => {"$table3.$key4" => 4},
4731
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4732
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4733
)->all;
4734
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4735

            
4736
$dbi = DBIx::Custom->connect;
4737
eval { $dbi->execute("drop table $table1") };
4738
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4739
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4740
eval { $dbi->execute("drop table $table2") };
4741
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4742
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4743
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4744
  table => $table1,
4745
  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",
4746
  where   => {"$table1.$key2" => 2},
4747
  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
4748
)->all;
4749
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
cleanup
Yuki Kimoto authored on 2012-01-20
4750
  'quote');
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4751

            
4752

            
4753
$dbi = DBIx::Custom->connect;
4754
eval { $dbi->execute("drop table $table1") };
4755
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4756
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4757
$sql = <<"EOS";
4758
left outer join (
cleanup
Yuki Kimoto authored on 2012-01-20
4759
select * from $table1 t1
4760
where t1.$key2 = (
4761
  select max(t2.$key2) from $table1 t2
4762
  where t1.$key1 = t2.$key1
4763
)
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4764
) $table3 on $table1.$key1 = $table3.$key1
4765
EOS
4766
$join = [$sql];
4767
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4768
  table => $table1,
4769
  column => "$table3.$key1 as ${table3}__$key1",
4770
  join  => $join
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4771
)->all;
4772
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4773

            
4774
$dbi = DBIx::Custom->connect;
4775
eval { $dbi->execute("drop table $table1") };
4776
eval { $dbi->execute("drop table $table2") };
4777
$dbi->execute($create_table1);
4778
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4779
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4780
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4781
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4782
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4783
  table => $table1,
4784
  join => [
4785
    "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4786
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4787
);
4788
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4789
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4790
  table => $table1,
4791
  column => [{$table2 => [$key3]}],
4792
  join => [
4793
    "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4794
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4795
);
4796
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4797
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4798
  table => $table1,
4799
  column => [{$table2 => [$key3]}],
4800
  join => [
4801
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4802
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4803
);
4804
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4805

            
4806
$dbi = DBIx::Custom->connect;
4807
eval { $dbi->execute("drop table $table1") };
4808
eval { $dbi->execute("drop table $table2") };
4809
$dbi->execute($create_table1);
4810
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4811
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4812
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4813
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4814
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4815
  table => $table1,
4816
  column => [{$table2 => [$key3]}],
4817
  join => [
4818
    {
4819
      clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4820
      table => [$table1, $table2]
4821
    }
4822
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4823
);
4824
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4825

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4826
$dbi = DBIx::Custom->connect;
4827
eval { $dbi->execute("drop table $table1") };
4828
eval { $dbi->execute("drop table $table2") };
4829
$dbi->execute($create_table1);
4830
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4831
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4832
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4833
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
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 > '3'"
4839
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
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 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4851
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4852
  table => $table1,
4853
  column => [{$table2 => [$key3]}],
4854
  join => [
4855
    "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4856
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4857
);
4858
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4859

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4860
test 'columns';
4861
$dbi = MyDBI1->connect;
4862
$model = $dbi->model($table1);
4863

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4864
test 'count';
4865
$dbi = DBIx::Custom->connect;
4866
eval { $dbi->execute("drop table $table1") };
4867
$dbi->execute($create_table1);
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, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4870
is($dbi->count(table => $table1), 2);
4871
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4872
$model = $dbi->create_model(table => $table1);
4873
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4874

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4875
eval { $dbi->execute("drop table $table1") };
4876
eval { $dbi->execute("drop table $table2") };
4877
$dbi->execute($create_table1);
4878
$dbi->execute($create_table2);
4879
$model = $dbi->create_model(table => $table1, primary_key => $key1);
4880
$model->insert({$key1 => 1, $key2 => 2});
4881
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
4882
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4883
$model->insert({$key1 => 1, $key3 => 3});
4884
is($model->count(id => 1), 1);
4885
is($model->count(where => {"$table2.$key3" => 3}), 1);
4886

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