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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
26
# Constant
27
my $table1 = $dbi->table1;
28
my $table2 = $dbi->table2;
29
my $table2_alias = $dbi->table2_alias;
30
my $table3 = $dbi->table3;
31
my $key1 = $dbi->key1;
32
my $key2 = $dbi->key2;
33
my $key3 = $dbi->key3;
34
my $key4 = $dbi->key4;
35
my $key5 = $dbi->key5;
36
my $key6 = $dbi->key6;
37
my $key7 = $dbi->key7;
38
my $key8 = $dbi->key8;
39
my $key9 = $dbi->key9;
40
my $key10 = $dbi->key10;
41
my $create_table1 = $dbi->create_table1;
42
my $create_table1_2 = $dbi->create_table1_2;
43
my $create_table1_type = $dbi->create_table1_type;
44
my $create_table1_highperformance = $dbi->create_table1_highperformance;
45
my $create_table2 = $dbi->create_table2;
46
my $create_table2_2 = $dbi->create_table2_2;
47
my $create_table3 = $dbi->create_table3;
48
my $create_table_reserved = $dbi->create_table_reserved;
49
my $q = substr($dbi->quote, 0, 1);
50
my $p = substr($dbi->quote, 1, 1) || $q;
51
my $date_typename = $dbi->date_typename;
52
my $datetime_typename = $dbi->datetime_typename;
53
my $date_datatype = $dbi->date_datatype;
54
my $datetime_datatype = $dbi->datetime_datatype;
55

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

            
test cleanup
Yuki Kimoto authored on 2011-08-15
99
require MyDBI1;
test cleanup
Yuki Kimoto authored on 2011-08-10
100
{
cleanup
Yuki Kimoto authored on 2012-01-20
101
  package MyDBI4;
test cleanup
Yuki Kimoto authored on 2011-08-10
102

            
cleanup
Yuki Kimoto authored on 2012-01-20
103
  use strict;
104
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
105

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
108
  sub connect {
109
    my $self = shift->SUPER::connect(@_);
110
    
111
    $self->include_model(
112
      MyModel2 => [
113
          $table1,
114
          {class => $table2, name => $table2}
115
      ]
116
    );
117
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
118

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
133
  sub insert {
134
    my ($self, $param) = @_;
135
    
136
    return $self->SUPER::insert($param);
137
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
138

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
143
  use strict;
144
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-15
145

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
173
  use strict;
174
  use warnings;
175

            
176
  use base 'MyModel2::Base1';
177

            
178
  sub insert {
179
    my ($self, $param) = @_;
180
    
181
    return $self->SUPER::insert($param);
182
  }
183

            
184
  sub list { shift->select; }
test cleanup
Yuki Kimoto authored on 2011-08-10
185
}
186
{
cleanup
Yuki Kimoto authored on 2012-01-20
187
   package MyDBI5;
test cleanup
Yuki Kimoto authored on 2011-08-10
188

            
cleanup
Yuki Kimoto authored on 2012-01-20
189
  use strict;
190
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
191

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
194
  sub connect {
195
    my $self = shift->SUPER::connect(@_);
196
    
197
    $self->include_model('MyModel4');
198
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
199
}
200
{
cleanup
Yuki Kimoto authored on 2012-01-20
201
  package MyDBI6;
202
  
203
  use base 'DBIx::Custom';
204
  
205
  sub connect {
206
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
207
    
cleanup
Yuki Kimoto authored on 2012-01-20
208
    $self->include_model('MyModel5');
test cleanup
Yuki Kimoto authored on 2011-08-10
209
    
cleanup
Yuki Kimoto authored on 2012-01-20
210
    return $self;
211
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
212
}
213
{
cleanup
Yuki Kimoto authored on 2012-01-20
214
  package MyDBI7;
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('MyModel6');
test cleanup
Yuki Kimoto authored on 2011-08-10
222
    
cleanup
Yuki Kimoto authored on 2012-01-20
223
    
224
    return $self;
225
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
226
}
227
{
cleanup
Yuki Kimoto authored on 2012-01-20
228
  package MyDBI8;
229
  
230
  use base 'DBIx::Custom';
231
  
232
  sub connect {
233
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
234
    
cleanup
Yuki Kimoto authored on 2012-01-20
235
    $self->include_model('MyModel7');
test cleanup
Yuki Kimoto authored on 2011-08-10
236
    
cleanup
Yuki Kimoto authored on 2012-01-20
237
    return $self;
238
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
239
}
240

            
241
{
cleanup
Yuki Kimoto authored on 2012-01-20
242
  package MyDBI9;
243
  
244
  use base 'DBIx::Custom';
245
  
246
  sub connect {
247
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
248
    
cleanup
Yuki Kimoto authored on 2012-01-20
249
    $self->include_model('MyModel8');
test cleanup
Yuki Kimoto authored on 2011-08-10
250
    
cleanup
Yuki Kimoto authored on 2012-01-20
251
    return $self;
252
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
253
}
254

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
255
test 'execute reuse option';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
256
eval { $dbi->execute("drop table $table1") };
257
$dbi->execute($create_table1);
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
258
$reuse = {};
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
259
for my $i (1 .. 2) {
cleanup
Yuki Kimoto authored on 2012-01-20
260
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, reuse => $reuse);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
261
}
262
$rows = $dbi->select(table => $table1)->all;
263
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-11-18
264
ok(keys %$reuse);
265
ok((keys %$reuse)[0] !~ /\?/);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
266

            
added test
Yuki Kimoto authored on 2011-08-16
267
# Get user table info
268
$dbi = DBIx::Custom->connect;
269
eval { $dbi->execute("drop table $table1") };
270
eval { $dbi->execute("drop table $table2") };
271
eval { $dbi->execute("drop table $table3") };
272
$dbi->execute($create_table1);
273
$dbi->execute($create_table2);
274
$dbi->execute($create_table3);
275
$user_table_info = $dbi->get_table_info(exclude => $dbi->exclude_table);
276

            
cleanup test
Yuki Kimoto authored on 2011-08-15
277
# Create table
test cleanup
Yuki Kimoto authored on 2011-08-10
278
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
279
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
280
$dbi->execute($create_table1);
281
$model = $dbi->create_model(table => $table1);
282
$model->insert({$key1 => 1, $key2 => 2});
283
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-08-15
284

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
285
eval { $dbi->execute("drop table $table1") };
286
$dbi->execute($create_table1);
287
$model = $dbi->create_model(table => $table1);
288
$model->insert({$key1 => 1, $key2 => 2});
289
is_deeply($model->select($key1)->all, [{$key1 => 1}]);
290

            
cleanup test
Yuki Kimoto authored on 2011-08-15
291
test 'DBIx::Custom::Result test';
292
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
293
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
294
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
295
$source = "select $key1, $key2 from $table1";
296
$query = $dbi->create_query($source);
297
$result = $dbi->execute($query);
cleanup
Yuki Kimoto authored on 2011-08-15
298

            
cleanup test
Yuki Kimoto authored on 2011-08-15
299
@rows = ();
300
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
301
  push @rows, [@$row];
cleanup test
Yuki Kimoto authored on 2011-08-15
302
}
303
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
cleanup
Yuki Kimoto authored on 2011-08-15
304

            
cleanup test
Yuki Kimoto authored on 2011-08-15
305
$result = $dbi->execute($query);
306
@rows = ();
307
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
308
  push @rows, {%$row};
cleanup test
Yuki Kimoto authored on 2011-08-15
309
}
310
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
311

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
325
test 'Insert query return value';
326
$source = "insert into $table1 {insert_param $key1 $key2}";
327
$query = $dbi->execute($source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
328
$ret_val = $dbi->execute($query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
329
ok($ret_val);
test cleanup
Yuki Kimoto authored on 2011-08-10
330

            
cleanup test
Yuki Kimoto authored on 2011-08-15
331
test 'Direct query';
332
$dbi->delete_all(table => $table1);
333
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
test cleanup
Yuki Kimoto authored on 2011-11-01
334
$dbi->execute($insert_source, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
335
$result = $dbi->execute("select * from $table1");
336
$rows = $result->all;
337
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
338

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

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

            
352
test 'Filter in';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
353
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
354
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
355
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
356
$dbi->execute($insert_query, {$key1 => 2, $key2 => 4});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
357
$select_source = "select * from $table1 where {in $table1.$key1 2} and {in $table1.$key2 2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
358
$select_query = $dbi->execute($select_source,{}, query => 1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
359
$select_query->filter({"$table1.$key1" => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
360
$result = $dbi->execute($select_query, {"$table1.$key1" => [1,5], "$table1.$key2" => [2,4]});
cleanup test
Yuki Kimoto authored on 2011-08-08
361
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
362
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
363

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
415
$update_source = "update $table1 {update_param $key1 $key2 $key3 $key4} where {= $key5}";
test cleanup
Yuki Kimoto authored on 2011-11-01
416
$dbi->execute($update_source, {$key1 => 1, $key2 => 1, $key3 => 1, $key4 => 1, $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 order by $key1");
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 => 1, $key3 => 1, $key4 => 1, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
421
                {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-08
422

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
444
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
445
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
446
  $source,
447
  {"$table1.$key1" => 1, "$table1.$key2" => 1},
448
  filter => {"$table1.$key2" => sub { $_[0] * 2 }}
cleanup test
Yuki Kimoto authored on 2011-08-08
449
);
450
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
451
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
452

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
453
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
454
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
455
$dbi->insert({$key1 => '2011-10-14 12:19:18', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
456
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
457
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
458
  $source,
459
  {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
460
);
461

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
466
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
467
$dbi->insert({$key1 => 'a:b c:d', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
468
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
469
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
470
  $source,
471
  {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
472
);
473
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
474
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
475

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
483
test 'insert';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
484
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
485
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
486
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
487
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
488
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
489
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
490
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
491

            
added tests
Yuki Kimoto authored on 2011-11-01
492
eval { $dbi->execute("drop table $table1") };
493
$dbi->execute($create_table1);
494
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
495
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
496
$result = $dbi->execute("select * from $table1");
497
$rows   = $result->all;
498
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
499

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
500
$dbi->execute("delete from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
501
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
502
  twice       => sub { $_[0] * 2 },
503
  three_times => sub { $_[0] * 3 }
cleanup test
Yuki Kimoto authored on 2011-08-10
504
);
505
$dbi->default_bind_filter('twice');
test cleanup
Yuki Kimoto authored on 2011-11-01
506
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
cleanup test
Yuki Kimoto authored on 2011-08-15
507
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
508
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
509
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
510
$dbi->delete_all(table => $table1);
511
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
512
$result = $dbi->execute("select * from $table1");
513
$rows   = $result->all;
514
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-10
515
$dbi->default_bind_filter(undef);
516

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
527
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
528
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
529
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
test cleanup
Yuki Kimoto authored on 2011-11-01
530
$dbi->insert({select => 1}, table => 'table');
cleanup test
Yuki Kimoto authored on 2011-08-10
531
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
532
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
533
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
cleanup test
Yuki Kimoto authored on 2011-08-10
534

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

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

            
updated pod
Yuki Kimoto authored on 2011-09-02
551
eval { $dbi->execute("drop table $table1") };
552
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
553
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
554
wrap => {$key1 => sub { "$_[0] - 1" }});
test cleanup
Yuki Kimoto authored on 2011-11-01
555
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
updated pod
Yuki Kimoto authored on 2011-09-02
556
$result = $dbi->execute("select * from $table1");
557
$rows   = $result->all;
558
is_deeply($rows, [{$key1 => 0, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
559

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
560
eval { $dbi->execute("drop table $table1") };
561
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
562
$dbi->insert_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
563
  $key1 => '5'
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
564
);
test cleanup
Yuki Kimoto authored on 2011-11-01
565
$dbi->insert({$key2 => 2}, table => $table1, timestamp => 1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
566
$result = $dbi->execute("select * from $table1");
567
$rows   = $result->all;
568
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
569

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

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

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
590
eval { $dbi->execute("drop table $table1") };
591
$dbi->execute($create_table1_2);
592
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
593
$dbi->insert($param, table => $table1, created_at => $key2);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
594
$result = $dbi->select(table => $table1);
595
is_deeply($param, {$key1 => 1});
596
$row   = $result->one;
597
is($row->{$key1}, 1);
598
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
599

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
600
eval { $dbi->execute("drop table $table1") };
601
$dbi->execute($create_table1_2);
602
$param = {$key1 => 1};
603
$dbi->insert($param, table => $table1, ctime => $key2);
604
$result = $dbi->select(table => $table1);
605
is_deeply($param, {$key1 => 1});
606
$row   = $result->one;
607
is($row->{$key1}, 1);
608
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
609

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
610
eval { $dbi->execute("drop table $table1") };
611
$dbi->execute($create_table1_2);
612
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
613
$dbi->insert($param, table => $table1, updated_at => $key3);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
614
$result = $dbi->select(table => $table1);
615
is_deeply($param, {$key1 => 1});
616
$row   = $result->one;
617
is($row->{$key1}, 1);
618
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
619

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
620
eval { $dbi->execute("drop table $table1") };
621
$dbi->execute($create_table1_2);
622
$param = {$key1 => 1};
623
$dbi->insert($param, table => $table1, mtime => $key3);
624
$result = $dbi->select(table => $table1);
625
is_deeply($param, {$key1 => 1});
626
$row   = $result->one;
627
is($row->{$key1}, 1);
628
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
629

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
630
eval { $dbi->execute("drop table $table1") };
631
$dbi->execute($create_table1_2);
632
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
633
$dbi->insert($param, table => $table1, created_at => $key2, updated_at => $key3);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
634
$result = $dbi->select(table => $table1);
635
is_deeply($param, {$key1 => 1});
636
$row   = $result->one;
637
is($row->{$key1}, 1);
638
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
639
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
640
is($row->{$key2}, $row->{$key3});
641

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
642
eval { $dbi->execute("drop table $table1") };
643
$dbi->execute($create_table1_2);
644
$param = {$key1 => 1};
645
$dbi->insert($param, table => $table1, created_at => $key2, mtime => $key3);
646
$result = $dbi->select(table => $table1);
647
is_deeply($param, {$key1 => 1});
648
$row   = $result->one;
649
is($row->{$key1}, 1);
650
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
651
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
652
is($row->{$key2}, $row->{$key3});
653

            
654
eval { $dbi->execute("drop table $table1") };
655
$dbi->execute($create_table1_2);
656
$param = {$key1 => 1};
657
$dbi->insert($param, table => $table1, ctime => $key2, updated_at => $key3);
658
$result = $dbi->select(table => $table1);
659
is_deeply($param, {$key1 => 1});
660
$row   = $result->one;
661
is($row->{$key1}, 1);
662
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
663
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
664
is($row->{$key2}, $row->{$key3});
665

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

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
700
eval { $dbi->execute("drop table $table1") };
701
$dbi->execute($create_table1_2);
702
$param = {$key1 => 1};
703
$model = $dbi->create_model(table => $table1, updated_at => $key3);
704
$model->insert($param);
705
$result = $dbi->select(table => $table1);
706
is_deeply($param, {$key1 => 1});
707
$row   = $result->one;
708
is($row->{$key1}, 1);
709
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
710

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

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

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
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, mtime => $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

            
748
eval { $dbi->execute("drop table $table1") };
749
$dbi->execute($create_table1_2);
750
$param = {$key1 => 1};
751
$model = $dbi->create_model(table => $table1, ctime=> $key2, updated_at => $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, mtime => $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

            
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
774
eval { $dbi->execute("drop table $table1") };
775
$dbi->execute($create_table1);
776
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] , table => $table1);
777
$result = $dbi->execute("select * from $table1");
778
$rows   = $result->all;
779
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
780

            
781
eval { $dbi->execute("drop table $table1") };
782
$dbi->execute($create_table1_2);
783
$dbi->insert([{$key1 => 1}, {$key1 => 3}] ,
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
784
  table => $table1,
785
  updated_at => $key2,
786
  created_at => $key3
787
);
788
$result = $dbi->execute("select * from $table1");
789
$rows   = $result->all;
790
is($rows->[0]->{$key1}, 1);
791
is($rows->[1]->{$key1}, 3);
792
like($rows->[0]->{$key2}, qr/\d{2}:/);
793
like($rows->[1]->{$key2}, qr/\d{2}:/);
794
like($rows->[0]->{$key3}, qr/\d{2}:/);
795
like($rows->[1]->{$key3}, qr/\d{2}:/);
796

            
797
eval { $dbi->execute("drop table $table1") };
798
$dbi->execute($create_table1_2);
799
$dbi->insert([{$key1 => 1}, {$key1 => 3}] ,
800
  table => $table1,
801
  mtime => $key2,
802
  ctime => $key3
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
803
);
804
$result = $dbi->execute("select * from $table1");
805
$rows   = $result->all;
806
is($rows->[0]->{$key1}, 1);
807
is($rows->[1]->{$key1}, 3);
808
like($rows->[0]->{$key2}, qr/\d{2}:/);
809
like($rows->[1]->{$key2}, qr/\d{2}:/);
810
like($rows->[0]->{$key3}, qr/\d{2}:/);
811
like($rows->[1]->{$key3}, qr/\d{2}:/);
812

            
813
eval { $dbi->execute("drop table $table1") };
814
$dbi->execute($create_table1);
815
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] ,
cleanup
Yuki Kimoto authored on 2012-01-20
816
table => $table1, filter => {$key1 => sub { $_[0] * 2 }});
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
817
$result = $dbi->execute("select * from $table1");
818
$rows   = $result->all;
819
is_deeply($rows, [{$key1 => 2, $key2 => 2}, {$key1 => 6, $key2 => 4}], "basic");
820

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
821
test 'update_or_insert';
822
eval { $dbi->execute("drop table $table1") };
823
$dbi->execute($create_table1);
824
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
825
  {$key2 => 2},
826
  table => $table1,
827
  primary_key => $key1,
828
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
829
);
830
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
831
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
832

            
833
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
834
  {$key2 => 3},
835
  table => $table1,
836
  primary_key => $key1,
837
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
838
);
839
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
840
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
841

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
842
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
843
  $dbi->update_or_insert(
844
    {$key2 => 3},
845
    table => $table1,
846
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
847
};
848

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
851
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
852
  $dbi->insert({$key1 => 1}, table => $table1);
853
  $dbi->update_or_insert(
854
    {$key2 => 3},
855
    table => $table1,
856
    primary_key => $key1,
857
    id => 1
858
  );
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
859
};
860
like($@, qr/one/);
861

            
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
862
eval { $dbi->execute("drop table $table1") };
863
$dbi->execute($create_table1);
864
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
865
  {},
866
  table => $table1,
867
  primary_key => $key1,
868
  id => 1
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
869
);
870
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
871
is($row->{$key1}, 1);
872

            
873
eval { 
cleanup
Yuki Kimoto authored on 2012-01-20
874
  $affected = $dbi->update_or_insert(
875
    {},
876
    table => $table1,
877
    primary_key => $key1,
878
    id => 1
879
  );
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
880
};
881
is($affected, 0);
882

            
micro optimization
Yuki Kimoto authored on 2011-10-31
883
test 'model update_or_insert';
884
eval { $dbi->execute("drop table $table1") };
885
$dbi->execute($create_table1);
886
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
887
  table => $table1,
888
  primary_key => $key1
micro optimization
Yuki Kimoto authored on 2011-10-31
889
);
890
$model->update_or_insert({$key2 => 2}, id => 1);
891
$row = $model->select(id => 1)->one;
892
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
893

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
894
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
895
  $model->insert({$key1 => 1});
896
  $model->update_or_insert(
897
    {$key2 => 3},
898
    id => 1
899
  );
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
900
};
901
like($@, qr/one/);
902

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
903
test 'default_bind_filter';
904
$dbi->execute("delete from $table1");
905
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
906
  twice       => sub { $_[0] * 2 },
907
  three_times => sub { $_[0] * 3 }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
908
);
909
$dbi->default_bind_filter('twice');
cleanup
Yuki Kimoto authored on 2011-11-01
910
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
911
$result = $dbi->execute("select * from $table1");
912
$rows   = $result->all;
913
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
914
$dbi->default_bind_filter(undef);
915

            
test cleanup
Yuki Kimoto authored on 2011-08-10
916
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
917
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
918
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
919
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
920
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
921
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
922
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
923
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
924
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
925
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
926
  "basic");
added tests
Yuki Kimoto authored on 2011-11-01
927

            
928
eval { $dbi->execute("drop table $table1") };
929
$dbi->execute($create_table1_2);
930
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
931
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
932
$dbi->update(param => {$key2 => 11}, table => $table1, where => {$key1 => 1});
933
$result = $dbi->execute("select * from $table1 order by $key1");
934
$rows   = $result->all;
935
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
936
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
937
  "basic");
938
                
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
939
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
940
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
941
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
942
$dbi->update({$key2 => 12}, table => $table1, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
943
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
944
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
945
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
946
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
947
  "update key same as search key");
test cleanup
Yuki Kimoto authored on 2011-08-10
948

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
956
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
957
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
958
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
959
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
960
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
961
            filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
962
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
963
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
964
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
965
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
966
  "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
967

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
973
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
974
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
975
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
976
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
977
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
978
$where->param({$key1 => 1, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
979
$dbi->update({$key1 => 3}, table => $table1, where => $where);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
980
$result = $dbi->select(table => $table1);
981
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
982

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

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1013
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1014
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1015
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1016
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
1017
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
1018
$dbi->insert({select => 1}, table => 'table');
1019
$dbi->update({update => 2}, table => 'table', where => {select => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1020
$result = $dbi->execute("select * from ${q}table$p");
1021
$rows   = $result->all;
1022
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
1023

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

            
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 => {'table.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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1037
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1038
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1039
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1040
$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
1041
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1042
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1043
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1044
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1045
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1046
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1047

            
updated pod
Yuki Kimoto authored on 2011-09-02
1048
eval { $dbi->execute("drop table $table1") };
1049
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1050
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1051
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1052
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
updated pod
Yuki Kimoto authored on 2011-09-02
1053
wrap => {$key2 => sub { "$_[0] - 1" }});
1054
$result = $dbi->execute("select * from $table1 order by $key1");
1055
$rows   = $result->all;
1056
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1057
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1058
  "basic");
updated pod
Yuki Kimoto authored on 2011-09-02
1059

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1060
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1061
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1062
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1063
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1064
$dbi->update({$key2 => \"'11'"}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1065
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1066
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1067
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1068
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1069
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1070

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1071
eval { $dbi->execute("drop table $table1") };
1072
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1073
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
1074
  $key1 => '5'
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1075
);
test cleanup
Yuki Kimoto authored on 2011-11-01
1076
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1077
$dbi->update(table => $table1, timestamp => 1, where => {$key2 => 2});
1078
$result = $dbi->execute("select * from $table1");
1079
$rows   = $result->all;
1080
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
1081

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

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

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

            
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 => {$key2 => 2});
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

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1130
eval { $dbi->execute("drop table $table1") };
1131
$dbi->execute($create_table1_2);
1132
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1133
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1134
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key1 => 1});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1135
$result = $dbi->select(table => $table1);
1136
is_deeply($param, {$key3 => 4});
1137
$row   = $result->one;
1138
is($row->{$key3}, 4);
1139
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1140

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1141
eval { $dbi->execute("drop table $table1") };
1142
$dbi->execute($create_table1_2);
1143
$param = {$key3 => 4};
1144
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1145
$dbi->update($param, table => $table1, mtime => $key2, where => {$key1 => 1});
1146
$result = $dbi->select(table => $table1);
1147
is_deeply($param, {$key3 => 4});
1148
$row   = $result->one;
1149
is($row->{$key3}, 4);
1150
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1151

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1152
eval { $dbi->execute("drop table $table1") };
1153
$dbi->execute($create_table1_2);
1154
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1155
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1156
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key3 => 3});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1157
$result = $dbi->select(table => $table1);
1158
is_deeply($param, {$key3 => 4});
1159
$row   = $result->one;
1160
is($row->{$key3}, 4);
1161
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1162

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1163
eval { $dbi->execute("drop table $table1") };
1164
$dbi->execute($create_table1_2);
1165
$param = {$key3 => 4};
1166
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1167
$dbi->update($param, table => $table1, mtime => $key2, where => {$key3 => 3});
1168
$result = $dbi->select(table => $table1);
1169
is_deeply($param, {$key3 => 4});
1170
$row   = $result->one;
1171
is($row->{$key3}, 4);
1172
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1173

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
1174
eval { $dbi->execute("drop table $table1") };
1175
$dbi->execute($create_table1_2);
1176
$model = $dbi->create_model(table => $table1, updated_at => $key2);
1177
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1178
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
1179
$model->update($param, where => {$key1 => 1});
1180
$result = $dbi->select(table => $table1);
1181
is_deeply($param, {$key3 => 4});
1182
$row   = $result->one;
1183
is($row->{$key3}, 4);
1184
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1185

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1198
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1199
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1200
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1201
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1202
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1203
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
1204
$dbi->update_all({$key2 => 10}, table => $table1, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1205
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1206
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1207
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1208
  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
1209
  "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1210

            
1211
test 'delete';
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);
test cleanup
Yuki Kimoto authored on 2011-11-01
1214
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1215
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1216
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1217
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1218
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1219
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1220

            
cleanup test
Yuki Kimoto authored on 2011-08-15
1221
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
1222
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1223
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1224
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1225
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1226
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1227
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1228
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1229

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1232
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1233
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1234
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1235
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
1236
$rows = $dbi->select(table => $table1)->all;
1237
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1238

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1239
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1240
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1241
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1242
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1243
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1244
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1245
$where->param({ke1 => 1, $key2 => 2});
1246
$dbi->delete(table => $table1, where => $where);
1247
$result = $dbi->select(table => $table1);
1248
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1249

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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1281
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
1282
$dbi = DBIx::Custom->connect;
1283
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1284
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1285
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1286
$dbi->insert({select => 1}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1287
$dbi->delete(table => 'table', where => {select => 1});
1288
$result = $dbi->execute("select * from ${q}table$p");
1289
$rows   = $result->all;
1290
is_deeply($rows, [], "reserved word");
1291

            
1292
test 'delete_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1293
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1294
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1295
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1296
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1297
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1298
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1299
$rows   = $result->all;
1300
is_deeply($rows, [], "basic");
1301

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1325
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1326
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
1327
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
1328
$DB::single = 1;
test cleanup
Yuki Kimoto authored on 2011-08-10
1329
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1330
  table => [$table1, $table2],
fixed test
Yuki Kimoto authored on 2012-03-01
1331
  column => "$table1.$key1 as " . u("${table1}_$key1")
1332
    . ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
1333
  where   => {"$table1.$key2" => 2},
1334
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1335
)->all;
fixed test
Yuki Kimoto authored on 2012-03-01
1336
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
1337

            
1338
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1339
  table => [$table1, $table2],
fixed test
Yuki Kimoto authored on 2012-03-01
1340
  column => ["$table1.$key1 as " . u("${table1}_$key1") . ", ${table2}.$key1 as " . u("${table2}_$key1"), $key2, $key3],
cleanup
Yuki Kimoto authored on 2012-01-20
1341
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1342
)->all;
fixed test
Yuki Kimoto authored on 2012-03-01
1343
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
1344

            
1345
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
1346
eval { $dbi->execute("drop table ${q}table$p") };
1347
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1348
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1349
$dbi->insert({select => 1, update => 2}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1350
$result = $dbi->select(table => 'table', where => {select => 1});
1351
$rows   = $result->all;
1352
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
1353

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
1354
eval { $dbi->execute("drop table $table1") };
1355
$dbi->execute($create_table1);
1356
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1357
$row = $dbi->select($key1, table => $table1)->one;
1358
is_deeply($row, {$key1 => 1});
1359

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

            
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
1363
eval { $dbi->execute("drop table $table1") };
1364
$dbi->execute($create_table1);
1365
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1366
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
1367
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
1368

            
1369
$rows = $dbi->select(table => $table1, where => {$key1 => [1, 5]})->all;
1370
is_deeply($rows, [
1371
  {$key1 => 1, $key2 => 2},
1372
  {$key1 => 5, $key2 => 6}
1373
], "table");
1374

            
1375
$rows = $dbi->select(table => $table1, where => {$key1 => []})->all;
1376
is_deeply($rows, [], "table");
1377

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1378
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1379
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1380
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1381
  twice       => sub { $_[0] * 2 },
1382
  three_times => sub { $_[0] * 3 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1383
);
1384
$dbi->default_fetch_filter('twice');
1385
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1386
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1387
$result = $dbi->select(table => $table1);
1388
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1389
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1390
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1391

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1392
$dbi->default_fetch_filter('twice');
1393
eval { $dbi->execute("drop table $table1") };
1394
$dbi->execute($create_table1);
1395
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1396
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1397
$result->filter({$key1 => 'three_times'});
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1398
$row = $result->fetch_one;
1399
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter");
1400

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1407
test 'filters';
1408
$dbi = DBIx::Custom->new;
1409

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1416
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1417
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1418
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1419
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1420
$dbi->begin_work;
1421
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1422
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1423
$dbi->rollback;
1424
$dbi->dbh->{AutoCommit} = 1;
1425

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

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

            
1430
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1431
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1432
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1433
$dbi->begin_work;
1434
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1435
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1436
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1437
$dbi->commit;
1438
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1439
$result = $dbi->select(table => $table1);
1440
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
cleanup
Yuki Kimoto authored on 2012-01-20
1441
  "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1442

            
1443
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1444
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1445
$dbi->execute($create_table1);
1446
{
cleanup
Yuki Kimoto authored on 2012-01-20
1447
  local $Carp::Verbose = 0;
1448
  eval{$dbi->execute("select * frm $table1")};
1449
  like($@, qr/\Qselect * frm $table1/, "fail prepare");
1450
  like($@, qr/\.t /, "fail : not verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1451
}
1452
{
cleanup
Yuki Kimoto authored on 2012-01-20
1453
  local $Carp::Verbose = 1;
1454
  eval{$dbi->execute("select * frm $table1")};
1455
  like($@, qr/Custom.*\.t /s, "fail : verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1456
}
1457

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

            
1463
{
cleanup
Yuki Kimoto authored on 2012-01-20
1464
  local $Carp::Verbose = 0;
1465
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1466
  like($@, qr/\Q.t /, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1467
}
1468
{
cleanup
Yuki Kimoto authored on 2012-01-20
1469
  local $Carp::Verbose = 1;
1470
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1471
  like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1472
}
1473

            
1474

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1475
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1476
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1477
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1478
$dbi->execute($create_table1);
1479

            
1480
$dbi->begin_work;
1481

            
1482
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1483
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1484
  die "Error";
1485
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1486
};
1487

            
1488
$dbi->rollback if $@;
1489

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

            
1494
$dbi->begin_work;
1495

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

            
1501
$dbi->commit unless $@;
1502

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

            
1507
$dbi->dbh->{AutoCommit} = 0;
1508
eval{ $dbi->begin_work };
1509
ok($@, "exception");
1510
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1511

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1512
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1513
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1514
$dbi->cache(1);
1515
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1516
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1517
$dbi->execute($source, {}, query => 1);
1518
is_deeply($dbi->{_cached}->{$source}, 
cleanup
Yuki Kimoto authored on 2012-01-20
1519
  {sql => " select * from $table1 where $key1 = ?  and $key2 = ? ", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1520

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1521
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1522
$dbi->execute($create_table1);
1523
$dbi->{_cached} = {};
1524
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1525
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1526
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1527

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

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

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

            
1559
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1560
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1561
  one => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1562
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1563
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1564
  two => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1565
);
1566
$dbi->method({
cleanup
Yuki Kimoto authored on 2012-01-20
1567
  twice => sub {
1568
    my $self = shift;
1569
    return $_[0] * 2;
1570
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
1571
});
1572

            
1573
is($dbi->one, 1, "first");
1574
is($dbi->two, 2, "second");
1575
is($dbi->twice(5), 10 , "second");
1576

            
1577
eval {$dbi->XXXXXX};
1578
ok($@, "not exists");
1579

            
1580
test 'out filter';
1581
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1582
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1583
$dbi->execute($create_table1);
1584
$dbi->register_filter(twice => sub { $_[0] * 2 });
1585
$dbi->register_filter(three_times => sub { $_[0] * 3});
1586
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1587
  $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1588
            $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
1589
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1590
$result = $dbi->execute("select * from $table1");
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1591
$row   = $result->fetch_hash_one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1592
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1593
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1594
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1595
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1596

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1602
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1603
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1604
$dbi->execute($create_table1);
1605
$dbi->register_filter(twice => sub { $_[0] * 2 });
1606
$dbi->register_filter(three_times => sub { $_[0] * 3});
1607
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1608
  $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1609
            $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1610
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1611
  $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1612
); 
test cleanup
Yuki Kimoto authored on 2011-11-01
1613
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1614
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1615
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1616
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1617

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

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

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

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

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

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

            
1704
$result->filter({$key2 => 'twice'});
1705
$rows   = $result->all;
1706
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1707

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

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

            
1717
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1718
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1719
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1720
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1721
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1722
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1723

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

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

            
1737
test 'end_filter';
1738
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1739
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1740
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1741
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1742
$result = $dbi->select(table => $table1);
1743
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1744
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1745
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1746
is_deeply($row, [6, 40]);
1747

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1758
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1759
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1760
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1761
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1762
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1763
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1764
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1765
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1766
is_deeply($row, [6, 12]);
1767

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

            
1778
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1779
$result = $dbi->select(table => $table1);
1780
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1781
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1782
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1783
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1784

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

            
1795
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1796
$dbi->apply_filter($table1,
cleanup
Yuki Kimoto authored on 2012-01-20
1797
  $key1 => {end => sub { $_[0] * 3 } },
1798
  $key2 => {end => 'five_times'}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1799
);
1800
$result = $dbi->select(table => $table1);
1801
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1802
$result->filter($key1 => undef);
1803
$result->end_filter($key1 => undef);
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 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1806

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1807
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1808
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1809
$result->filter($key1 => undef);
1810
$result->end_filter($key1 => undef);
1811
$row = $result->fetch;
1812
is_deeply($row, [1, 1, 40], 'apply_filter overwrite');
1813

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

            
1828
test 'empty where select';
1829
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1830
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1831
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1832
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1833
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1834
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1835
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1836

            
1837
test 'select query option';
1838
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1839
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1840
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1841
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1842
ok(ref $query);
cleanup
Yuki Kimoto authored on 2011-11-01
1843
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1844
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1845
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1846
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1847
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1848
ok(ref $query);
test cleanup
Yuki Kimoto authored on 2011-08-10
1849

            
1850
test 'where';
1851
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1852
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1853
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1854
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1855
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1856
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1857
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1858

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

            
1863
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1864
  table => $table1,
1865
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1866
);
1867
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1868
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1869

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

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

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

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

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

            
1918
eval {
1919
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1920
           ->clause(['uuu']);
test cleanup
Yuki Kimoto authored on 2011-08-10
1921
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1922
  table => $table1,
1923
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1924
);
1925
};
1926
ok($@);
1927

            
1928
$where = $dbi->where;
1929
is("$where", '');
1930

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2100
eval {$dbi->where(ppp => 1) };
2101
like($@, qr/invalid/);
2102

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

            
2114

            
2115
$where = $dbi->where(
cleanup
Yuki Kimoto authored on 2012-01-20
2116
  clause => ['and', ['or'], ['or', ":$key1", ":$key2"]],
2117
  param => {}
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}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2125

            
2126
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2127
$where->clause(['and', ":${key1}{=}"]);
2128
$where->param({$key1 => undef});
2129
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
2130
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2131
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2132

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

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

            
2144
$dbi = DBIx::Custom->connect;
2145
eval { $dbi->execute("drop table $table1") };
2146
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2147
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
2148
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2149
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2150
  ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
2151
  ->param({$key1 => 1});
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2152

            
2153
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2154
  table => $table1,
2155
  where => $where
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2156
);
2157
$row = $result->all;
2158
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
2159

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2160
test 'register_tag_processor';
2161
$dbi = DBIx::Custom->connect;
2162
$dbi->register_tag_processor(
cleanup
Yuki Kimoto authored on 2012-01-20
2163
  a => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
2164
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2165
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2166

            
2167
test 'register_tag';
2168
$dbi = DBIx::Custom->connect;
2169
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
2170
  b => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
2171
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2172
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2173

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2179
test 'more tests';
2180
$dbi = DBIx::Custom->connect;
2181
eval{$dbi->apply_filter('table', 'column', [])};
2182
like($@, qr/apply_filter/);
2183

            
2184
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
2185
like($@, qr/apply_filter/);
2186

            
2187
$dbi->apply_filter(
2188

            
2189
);
2190
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2191
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2192
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2193
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2194
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2195
$dbi->apply_filter($table1, $key2, 
cleanup
Yuki Kimoto authored on 2012-01-20
2196
                 {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2197
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
2198
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2199

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

            
2209
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2210
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2211
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2212
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2213
like($@, qr/not registered/);
2214
$dbi->method({one => sub { 1 }});
2215
is($dbi->one, 1);
2216

            
2217
eval{DBIx::Custom->connect(dsn => undef)};
2218
like($@, qr/_connect/);
2219

            
2220
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2221
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2222
$dbi->execute($create_table1);
2223
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
2224
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
2225
           filter => {$key1 => 'twice'});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2226
$row = $dbi->select(table => $table1)->one;
2227
is_deeply($row, {$key1 => 2, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
2228
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
2229
           filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
2230
like($@, qr//);
2231

            
2232
$dbi->register_filter(one => sub { });
2233
$dbi->default_fetch_filter('one');
2234
ok($dbi->default_fetch_filter);
2235
$dbi->default_bind_filter('one');
2236
ok($dbi->default_bind_filter);
2237
eval{$dbi->default_fetch_filter('no')};
2238
like($@, qr/not registered/);
2239
eval{$dbi->default_bind_filter('no')};
2240
like($@, qr/not registered/);
2241
$dbi->default_bind_filter(undef);
2242
ok(!defined $dbi->default_bind_filter);
2243
$dbi->default_fetch_filter(undef);
2244
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2245
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2246
like($@, qr/Tag not finished/);
2247

            
2248
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2249
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2250
$dbi->execute($create_table1);
2251
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2252
$result = $dbi->select(table => $table1);
2253
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2254
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2255
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2256
like($@, qr/not registered/);
2257
$result->default_filter(undef);
2258
ok(!defined $result->default_filter);
2259
$result->default_filter('one');
2260
is($result->default_filter->(), 1);
2261

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2262
test 'option';
2263
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
2264
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
2265
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2266
ok($dbi->dbh->{PrintError});
2267
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2268
ok($dbi->dbh->{PrintError});
2269

            
2270
test 'DBIx::Custom::Result stash()';
2271
$result = DBIx::Custom::Result->new;
2272
is_deeply($result->stash, {}, 'default');
2273
$result->stash->{foo} = 1;
2274
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2275

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2276
test 'delete_at';
2277
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2278
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2279
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2280
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2281
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2282
  table => $table1,
2283
  primary_key => [$key1, $key2],
2284
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2285
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2286
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2287

            
cleanup
Yuki Kimoto authored on 2011-11-01
2288
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2289
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2290
  table => $table1,
2291
  primary_key => $key1,
2292
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2293
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2294
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2295

            
2296
test 'insert_at';
2297
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2298
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2299
$dbi->execute($create_table1_2);
2300
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2301
  {$key3 => 3},
2302
  primary_key => [$key1, $key2], 
2303
  table => $table1,
2304
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2305
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2306
is($dbi->select(table => $table1)->one->{$key1}, 1);
2307
is($dbi->select(table => $table1)->one->{$key2}, 2);
2308
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2309

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2310
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2311
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2312
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2313
  {$key2 => 2, $key3 => 3},
2314
  primary_key => $key1, 
2315
  table => $table1,
2316
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2317
);
2318

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2351
$dbi->delete_all(table => $table1);
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,
2357
  where => 1,
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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2392
$dbi->delete_all(table => $table1);
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,
2397
  where => 1,
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, $key2],
2409
  where => [1, 2]
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

            
2416
test 'model delete_at';
2417
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2418
eval { $dbi->execute("drop table $table1") };
2419
eval { $dbi->execute("drop table $table2") };
2420
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2421
$dbi->execute($create_table1_2);
2422
$dbi->execute($create_table2_2);
2423
$dbi->execute($create_table3);
test cleanup
Yuki Kimoto authored on 2011-11-01
2424
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2425
$dbi->model($table1)->delete_at(where => [1, 2]);
2426
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2427
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2428
$dbi->model($table1)->delete_at(where => [1, 2]);
2429
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2430
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2431
$dbi->model($table3)->delete_at(where => [1, 2]);
2432
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2433

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

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

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

            
2474

            
2475
test 'mycolumn and column';
2476
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2477
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2478
eval { $dbi->execute("drop table $table1") };
2479
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2480
$dbi->execute($create_table1);
2481
$dbi->execute($create_table2);
2482
$dbi->separator('__');
2483
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2484
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2485
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2486
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2487
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2488
  column => [$model->mycolumn, $model->column($table2)],
2489
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2490
);
2491
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2492
        {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2493

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2494
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2495
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2496
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2497
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2498
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2499
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2500
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2501
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2502
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2503
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2504
is($dbi->select(table => $table1)->one->{$key1}, 1);
2505
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2506

            
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->insert_param($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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2519
test 'mycolumn';
2520
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2521
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2522
eval { $dbi->execute("drop table $table1") };
2523
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2524
$dbi->execute($create_table1);
2525
$dbi->execute($create_table2);
2526
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2527
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2528
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2529
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2530
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2531
  column => [
2532
    $model->mycolumn,
2533
    $model->column($table2)
2534
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2535
);
2536
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2537
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2538

            
2539
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2540
  column => [
2541
    $model->mycolumn([$key1]),
2542
    $model->column($table2 => [$key1])
2543
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2544
);
2545
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2546
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2547
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2548
  column => [
2549
    $model->mycolumn([$key1]),
2550
    {$table2 => [$key1]}
2551
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2552
);
2553
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2554
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2555

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2574
test 'merge_param';
2575
$dbi = DBIx::Custom->new;
2576
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2577
  {$key1 => 1, $key2 => 2, $key3 => 3},
2578
  {$key1 => 1, $key2 => 2},
2579
  {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2580
];
2581
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2582
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2583

            
2584
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2585
  {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2586
  {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2587
];
2588
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2589
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
2590

            
2591
test 'select() param option';
2592
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2593
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2594
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2595
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2596
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2597
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2598
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2599
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
2600
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
2601
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2602
  table => $table1,
2603
  column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2604
  where   => {"$table1.$key2" => 3},
2605
  join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
2606
            " $table2 on $table1.$key1 = $table2.$key1"],
2607
  param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2608
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2609
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2610

            
cleanup
Yuki Kimoto authored on 2011-10-21
2611
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2612
  table => $table1,
2613
  column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2614
  where   => {"$table1.$key2" => 3},
2615
  join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2616
           " $table2 on $table1.$key1 = $table2.$key1",
2617
  param => {"$table2.$key3" => 5}
cleanup
Yuki Kimoto authored on 2011-10-21
2618
)->all;
2619
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2620

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2621
test 'select() string where';
2622
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2623
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2624
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2625
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2626
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2627
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2628
  table => $table1,
2629
  where => "$key1 = :$key1 and $key2 = :$key2",
2630
  where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2631
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2632
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2633

            
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 => [
2642
    "$key1 = :$key1 and $key2 = :$key2",
2643
    {$key1 => 1, $key2 => 2}
2644
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2645
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2646
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2647

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

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

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

            
2691

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

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

            
2721
test 'insert id and primary_key option';
2722
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2723
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2724
$dbi->execute($create_table1_2);
2725
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2726
  {$key3 => 3},
2727
  primary_key => [$key1, $key2], 
2728
  table => $table1,
2729
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2730
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2731
is($dbi->select(table => $table1)->one->{$key1}, 1);
2732
is($dbi->select(table => $table1)->one->{$key2}, 2);
2733
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2734

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2735
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2736
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2737
  {$key2 => 2, $key3 => 3},
2738
  primary_key => $key1, 
2739
  table => $table1,
2740
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2741
);
2742

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2743
is($dbi->select(table => $table1)->one->{$key1}, 0);
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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2747
$dbi = DBIx::Custom->connect;
2748
eval { $dbi->execute("drop table $table1") };
2749
$dbi->execute($create_table1_2);
2750
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2751
  {$key3 => 3},
2752
  primary_key => [$key1, $key2], 
2753
  table => $table1,
2754
  id => 1,
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2755
);
2756
is($dbi->select(table => $table1)->one->{$key1}, 1);
2757
ok(!$dbi->select(table => $table1)->one->{$key2});
2758
is($dbi->select(table => $table1)->one->{$key3}, 3);
2759

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2760
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2761
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2762
$dbi->execute($create_table1_2);
2763
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2764
  {$key3 => 3},
2765
  primary_key => [$key1, $key2], 
2766
  table => $table1,
2767
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2768
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2769
is($dbi->select(table => $table1)->one->{$key1}, 1);
2770
is($dbi->select(table => $table1)->one->{$key2}, 2);
2771
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2772

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2773
$dbi = DBIx::Custom->connect;
2774
eval { $dbi->execute("drop table $table1") };
2775
$dbi->execute($create_table1_2);
2776
$param = {$key3 => 3, $key2 => 4};
2777
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2778
  $param,
2779
  primary_key => [$key1, $key2], 
2780
  table => $table1,
2781
  id => [1, 2],
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2782
);
2783
is($dbi->select(table => $table1)->one->{$key1}, 1);
2784
is($dbi->select(table => $table1)->one->{$key2}, 4);
2785
is($dbi->select(table => $table1)->one->{$key3}, 3);
2786
is_deeply($param, {$key3 => 3, $key2 => 4});
2787

            
added test
Yuki Kimoto authored on 2011-10-25
2788
$dbi = DBIx::Custom->connect;
2789
eval { $dbi->execute("drop table $table1") };
2790
$dbi->execute($create_table1_2);
2791
$param = {$key3 => 3, $key2 => 4};
2792
$query = $dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2793
  $param,
2794
  primary_key => [$key1, $key2], 
2795
  table => $table1,
2796
  id => [1, 2],
2797
  query => 1
added test
Yuki Kimoto authored on 2011-10-25
2798
);
micro optimization
Yuki Kimoto authored on 2011-11-16
2799
ok(ref $query);
added test
Yuki Kimoto authored on 2011-10-25
2800
is_deeply($param, {$key3 => 3, $key2 => 4});
2801

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2802
test 'model insert id and primary_key option';
2803
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2804
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2805
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2806
$dbi->model($table1)->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2807
  {$key3 => 3},
2808
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2809
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2810
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2811
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2812
is($row->{$key1}, 1);
2813
is($row->{$key2}, 2);
2814
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2815

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

            
2829
test 'update and id option';
2830
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2831
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2832
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2833
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2834
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2835
  {$key3 => 4},
2836
  table => $table1,
2837
  primary_key => [$key1, $key2],
2838
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2839
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2840
is($dbi->select(table => $table1)->one->{$key1}, 1);
2841
is($dbi->select(table => $table1)->one->{$key2}, 2);
2842
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2843

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2844
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2845
$dbi->insert({$key1 => 0, $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,
2850
  id => 0,
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}, 0);
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

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

            
2870

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

            
2886

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

            
cleanup
Yuki Kimoto authored on 2011-11-01
2899
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2900
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2901
  table => $table1,
2902
  primary_key => $key1,
2903
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2904
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2905
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2906

            
2907

            
2908
test 'model delete and id option';
2909
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2910
eval { $dbi->execute("drop table $table1") };
2911
eval { $dbi->execute("drop table $table2") };
2912
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2913
$dbi->execute($create_table1_2);
2914
$dbi->execute($create_table2_2);
2915
$dbi->execute($create_table3);
cleanup
Yuki Kimoto authored on 2011-11-01
2916
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2917
$dbi->model($table1)->delete(id => [1, 2]);
2918
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2919
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2920
$dbi->model($table1)->delete(id => [1, 2]);
2921
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2922
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2923
$dbi->model($table3)->delete(id => [1, 2]);
2924
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2925

            
2926

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2942
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2943
$dbi->insert({$key1 => 0, $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,
2947
  id => 0,
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}, 0);
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 => 1, $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, $key2],
2959
  id => [1, 2]
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}, 1);
2963
is($row->{$key2}, 2);
2964
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2965

            
2966

            
2967
test 'model select_at';
2968
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2969
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2970
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2971
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2972
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
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
test 'column separator is default .';
2979
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2980
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2981
eval { $dbi->execute("drop table $table1") };
2982
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2983
$dbi->execute($create_table1);
2984
$dbi->execute($create_table2);
2985
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2986
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2987
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2988
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2989
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2990
  column => [$model->column($table2)],
2991
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2992
);
2993
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2994
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2995

            
2996
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2997
  column => [$model->column($table2 => [$key1, $key3])],
2998
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2999
);
3000
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3001
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3002

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3003
test 'separator';
3004
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3005
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3006
eval { $dbi->execute("drop table $table1") };
3007
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3008
$dbi->execute($create_table1);
3009
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
3010

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3011
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3012
  table => $table1,
3013
  join => [
3014
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3015
  ],
3016
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
3017
);
3018
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3019
  table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
3020
);
3021
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3022
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3023
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3024
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3025
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3026
  column => [
3027
    $model->mycolumn,
3028
    {$table2 => [$key1, $key3]}
3029
  ],
3030
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3031
);
3032
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3033
        {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3034
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3035

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3036
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3037
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3038
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3039
  column => [
3040
    $model->mycolumn,
3041
    {$table2 => [$key1, $key3]}
3042
  ],
3043
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3044
);
3045
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3046
        {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3047
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3048

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

            
3062

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3063
test 'filter_off';
3064
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3065
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3066
eval { $dbi->execute("drop table $table1") };
3067
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3068
$dbi->execute($create_table1);
3069
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
3070

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3071
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3072
  table => $table1,
3073
  join => [
3074
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3075
  ],
3076
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
3077
);
3078
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3079
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3080
$model = $dbi->model($table1);
3081
$result = $model->select(column => $key1);
3082
$result->filter($key1 => sub { $_[0] * 2 });
3083
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
3084

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3085
test 'available_datetype';
3086
$dbi = DBIx::Custom->connect;
3087
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
3088

            
3089

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3090
test 'select prefix option';
3091
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3092
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3093
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3094
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3095
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3096
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
3097

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

            
added tests
Yuki Kimoto authored on 2011-08-26
3099
test 'mapper';
3100
$dbi = DBIx::Custom->connect;
3101
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3102
  id => {key => "$table1.id"},
3103
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3104
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
3105
);
3106
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3107
"$table1.price" => 1900});
added tests
Yuki Kimoto authored on 2011-08-26
3108

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

            
added tests
Yuki Kimoto authored on 2011-08-26
3118
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3119
  id => {key => "$table1.id"},
3120
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3121
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
3122
);
3123
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
3124

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

            
3132
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3133
  id => {key => "$table1.id"},
3134
  price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
3135
);
3136
is_deeply($param, {"$table1.price" => undef});
3137

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

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

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3150
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3151
  price => sub { '%' . $_[0] },
3152
  author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
3153
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3154
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
3155

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

            
3161
$where = $dbi->where;
3162
$where->clause(['and', ":${key1}{=}"]);
3163
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
3164
$where->param($param);
3165
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3166
$row = $result->all;
3167
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3168

            
3169
$where = $dbi->where;
3170
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
3171
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
3172
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
3173
$row = $result->all;
3174
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3175
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
3176
$row = $result->all;
3177
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3178

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

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3191
$where = $dbi->where;
3192
$where->clause(['and', ":${key1}{=}"]);
3193
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
cleanup
Yuki Kimoto authored on 2012-01-20
3194
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3195
$where->param($param);
3196
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3197
$row = $result->all;
3198
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3199

            
3200
$where = $dbi->where;
3201
$where->clause(['and', ":${key1}{=}"]);
3202
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
3203
$where->param($param);
3204
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3205
$row = $result->all;
3206
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3207

            
3208
$where = $dbi->where;
3209
$where->clause(['and', ":${key1}{=}"]);
3210
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
cleanup
Yuki Kimoto authored on 2012-01-20
3211
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3212
$where->param($param);
3213
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3214
$row = $result->all;
3215
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3216

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

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

            
3226
$where = $dbi->where;
3227
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3228
  id => {key => "$table1.id"},
3229
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3230
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3231
);
3232
$where->param($param);
3233
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3234
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3235

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

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

            
3254
$where = $dbi->where;
3255
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3256
  id => {key => "$table1.id"},
3257
  price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3258
);
3259
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
3260

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

            
3268
$where = $dbi->where;
3269
$param = $dbi->mapper(param => {id => [1, 2], author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3270
  id => {key => "$table1.id"},
3271
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3272
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3273
);
3274
is_deeply($param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3275
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3276

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

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

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

            
- DBIx::Custom::Mapper::map ...
Yuki Kimoto authored on 2012-02-29
3300
$param = $dbi->mapper(param => {author => 'Ken',})->map(
3301
  author => ["$table1.author" => '%<value>%'],
3302
);
3303
is_deeply($param, {"$table1.author" => '%Ken%'});
3304

            
3305
$param = $dbi->mapper(param => {author => 'Ken'})->map(
3306
  author => ["$table1.author" => 'p'],
3307
);
3308
is_deeply($param, {"$table1.author" => 'p'});
3309

            
3310
$param = $dbi->mapper(param => {author => 'Ken',})->map(
3311
  author => {value => '%<value>%'}
3312
);
3313
is_deeply($param, {"author" => '%Ken%'});
3314

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3315
test 'order';
3316
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3317
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3318
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3319
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3320
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3321
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3322
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3323
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3324
$order->prepend($key1, "$key2 desc");
3325
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3326
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
3327
{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3328
$order->prepend("$key1 desc");
3329
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3330
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
cleanup
Yuki Kimoto authored on 2012-01-20
3331
{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3332

            
3333
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3334
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3335
$result = $dbi->select(table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
3336
column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
3337
append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3338
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
cleanup
Yuki Kimoto authored on 2012-01-20
3339
{"$table1-$key1" => 1, "$table1-$key2" => 1},
3340
{"$table1-$key1" => 2, "$table1-$key2" => 4},
3341
{"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3342

            
3343
test 'tag_parse';
3344
$dbi = DBIx::Custom->connect;
3345
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3346
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3347
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3348
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3349
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3350
ok($@);
3351

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3352
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3353
{
cleanup
Yuki Kimoto authored on 2012-01-20
3354
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3355
  $dbi = DBIx::Custom->connect;
3356
  eval { $dbi->execute("drop table $table1") };
3357
  $dbi->execute($create_table1);
3358
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3359
  eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3360
  ok($@);
3361
  eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) };
3362
  ok($@);
3363
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3364
}
3365

            
3366
{
cleanup
Yuki Kimoto authored on 2012-01-20
3367
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3368
  $dbi = DBIx::Custom->connect;
3369
  eval { $dbi->execute("drop table $table1") };
3370
  $dbi->execute($create_table1);
3371
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3372
  is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1);
3373
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3374
}
3375

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3376
test 'last_sql';
3377
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3378
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3379
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3380
$dbi->execute("select * from $table1");
micro optimization
Yuki Kimoto authored on 2011-11-18
3381
is($dbi->last_sql, " select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3382

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

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

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

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

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

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

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

            
3423
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3424
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3425
$dbi->execute($create_table1_highperformance);
3426
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3427
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3428
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3429
];
3430
{
cleanup
Yuki Kimoto authored on 2012-01-20
3431
  my $query;
3432
  for my $row (@$rows) {
3433
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3434
    $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3435
  }
3436
  is_deeply($dbi->select(table => $table1)->all,
3437
    [
3438
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3439
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3440
    ]
3441
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3442
}
3443

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3444
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3445
$dbi->execute($create_table1_highperformance);
3446
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3447
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3448
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3449
];
3450
{
cleanup
Yuki Kimoto authored on 2012-01-20
3451
  my $query;
3452
  my $sth;
3453
  for my $row (@$rows) {
3454
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3455
    $sth ||= $query->{sth};
3456
    $sth->execute(map { $row->{$_} } sort keys %$row);
3457
  }
3458
  is_deeply($dbi->select(table => $table1)->all,
3459
    [
3460
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3461
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3462
    ]
3463
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3464
}
3465

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

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3487
eval { $dbi->execute("drop table $table1") };
3488
$dbi->execute($create_table1);
3489
{
cleanup
Yuki Kimoto authored on 2012-01-20
3490
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3491
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3492
  eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3493
  like($@, qr/primary_key/);
3494
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3495
}
3496

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

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

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3516
test 'id option more';
3517
eval { $dbi->execute("drop table $table1") };
3518
$dbi->execute($create_table1_highperformance);
3519
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3520
  $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
3521
};
3522
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3523
$model->insert($row);
3524
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3525
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3526
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3527
  {$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
3528
);
3529

            
3530
eval { $dbi->execute("drop table $table1") };
3531
eval { $dbi->execute("drop table $table2") };
3532
$dbi->execute($create_table1);
3533
$dbi->execute($create_table2);
3534
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3535
$model->insert({$key1 => 1, $key2 => 2});
3536
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
3537
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3538
$model->insert({$key1 => 1, $key3 => 3});
3539
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3540
  column => {$table1 => ["$key2"]},
3541
  id => 1
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3542
);
3543
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3544

            
3545
eval { $dbi->execute("drop table $table1") };
3546
$dbi->execute($create_table1_highperformance);
3547
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3548
  $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
3549
};
3550
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3551
$model->insert($row);
3552
$query = $model->delete(id => 1, query => 1);
3553
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3554
is_deeply($dbi->select(table => $table1)->all, []);
3555

            
3556
eval { $dbi->execute("drop table $table1") };
3557
eval { $dbi->execute($create_table1_highperformance) };
3558
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3559
  $key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => 2
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3560
};
3561
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3562
$model->insert($row);
3563
$query = $model->select(id => 1, query => 1);
3564
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3565
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3566
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3567
  {$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
3568
);
3569

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3570
test 'result';
3571
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3572
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3573
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3574
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3575
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3576

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3577
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3578
@rows = ();
3579
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
3580
  push @rows, [@$row];
test cleanup
Yuki Kimoto authored on 2011-08-10
3581
}
3582
is_deeply(\@rows, [[1, 2], [3, 4]]);
3583

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3584
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3585
@rows = ();
3586
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
3587
  push @rows, {%$row};
test cleanup
Yuki Kimoto authored on 2011-08-10
3588
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3589
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3590

            
3591
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3592
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3593
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3594
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3595
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3596

            
3597
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3598
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3599
$rows = $result->fetch_all;
3600
is_deeply($rows, [[1, 2], [3, 4]]);
3601

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3606
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3607
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3608
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3609
$rows = $result->fetch_all;
3610
is_deeply($rows, [[3, 2], [9, 4]], "array");
3611

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3612
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
3613
$result->dbi->filters({three_times => sub { $_[0] * 3}});
3614
$result->filter({$key1 => 'three_times'});
3615
$rows = $result->fetch_all;
3616
is_deeply($rows, [[3, 3, 2], [9, 9, 4]], "array");
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_hash_all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3622
is_deeply($rows, [{$key1 => 3, $key2 => 2}, {$key1 => 9, $key2 => 4}], "hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
3623

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2012-02-28
3624
test 'flat';
3625
$result = $dbi->select(table => $table1);
3626
$rows = [$result->flat];
3627
is_deeply($rows, [1, 2, 3, 4]);
3628

            
added EXPERIMETAL DBIx::Cust...
Yuki Kimoto authored on 2012-02-28
3629
test 'kv';
3630
$dbi = DBIx::Custom->connect;
3631
eval { $dbi->execute("drop table $table1") };
3632
$dbi->execute($create_table1);
3633
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3634
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3635

            
3636
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key1");
3637
$rows = $result->kv;
3638
is_deeply($rows, {0 => {$key2 => 2}, 3 => {$key2 => 4}});
3639

            
3640
$dbi = DBIx::Custom->connect;
3641
eval { $dbi->execute("drop table $table1") };
3642
$dbi->execute($create_table1);
3643
$dbi->insert({$key1 => 0, $key2 => 1}, table => $table1);
3644
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3645
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3646
$dbi->insert({$key1 => 3, $key2 => 5}, table => $table1);
3647

            
3648
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key2");
3649
$rows = $result->kv(multi => 1);
3650
is_deeply($rows, {
3651
  0 => [
3652
    {$key2 => 1},
3653
    {$key2 => 2}
3654
  ],
3655
  3 => [
3656
    {$key2 => 4},
3657
    {$key2 => 5}
3658
  ]
3659
});
3660

            
3661

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3662
test 'DBIx::Custom::Result fetch_multi';
3663
eval { $dbi->execute("drop table $table1") };
3664
$dbi->execute($create_table1);
3665
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3666
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3667
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3668
$result = $dbi->select(table => $table1);
3669
$rows = $result->fetch_multi(2);
3670
is_deeply($rows, [[1, 2], [3, 4]]);
3671
$rows = $result->fetch_multi(2);
3672
is_deeply($rows, [[5, 6]]);
3673
$rows = $result->fetch_multi(2);
3674
ok(!$rows);
3675

            
3676
test 'DBIx::Custom::Result fetch_hash_multi';
3677
eval { $dbi->execute("drop table $table1") };
3678
$dbi->execute($create_table1);
3679
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3680
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3681
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3682
$result = $dbi->select(table => $table1);
3683
$rows = $result->fetch_hash_multi(2);
3684
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3685
$rows = $result->fetch_hash_multi(2);
3686
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3687
$rows = $result->fetch_hash_multi(2);
3688
ok(!$rows);
3689

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

            
3726
for (my $i = 0; $i < @$datas; $i++) {
cleanup
Yuki Kimoto authored on 2012-01-20
3727
  my $data = $datas->[$i];
3728
  my $dbi = DBIx::Custom->new;
3729
  my $builder = $dbi->query_builder;
3730
  my $query = $builder->build_query($data->{source});
3731
  is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3732
  is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3733
}
3734

            
cleanup
Yuki Kimoto authored on 2011-08-13
3735
$dbi = DBIx::Custom->new;
3736
$builder = $dbi->query_builder;
3737
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
3738
  p => sub {
3739
    my @args = @_;
3740
    
3741
    my $expand    = "? $args[0] $args[1]";
3742
    my $columns = [2];
3743
    return [$expand, $columns];
3744
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3745
);
3746

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3757
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3758
  q => 'string'
test cleanup
Yuki Kimoto authored on 2011-08-10
3759
});
3760

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3764
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3765
  r => sub {} 
test cleanup
Yuki Kimoto authored on 2011-08-10
3766
});
3767

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

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

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

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

            
3782

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

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

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

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

            
3798
test 'variouse source';
3799
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3800
$query = $builder->build_query($source);
3801
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3802

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

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

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

            
3815
$source = "a {= b} }";
3816
eval{$builder->build_query($source)};
3817
like($@, qr/unexpected "}"/, "error : 1");
3818

            
3819
$source = "a {= {}";
3820
eval{$builder->build_query($source)};
3821
like($@, qr/unexpected "{"/, "error : 2");
3822

            
3823
test 'select() sqlfilter option';
3824
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3825
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3826
eval { $dbi->execute("drop table $table1") };
3827
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3828
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3829
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3830
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3831
  table => $table1,
3832
  column => $key1,
3833
  sqlfilter => sub {
3834
    my $sql = shift;
3835
    $sql = "select * from ( $sql ) t where $key1 = 1";
3836
    return $sql;
3837
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3838
)->all;
3839
is_deeply($rows, [{$key1 => 1}]);
3840

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3841
test 'select() after_build_sql option';
3842
$dbi = DBIx::Custom->connect;
3843
$dbi->user_table_info($user_table_info);
3844
eval { $dbi->execute("drop table $table1") };
3845
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3846
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3847
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3848
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3849
  table => $table1,
3850
  column => $key1,
3851
  after_build_sql => sub {
3852
    my $sql = shift;
3853
    $sql = "select * from ( $sql ) t where $key1 = 1";
3854
    return $sql;
3855
  }
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3856
)->all;
3857
is_deeply($rows, [{$key1 => 1}]);
3858

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3859
test 'dbi method from model';
3860
$dbi = MyDBI9->connect;
3861
eval { $dbi->execute("drop table $table1") };
3862
$dbi->execute($create_table1);
3863
$dbi->setup_model;
3864
$model = $dbi->model($table1);
3865
eval{$model->execute("select * from $table1")};
3866
ok(!$@);
3867

            
3868
test 'column table option';
3869
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3870
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3871
eval { $dbi->execute("drop table $table1") };
3872
$dbi->execute($create_table1);
3873
eval { $dbi->execute("drop table $table2") };
3874
$dbi->execute($create_table2);
3875
$dbi->setup_model;
3876
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3877
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3878
$model = $dbi->model($table1);
3879
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3880
  column => [
3881
    $model->column($table2, {alias => $table2_alias})
3882
  ],
3883
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3884
);
3885
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3886
        {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3887

            
3888
$dbi->separator('__');
3889
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3890
  column => [
3891
    $model->column($table2, {alias => $table2_alias})
3892
  ],
3893
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3894
);
3895
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3896
  {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3897

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

            
3908
test 'create_model';
3909
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3910
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3911
eval { $dbi->execute("drop table $table1") };
3912
eval { $dbi->execute("drop table $table2") };
3913
$dbi->execute($create_table1);
3914
$dbi->execute($create_table2);
3915

            
3916
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3917
  table => $table1,
3918
  join => [
3919
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3920
  ],
3921
  primary_key => [$key1]
cleanup test
Yuki Kimoto authored on 2011-08-15
3922
);
3923
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3924
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3925
);
3926
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3927
  table => $table3,
3928
  filter => [
3929
    $key1 => {in => sub { uc $_[0] }}
3930
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
3931
);
3932
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3933
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3934
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3935
$model = $dbi->model($table1);
3936
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3937
  column => [$model->mycolumn, $model->column($table2)],
3938
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-15
3939
);
3940
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3941
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3942
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3943

            
3944
test 'model method';
3945
$dbi = DBIx::Custom->connect;
3946
eval { $dbi->execute("drop table $table2") };
3947
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3948
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3949
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3950
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3951
);
3952
$model->method(foo => sub { shift->select(@_) });
3953
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3954

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

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

            
3973
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3974
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3975
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3976
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3977
where $key1 = 1
3978
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3979
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3980
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3981
$rows   = $result->all;
3982
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3983
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3984
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
3985

            
3986

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

            
3993
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3994
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3995
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3996
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3997
where $key1 = 1
3998
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3999
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
4000
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
4001
$rows   = $result->all;
4002
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
4003
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
4004
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
4005

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
4025
          
cleanup test
Yuki Kimoto authored on 2011-08-15
4026
$dbi = DBIx::Custom->connect;
4027
eval { $dbi->execute("drop table $table1") };
4028
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4029
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
4030
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
4031

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4058
test 'Model class';
4059
$dbi = MyDBI1->connect;
4060
eval { $dbi->execute("drop table $table1") };
4061
$dbi->execute($create_table1);
4062
$model = $dbi->model($table1);
4063
$model->insert({$key1 => 'a', $key2 => 'b'});
4064
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4065
eval { $dbi->execute("drop table $table2") };
4066
$dbi->execute($create_table2);
4067
$model = $dbi->model($table2);
4068
$model->insert({$key1 => 'a'});
4069
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4070
is($dbi->models->{$table1}, $dbi->model($table1));
4071
is($dbi->models->{$table2}, $dbi->model($table2));
4072

            
4073
$dbi = MyDBI4->connect;
4074
eval { $dbi->execute("drop table $table1") };
4075
$dbi->execute($create_table1);
4076
$model = $dbi->model($table1);
4077
$model->insert({$key1 => 'a', $key2 => 'b'});
4078
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4079
eval { $dbi->execute("drop table $table2") };
4080
$dbi->execute($create_table2);
4081
$model = $dbi->model($table2);
4082
$model->insert({$key1 => 'a'});
4083
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4084

            
4085
$dbi = MyDBI5->connect;
4086
eval { $dbi->execute("drop table $table1") };
4087
eval { $dbi->execute("drop table $table2") };
4088
$dbi->execute($create_table1);
4089
$dbi->execute($create_table2);
4090
$model = $dbi->model($table2);
4091
$model->insert({$key1 => 'a'});
4092
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
4093
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4094
$model = $dbi->model($table1);
4095
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
4096

            
4097
test 'primary_key';
4098
$dbi = MyDBI1->connect;
4099
$model = $dbi->model($table1);
4100
$model->primary_key([$key1, $key2]);
4101
is_deeply($model->primary_key, [$key1, $key2]);
4102

            
4103
test 'columns';
4104
$dbi = MyDBI1->connect;
4105
$model = $dbi->model($table1);
4106
$model->columns([$key1, $key2]);
4107
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4108

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4109
test 'setup_model';
4110
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
4111
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4112
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4113
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
4114

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4115
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4116
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4117
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
4118
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
4119
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4120

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4121
test 'each_column';
4122
$dbi = DBIx::Custom->connect;
4123
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4124
eval { $dbi->execute("drop table $table1") };
4125
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4126
eval { $dbi->execute("drop table $table3") };
4127
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4128
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4129

            
4130
$infos = [];
4131
$dbi->each_column(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4132
  my ($self, $table, $column, $cinfo) = @_;
4133
  
4134
  if ($table =~ /^table\d/i) {
4135
     my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
4136
     push @$infos, $info;
4137
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4138
});
4139
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4140
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4141
  [
4142
    [$table1, $key1, $key1],
4143
    [$table1, $key2, $key2],
4144
    [$table2, $key1, $key1],
4145
    [$table2, $key3, $key3]
4146
  ]
4147
  
cleanup test
Yuki Kimoto authored on 2011-08-10
4148
);
cleanup test
Yuki Kimoto authored on 2011-08-16
4149

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4150
test 'each_table';
4151
$dbi = DBIx::Custom->connect;
4152
eval { $dbi->execute("drop table $table1") };
4153
eval { $dbi->execute("drop table $table2") };
4154
$dbi->execute($create_table2);
4155
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4156

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4157
$infos = [];
4158
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4159
  my ($self, $table, $table_info) = @_;
4160
  
4161
  if ($table =~ /^table\d/i) {
4162
    my $info = [$table, $table_info->{TABLE_NAME}];
4163
    push @$infos, $info;
4164
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4165
});
4166
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4167
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4168
  [
4169
    [$table1, $table1],
4170
    [$table2, $table2],
4171
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4172
);
4173

            
cleanup test
Yuki Kimoto authored on 2011-08-16
4174
$dbi = DBIx::Custom->connect;
4175
eval { $dbi->execute("drop table $table1") };
4176
eval { $dbi->execute("drop table $table2") };
4177
$dbi->execute($create_table2);
4178
$dbi->execute($create_table1_type);
4179

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4199
test 'type_rule into';
4200
eval { $dbi->execute("drop table $table1") };
4201
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4202
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
4203

            
4204

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

            
cleanup
Yuki Kimoto authored on 2011-08-16
4209
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4210
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4211
  into1 => {
4212
    $date_typename => sub { '2010-' . $_[0] }
4213
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4214
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4215
$dbi->insert({$key1 => '01-01'}, table => $table1);
4216
$result = $dbi->select(table => $table1);
4217
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4218

            
4219
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4220
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4221
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4222
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4223
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4224
  into1 => [
4225
     [$date_typename, $datetime_typename] => sub {
4226
        my $value = shift;
4227
        $value =~ s/02/03/g;
4228
        return $value;
4229
     }
4230
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
4231
);
4232
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
4233
$result = $dbi->select(table => $table1);
4234
$row = $result->one;
4235
like($row->{$key1}, qr/^2010-01-03/);
4236
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4237

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4238
$dbi = DBIx::Custom->connect;
4239
eval { $dbi->execute("drop table $table1") };
4240
$dbi->execute($create_table1_type);
4241
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4242
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4243
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4244
  into1 => [
4245
    [$date_typename, $datetime_typename] => sub {
4246
      my $value = shift;
4247
      $value =~ s/02/03/g;
4248
      return $value;
4249
    }
4250
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4251
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4252
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
4253
  "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
4254
  {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
4255
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4256
$row = $result->one;
4257
like($row->{$key1}, qr/^2010-01-03/);
4258
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4259

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

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

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

            
4333

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4360
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
4361
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
4362
eval { $dbi->execute("drop table $table1") };
4363
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4364
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4365
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4366
  from1 => {
4367
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4368
  },
4369
  into1 => {
4370
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4371
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4372
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4373
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4374
$result = $dbi->select(table => $table1, type_rule_off => 1);
4375
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4376

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4439
eval{$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4440
  into1 => {
4441
    $date_typename => 'pp'
4442
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4443
)};
4444
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4445

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4446
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4447
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4448
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4449
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4450
  $dbi->type_rule(
4451
    from1 => {
4452
      Date => sub { $_[0] * 2 },
4453
    }
4454
  );
cleanup test
Yuki Kimoto authored on 2011-08-10
4455
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4456
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4457

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4458
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4459
  $dbi->type_rule(
4460
    into1 => {
4461
      Date => sub { $_[0] * 2 },
4462
    }
4463
  );
cleanup test
Yuki Kimoto authored on 2011-08-15
4464
};
4465
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4466

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

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

            
4505
$result = $dbi->select(table => $table1);
4506
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4507
  from1 => {
4508
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4509
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4510
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4511
$row = $result->one;
4512
like($row->{$key1}, qr/2010-01-05/);
4513
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4514

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

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

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

            
4542
$result = $dbi->select(table => $table1);
4543
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4544
  from1 => [$date_datatype => undef]
cleanup test
Yuki Kimoto authored on 2011-08-15
4545
);
4546
$row = $result->one;
4547
like($row->{$key1}, qr/^2010-01-03/);
4548
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4549

            
4550
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4551
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4552
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4553
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4554
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4555
  from1 => {
4556
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4557
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4558
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4559
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4560
$result = $dbi->select(table => $table1);
4561
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4562
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4563

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

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4650
test 'join';
4651
$dbi = DBIx::Custom->connect;
4652
eval { $dbi->execute("drop table $table1") };
4653
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4654
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4655
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4656
eval { $dbi->execute("drop table $table2") };
4657
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4658
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4659
eval { $dbi->execute("drop table $table3") };
4660
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4661
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4662
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4663
  table => $table1,
4664
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4665
  where   => {"$table1.$key2" => 2},
4666
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4667
)->all;
4668
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4669

            
4670
$dbi = DBIx::Custom->connect;
4671
eval { $dbi->execute("drop table $table1") };
4672
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4673
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4674
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4675
eval { $dbi->execute("drop table $table2") };
4676
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4677
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4678
eval { $dbi->execute("drop table $table3") };
4679
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4680
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4681
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4682
  table => $table1,
4683
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4684
  where   => {"$table1.$key2" => 2},
4685
  join  => {
4686
    clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4687
    table => [$table1, $table2]
4688
  }
added test
Yuki Kimoto authored on 2011-10-27
4689
)->all;
4690
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
4691

            
4692
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4693
  table => $table1,
4694
  where   => {$key1 => 1},
4695
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4696
)->all;
4697
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4698

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

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

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

            
4725
$dbi = DBIx::Custom->connect;
4726
eval { $dbi->execute("drop table $table1") };
4727
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4728
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4729
eval { $dbi->execute("drop table $table2") };
4730
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4731
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4732
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4733
  table => $table1,
4734
  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",
4735
  where   => {"$table1.$key2" => 2},
4736
  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
4737
)->all;
4738
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
cleanup
Yuki Kimoto authored on 2012-01-20
4739
  'quote');
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4740

            
4741

            
4742
$dbi = DBIx::Custom->connect;
4743
eval { $dbi->execute("drop table $table1") };
4744
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4745
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4746
$sql = <<"EOS";
4747
left outer join (
cleanup
Yuki Kimoto authored on 2012-01-20
4748
select * from $table1 t1
4749
where t1.$key2 = (
4750
  select max(t2.$key2) from $table1 t2
4751
  where t1.$key1 = t2.$key1
4752
)
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4753
) $table3 on $table1.$key1 = $table3.$key1
4754
EOS
4755
$join = [$sql];
4756
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4757
  table => $table1,
4758
  column => "$table3.$key1 as ${table3}__$key1",
4759
  join  => $join
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4760
)->all;
4761
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4762

            
4763
$dbi = DBIx::Custom->connect;
4764
eval { $dbi->execute("drop table $table1") };
4765
eval { $dbi->execute("drop table $table2") };
4766
$dbi->execute($create_table1);
4767
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4768
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4769
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4770
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4771
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4772
  table => $table1,
4773
  join => [
4774
    "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4775
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4776
);
4777
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4778
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4779
  table => $table1,
4780
  column => [{$table2 => [$key3]}],
4781
  join => [
4782
    "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4783
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4784
);
4785
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4786
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4787
  table => $table1,
4788
  column => [{$table2 => [$key3]}],
4789
  join => [
4790
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4791
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4792
);
4793
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4794

            
4795
$dbi = DBIx::Custom->connect;
4796
eval { $dbi->execute("drop table $table1") };
4797
eval { $dbi->execute("drop table $table2") };
4798
$dbi->execute($create_table1);
4799
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4800
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4801
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4802
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4803
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4804
  table => $table1,
4805
  column => [{$table2 => [$key3]}],
4806
  join => [
4807
    {
4808
      clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4809
      table => [$table1, $table2]
4810
    }
4811
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4812
);
4813
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4814

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4815
$dbi = DBIx::Custom->connect;
4816
eval { $dbi->execute("drop table $table1") };
4817
eval { $dbi->execute("drop table $table2") };
4818
$dbi->execute($create_table1);
4819
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4820
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4821
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4822
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4823
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4824
  table => $table1,
4825
  column => [{$table2 => [$key3]}],
4826
  join => [
4827
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4828
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4829
);
4830
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4831

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4849
test 'columns';
4850
$dbi = MyDBI1->connect;
4851
$model = $dbi->model($table1);
4852

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4853
test 'count';
4854
$dbi = DBIx::Custom->connect;
4855
eval { $dbi->execute("drop table $table1") };
4856
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4857
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4858
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4859
is($dbi->count(table => $table1), 2);
4860
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4861
$model = $dbi->create_model(table => $table1);
4862
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4863

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4864
eval { $dbi->execute("drop table $table1") };
4865
eval { $dbi->execute("drop table $table2") };
4866
$dbi->execute($create_table1);
4867
$dbi->execute($create_table2);
4868
$model = $dbi->create_model(table => $table1, primary_key => $key1);
4869
$model->insert({$key1 => 1, $key2 => 2});
4870
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
4871
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4872
$model->insert({$key1 => 1, $key3 => 3});
4873
is($model->count(id => 1), 1);
4874
is($model->count(where => {"$table2.$key3" => 3}), 1);
4875

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