DBIx-Custom / t / common.t /
Newer Older
4875 lines | 159.971kb
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);
test cleanup
Yuki Kimoto authored on 2011-08-10
1328
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1329
  table => [$table1, $table2],
fixed test
Yuki Kimoto authored on 2012-03-01
1330
  column => "$table1.$key1 as " . u("${table1}_$key1")
1331
    . ", $table2.$key1 as " . u("${table2}_$key1") . ", $key2, $key3",
cleanup
Yuki Kimoto authored on 2012-01-20
1332
  where   => {"$table1.$key2" => 2},
1333
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1334
)->all;
fixed test
Yuki Kimoto authored on 2012-03-01
1335
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
1336

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1473

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

            
1479
$dbi->begin_work;
1480

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

            
1487
$dbi->rollback if $@;
1488

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

            
1493
$dbi->begin_work;
1494

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

            
1500
$dbi->commit unless $@;
1501

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2113

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

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

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

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

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

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

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

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

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

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

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

            
2186
$dbi->apply_filter(
2187

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2350
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2351
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2352
$dbi->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2353
  {$key3 => 4},
2354
  table => $table1,
2355
  primary_key => $key1,
2356
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2357
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2358
is($dbi->select(table => $table1)->one->{$key1}, 1);
2359
is($dbi->select(table => $table1)->one->{$key2}, 2);
2360
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2361

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2391
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2392
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2393
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2394
  table => $table1,
2395
  primary_key => $key1,
2396
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2397
);
2398
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2399
is($row->{$key1}, 1);
2400
is($row->{$key2}, 2);
2401
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2402

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

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

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

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

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

            
2473

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2690

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2843
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2844
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2845
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2846
  {$key3 => 4},
2847
  table => $table1,
2848
  primary_key => $key1,
2849
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2850
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2851
is($dbi->select(table => $table1)->one->{$key1}, 0);
2852
is($dbi->select(table => $table1)->one->{$key2}, 2);
2853
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2854

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

            
2869

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

            
2885

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

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

            
2906

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

            
2925

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2941
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2942
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2943
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2944
  table => $table1,
2945
  primary_key => $key1,
2946
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2947
);
2948
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2949
is($row->{$key1}, 0);
2950
is($row->{$key2}, 2);
2951
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2952

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

            
2965

            
2966
test 'model select_at';
2967
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2968
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2969
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2970
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2971
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2972
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2973
is($row->{$key1}, 1);
2974
is($row->{$key2}, 2);
2975
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2976

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

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

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

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

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

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

            
3061

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

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

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

            
3088

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3660

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3781

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3985

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4203

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

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

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

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

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

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

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

            
4332

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4740

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

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

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

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

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

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

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

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

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