DBIx-Custom / t / common.t /
Newer Older
4888 lines | 160.442kb
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;
61
my $q = substr($dbi->quote, 0, 1);
62
my $p = substr($dbi->quote, 1, 1) || $q;
63
my $date_typename = $dbi->date_typename;
64
my $datetime_typename = $dbi->datetime_typename;
65
my $date_datatype = $dbi->date_datatype;
66
my $datetime_datatype = $dbi->datetime_datatype;
improved test
Yuki Kimoto authored on 2012-03-01
67
my $setup_model_args = $dbi->can('setup_model_args') ? $dbi->setup_model_args : [];
cleanup test
Yuki Kimoto authored on 2011-08-15
68

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
189
  use base 'MyModel2::Base1';
190

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
691
eval { $dbi->execute("drop table $table1") };
692
$dbi->execute($create_table1_2);
693
$model = $dbi->create_model(table => $table1, created_at => $key2);
694
$param = {$key1 => 1};
695
$model->insert($param);
696
$result = $dbi->select(table => $table1);
697
is_deeply($param, {$key1 => 1});
698
$row   = $result->one;
699
is($row->{$key1}, 1);
700
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
701

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

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

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

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

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

            
761
eval { $dbi->execute("drop table $table1") };
762
$dbi->execute($create_table1_2);
763
$param = {$key1 => 1};
764
$model = $dbi->create_model(table => $table1, ctime=> $key2, updated_at => $key3);
765
$model->insert($param);
766
$result = $dbi->select(table => $table1);
767
is_deeply($param, {$key1 => 1});
768
$row   = $result->one;
769
is($row->{$key1}, 1);
770
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
771
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
772
is($row->{$key2}, $row->{$key3});
773

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1486

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

            
1492
$dbi->begin_work;
1493

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

            
1500
$dbi->rollback if $@;
1501

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

            
1506
$dbi->begin_work;
1507

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

            
1513
$dbi->commit unless $@;
1514

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1790
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1791
$result = $dbi->select(table => $table1);
1792
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1793
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1794
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1795
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1796

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2126

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

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

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

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

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

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

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

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

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

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

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

            
2199
$dbi->apply_filter(
2200

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2486

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2703

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2882

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

            
2898

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

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

            
2919

            
2920
test 'model delete and id option';
2921
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2922
eval { $dbi->execute("drop table $table1") };
2923
eval { $dbi->execute("drop table $table2") };
2924
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2925
$dbi->execute($create_table1_2);
2926
$dbi->execute($create_table2_2);
2927
$dbi->execute($create_table3);
cleanup
Yuki Kimoto authored on 2011-11-01
2928
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2929
$dbi->model($table1)->delete(id => [1, 2]);
2930
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2931
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2932
$dbi->model($table1)->delete(id => [1, 2]);
2933
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2934
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2935
$dbi->model($table3)->delete(id => [1, 2]);
2936
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2937

            
2938

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

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

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

            
2978

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

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

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

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

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

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

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

            
3074

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

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

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

            
3101

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3673

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3794

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3998

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4216

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

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

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

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

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

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

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

            
4345

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

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4458
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4459
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4460
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4461
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4462
  $dbi->type_rule(
4463
    from1 => {
4464
      Date => sub { $_[0] * 2 },
4465
    }
4466
  );
cleanup test
Yuki Kimoto authored on 2011-08-10
4467
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4468
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4469

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

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

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

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

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

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

            
4545
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4546
$result = $dbi->select(table => $table1);
4547
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4548
  from1 => [$date_datatype => 'five']
cleanup test
Yuki Kimoto authored on 2011-08-15
4549
);
4550
$row = $result->one;
4551
like($row->{$key1}, qr/^2010-01-05/);
4552
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4553

            
4554
$result = $dbi->select(table => $table1);
4555
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4556
  from1 => [$date_datatype => undef]
cleanup test
Yuki Kimoto authored on 2011-08-15
4557
);
4558
$row = $result->one;
4559
like($row->{$key1}, qr/^2010-01-03/);
4560
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4561

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

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

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

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

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

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

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

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

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

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

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

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

            
4753

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

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

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

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4827
$dbi = DBIx::Custom->connect;
4828
eval { $dbi->execute("drop table $table1") };
4829
eval { $dbi->execute("drop table $table2") };
4830
$dbi->execute($create_table1);
4831
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4832
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4833
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4834
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4835
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4836
  table => $table1,
4837
  column => [{$table2 => [$key3]}],
4838
  join => [
4839
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4840
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4841
);
4842
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4843

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4865
test 'count';
4866
$dbi = DBIx::Custom->connect;
4867
eval { $dbi->execute("drop table $table1") };
4868
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4869
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4870
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4871
is($dbi->count(table => $table1), 2);
4872
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4873
$model = $dbi->create_model(table => $table1);
4874
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4875

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

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