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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-15
92
require MyDBI1;
test cleanup
Yuki Kimoto authored on 2011-08-10
93
{
cleanup
Yuki Kimoto authored on 2012-01-20
94
  package MyDBI4;
test cleanup
Yuki Kimoto authored on 2011-08-10
95

            
cleanup
Yuki Kimoto authored on 2012-01-20
96
  use strict;
97
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
98

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
101
  sub connect {
102
    my $self = shift->SUPER::connect(@_);
103
    
104
    $self->include_model(
105
      MyModel2 => [
106
          $table1,
107
          {class => $table2, name => $table2}
108
      ]
109
    );
110
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
111

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
119
  package MyModel2::table1;
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 'MyModel2::Base1';
test cleanup
Yuki Kimoto authored on 2011-08-10
125

            
cleanup
Yuki Kimoto authored on 2012-01-20
126
  sub insert {
127
    my ($self, $param) = @_;
128
    
129
    return $self->SUPER::insert($param);
130
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
131

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
136
  use strict;
137
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-15
138

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
141
  sub insert {
142
    my ($self, $param) = @_;
143
    
144
    return $self->SUPER::insert($param);
145
  }
test cleanup
Yuki Kimoto authored on 2011-08-15
146

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
151
  use strict;
152
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-15
153

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
166
  use strict;
167
  use warnings;
168

            
169
  use base 'MyModel2::Base1';
170

            
171
  sub insert {
172
    my ($self, $param) = @_;
173
    
174
    return $self->SUPER::insert($param);
175
  }
176

            
177
  sub list { shift->select; }
test cleanup
Yuki Kimoto authored on 2011-08-10
178
}
179
{
cleanup
Yuki Kimoto authored on 2012-01-20
180
   package MyDBI5;
test cleanup
Yuki Kimoto authored on 2011-08-10
181

            
cleanup
Yuki Kimoto authored on 2012-01-20
182
  use strict;
183
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
184

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
187
  sub connect {
188
    my $self = shift->SUPER::connect(@_);
189
    
190
    $self->include_model('MyModel4');
191
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
192
}
193
{
cleanup
Yuki Kimoto authored on 2012-01-20
194
  package MyDBI6;
195
  
196
  use base 'DBIx::Custom';
197
  
198
  sub connect {
199
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
200
    
cleanup
Yuki Kimoto authored on 2012-01-20
201
    $self->include_model('MyModel5');
test cleanup
Yuki Kimoto authored on 2011-08-10
202
    
cleanup
Yuki Kimoto authored on 2012-01-20
203
    return $self;
204
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
205
}
206
{
cleanup
Yuki Kimoto authored on 2012-01-20
207
  package MyDBI7;
208
  
209
  use base 'DBIx::Custom';
210
  
211
  sub connect {
212
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
213
    
cleanup
Yuki Kimoto authored on 2012-01-20
214
    $self->include_model('MyModel6');
test cleanup
Yuki Kimoto authored on 2011-08-10
215
    
cleanup
Yuki Kimoto authored on 2012-01-20
216
    
217
    return $self;
218
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
219
}
220
{
cleanup
Yuki Kimoto authored on 2012-01-20
221
  package MyDBI8;
222
  
223
  use base 'DBIx::Custom';
224
  
225
  sub connect {
226
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
227
    
cleanup
Yuki Kimoto authored on 2012-01-20
228
    $self->include_model('MyModel7');
test cleanup
Yuki Kimoto authored on 2011-08-10
229
    
cleanup
Yuki Kimoto authored on 2012-01-20
230
    return $self;
231
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
232
}
233

            
234
{
cleanup
Yuki Kimoto authored on 2012-01-20
235
  package MyDBI9;
236
  
237
  use base 'DBIx::Custom';
238
  
239
  sub connect {
240
    my $self = shift->SUPER::connect(@_);
test cleanup
Yuki Kimoto authored on 2011-08-10
241
    
cleanup
Yuki Kimoto authored on 2012-01-20
242
    $self->include_model('MyModel8');
test cleanup
Yuki Kimoto authored on 2011-08-10
243
    
cleanup
Yuki Kimoto authored on 2012-01-20
244
    return $self;
245
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
246
}
247

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

            
added test
Yuki Kimoto authored on 2011-08-16
260
# Get user table info
261
$dbi = DBIx::Custom->connect;
262
eval { $dbi->execute("drop table $table1") };
263
eval { $dbi->execute("drop table $table2") };
264
eval { $dbi->execute("drop table $table3") };
265
$dbi->execute($create_table1);
266
$dbi->execute($create_table2);
267
$dbi->execute($create_table3);
268
$user_table_info = $dbi->get_table_info(exclude => $dbi->exclude_table);
269

            
cleanup test
Yuki Kimoto authored on 2011-08-15
270
# Create table
test cleanup
Yuki Kimoto authored on 2011-08-10
271
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
272
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
273
$dbi->execute($create_table1);
274
$model = $dbi->create_model(table => $table1);
275
$model->insert({$key1 => 1, $key2 => 2});
276
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-08-15
277

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
278
eval { $dbi->execute("drop table $table1") };
279
$dbi->execute($create_table1);
280
$model = $dbi->create_model(table => $table1);
281
$model->insert({$key1 => 1, $key2 => 2});
282
is_deeply($model->select($key1)->all, [{$key1 => 1}]);
283

            
cleanup test
Yuki Kimoto authored on 2011-08-15
284
test 'DBIx::Custom::Result test';
285
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
286
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
287
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
288
$source = "select $key1, $key2 from $table1";
289
$query = $dbi->create_query($source);
290
$result = $dbi->execute($query);
cleanup
Yuki Kimoto authored on 2011-08-15
291

            
cleanup test
Yuki Kimoto authored on 2011-08-15
292
@rows = ();
293
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
294
  push @rows, [@$row];
cleanup test
Yuki Kimoto authored on 2011-08-15
295
}
296
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
cleanup
Yuki Kimoto authored on 2011-08-15
297

            
cleanup test
Yuki Kimoto authored on 2011-08-15
298
$result = $dbi->execute($query);
299
@rows = ();
300
while (my $row = $result->fetch_hash) {
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, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
304

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
318
test 'Insert query return value';
319
$source = "insert into $table1 {insert_param $key1 $key2}";
320
$query = $dbi->execute($source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
321
$ret_val = $dbi->execute($query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
322
ok($ret_val);
test cleanup
Yuki Kimoto authored on 2011-08-10
323

            
cleanup test
Yuki Kimoto authored on 2011-08-15
324
test 'Direct query';
325
$dbi->delete_all(table => $table1);
326
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
test cleanup
Yuki Kimoto authored on 2011-11-01
327
$dbi->execute($insert_source, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
328
$result = $dbi->execute("select * from $table1");
329
$rows = $result->all;
330
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
331

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
337
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
338
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
339
$insert_query->filter({$key1 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
340
$dbi->execute($insert_query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
341
$result = $dbi->execute("select * from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
342
$rows = $result->filter({$key2 => 'three_times'})->all;
343
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
344

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added tests
Yuki Kimoto authored on 2011-11-01
485
eval { $dbi->execute("drop table $table1") };
486
$dbi->execute($create_table1);
487
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
488
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
489
$result = $dbi->execute("select * from $table1");
490
$rows   = $result->all;
491
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
492

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
520
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
521
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
522
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
test cleanup
Yuki Kimoto authored on 2011-11-01
523
$dbi->insert({select => 1}, table => 'table');
cleanup test
Yuki Kimoto authored on 2011-08-10
524
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
525
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
526
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
cleanup test
Yuki Kimoto authored on 2011-08-10
527

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

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

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

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

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

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

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

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
593
eval { $dbi->execute("drop table $table1") };
594
$dbi->execute($create_table1_2);
595
$param = {$key1 => 1};
596
$dbi->insert($param, table => $table1, ctime => $key2);
597
$result = $dbi->select(table => $table1);
598
is_deeply($param, {$key1 => 1});
599
$row   = $result->one;
600
is($row->{$key1}, 1);
601
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
602

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

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

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

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

            
647
eval { $dbi->execute("drop table $table1") };
648
$dbi->execute($create_table1_2);
649
$param = {$key1 => 1};
650
$dbi->insert($param, table => $table1, ctime => $key2, updated_at => $key3);
651
$result = $dbi->select(table => $table1);
652
is_deeply($param, {$key1 => 1});
653
$row   = $result->one;
654
is($row->{$key1}, 1);
655
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
656
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
657
is($row->{$key2}, $row->{$key3});
658

            
659
eval { $dbi->execute("drop table $table1") };
660
$dbi->execute($create_table1_2);
661
$param = {$key1 => 1};
662
$dbi->insert($param, table => $table1, ctime => $key2, mtime => $key3);
663
$result = $dbi->select(table => $table1);
664
is_deeply($param, {$key1 => 1});
665
$row   = $result->one;
666
is($row->{$key1}, 1);
667
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
668
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
669
is($row->{$key2}, $row->{$key3});
670

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
671
eval { $dbi->execute("drop table $table1") };
672
$dbi->execute($create_table1_2);
673
$model = $dbi->create_model(table => $table1, created_at => $key2);
674
$param = {$key1 => 1};
675
$model->insert($param);
676
$result = $dbi->select(table => $table1);
677
is_deeply($param, {$key1 => 1});
678
$row   = $result->one;
679
is($row->{$key1}, 1);
680
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
681

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

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

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

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

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

            
741
eval { $dbi->execute("drop table $table1") };
742
$dbi->execute($create_table1_2);
743
$param = {$key1 => 1};
744
$model = $dbi->create_model(table => $table1, ctime=> $key2, updated_at => $key3);
745
$model->insert($param);
746
$result = $dbi->select(table => $table1);
747
is_deeply($param, {$key1 => 1});
748
$row   = $result->one;
749
is($row->{$key1}, 1);
750
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
751
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
752
is($row->{$key2}, $row->{$key3});
753

            
754
eval { $dbi->execute("drop table $table1") };
755
$dbi->execute($create_table1_2);
756
$param = {$key1 => 1};
757
$model = $dbi->create_model(table => $table1, ctime=> $key2, mtime => $key3);
758
$model->insert($param);
759
$result = $dbi->select(table => $table1);
760
is_deeply($param, {$key1 => 1});
761
$row   = $result->one;
762
is($row->{$key1}, 1);
763
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
764
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
765
is($row->{$key2}, $row->{$key3});
766

            
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
767
eval { $dbi->execute("drop table $table1") };
768
$dbi->execute($create_table1);
769
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] , table => $table1);
770
$result = $dbi->execute("select * from $table1");
771
$rows   = $result->all;
772
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
773

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
814
test 'update_or_insert';
815
eval { $dbi->execute("drop table $table1") };
816
$dbi->execute($create_table1);
817
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
818
  {$key2 => 2},
819
  table => $table1,
820
  primary_key => $key1,
821
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
822
);
823
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
824
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
825

            
826
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
827
  {$key2 => 3},
828
  table => $table1,
829
  primary_key => $key1,
830
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
831
);
832
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
833
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
834

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
835
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
836
  $dbi->update_or_insert(
837
    {$key2 => 3},
838
    table => $table1,
839
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
840
};
841

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
844
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
845
  $dbi->insert({$key1 => 1}, table => $table1);
846
  $dbi->update_or_insert(
847
    {$key2 => 3},
848
    table => $table1,
849
    primary_key => $key1,
850
    id => 1
851
  );
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
852
};
853
like($@, qr/one/);
854

            
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
855
eval { $dbi->execute("drop table $table1") };
856
$dbi->execute($create_table1);
857
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
858
  {},
859
  table => $table1,
860
  primary_key => $key1,
861
  id => 1
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
862
);
863
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
864
is($row->{$key1}, 1);
865

            
866
eval { 
cleanup
Yuki Kimoto authored on 2012-01-20
867
  $affected = $dbi->update_or_insert(
868
    {},
869
    table => $table1,
870
    primary_key => $key1,
871
    id => 1
872
  );
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
873
};
874
is($affected, 0);
875

            
micro optimization
Yuki Kimoto authored on 2011-10-31
876
test 'model update_or_insert';
877
eval { $dbi->execute("drop table $table1") };
878
$dbi->execute($create_table1);
879
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
880
  table => $table1,
881
  primary_key => $key1
micro optimization
Yuki Kimoto authored on 2011-10-31
882
);
883
$model->update_or_insert({$key2 => 2}, id => 1);
884
$row = $model->select(id => 1)->one;
885
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
886

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
887
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
888
  $model->insert({$key1 => 1});
889
  $model->update_or_insert(
890
    {$key2 => 3},
891
    id => 1
892
  );
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
893
};
894
like($@, qr/one/);
895

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

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

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

            
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 : param is array ref");
test cleanup
Yuki Kimoto authored on 2011-08-10
948

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

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

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

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

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

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

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

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

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

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

            
1020
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1021
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1022
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
1023
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
1024
$dbi->insert({select => 1}, table => 'table');
1025
$dbi->update({update => 2}, table => 'table', where => {'table.select' => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1026
$result = $dbi->execute("select * from ${q}table$p");
1027
$rows   = $result->all;
1028
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
1029

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1204
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1205
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1206
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1207
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1208
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1209
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1210
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1211
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1212
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1213

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1225
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1226
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1227
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1228
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
1229
$rows = $dbi->select(table => $table1)->all;
1230
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1231

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1318
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1319
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
1320
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1321
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1322
  table => [$table1, $table2],
1323
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
1324
  where   => {"$table1.$key2" => 2},
1325
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1326
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1327
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], "relation : exists where");
test cleanup
Yuki Kimoto authored on 2011-08-10
1328

            
1329
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1330
  table => [$table1, $table2],
1331
  column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
1332
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1333
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1334
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}], "relation : no exists where");
test cleanup
Yuki Kimoto authored on 2011-08-10
1335

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

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
1345
eval { $dbi->execute("drop table $table1") };
1346
$dbi->execute($create_table1);
1347
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1348
$row = $dbi->select($key1, table => $table1)->one;
1349
is_deeply($row, {$key1 => 1});
1350

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

            
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
1354
eval { $dbi->execute("drop table $table1") };
1355
$dbi->execute($create_table1);
1356
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1357
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
1358
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
1359

            
1360
$rows = $dbi->select(table => $table1, where => {$key1 => [1, 5]})->all;
1361
is_deeply($rows, [
1362
  {$key1 => 1, $key2 => 2},
1363
  {$key1 => 5, $key2 => 6}
1364
], "table");
1365

            
1366
$rows = $dbi->select(table => $table1, where => {$key1 => []})->all;
1367
is_deeply($rows, [], "table");
1368

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1383
$dbi->default_fetch_filter('twice');
1384
eval { $dbi->execute("drop table $table1") };
1385
$dbi->execute($create_table1);
1386
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1387
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1388
$result->filter({$key1 => 'three_times'});
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1389
$row = $result->fetch_one;
1390
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter");
1391

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1398
test 'filters';
1399
$dbi = DBIx::Custom->new;
1400

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1407
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1408
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1409
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1410
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1411
$dbi->begin_work;
1412
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1413
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1414
$dbi->rollback;
1415
$dbi->dbh->{AutoCommit} = 1;
1416

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

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

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

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

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

            
1454
{
cleanup
Yuki Kimoto authored on 2012-01-20
1455
  local $Carp::Verbose = 0;
1456
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1457
  like($@, qr/\Q.t /, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1458
}
1459
{
cleanup
Yuki Kimoto authored on 2012-01-20
1460
  local $Carp::Verbose = 1;
1461
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1462
  like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1463
}
1464

            
1465

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1466
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1467
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1468
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1469
$dbi->execute($create_table1);
1470

            
1471
$dbi->begin_work;
1472

            
1473
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1474
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1475
  die "Error";
1476
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1477
};
1478

            
1479
$dbi->rollback if $@;
1480

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

            
1485
$dbi->begin_work;
1486

            
1487
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1488
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1489
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1490
};
1491

            
1492
$dbi->commit unless $@;
1493

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

            
1498
$dbi->dbh->{AutoCommit} = 0;
1499
eval{ $dbi->begin_work };
1500
ok($@, "exception");
1501
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1502

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1503
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1504
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1505
$dbi->cache(1);
1506
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1507
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1508
$dbi->execute($source, {}, query => 1);
1509
is_deeply($dbi->{_cached}->{$source}, 
cleanup
Yuki Kimoto authored on 2012-01-20
1510
  {sql => " select * from $table1 where $key1 = ?  and $key2 = ? ", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1511

            
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->execute($create_table1);
1514
$dbi->{_cached} = {};
1515
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1516
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1517
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1518

            
1519
test 'execute';
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
{
cleanup
Yuki Kimoto authored on 2012-01-20
1523
  local $Carp::Verbose = 0;
1524
  eval{$dbi->execute("select * frm $table1")};
1525
  like($@, qr/\Qselect * frm $table1/, "fail prepare");
1526
  like($@, qr/\.t /, "fail : not verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1527
}
1528
{
cleanup
Yuki Kimoto authored on 2012-01-20
1529
  local $Carp::Verbose = 1;
1530
  eval{$dbi->execute("select * frm $table1")};
1531
  like($@, qr/Custom.*\.t /s, "fail : verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1532
}
1533

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

            
1539
{
cleanup
Yuki Kimoto authored on 2012-01-20
1540
  local $Carp::Verbose = 0;
1541
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1542
  like($@, qr/\Q.t /, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1543
}
1544
{
cleanup
Yuki Kimoto authored on 2012-01-20
1545
  local $Carp::Verbose = 1;
1546
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1547
  like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1548
}
1549

            
1550
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1551
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1552
  one => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1553
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1554
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1555
  two => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1556
);
1557
$dbi->method({
cleanup
Yuki Kimoto authored on 2012-01-20
1558
  twice => sub {
1559
    my $self = shift;
1560
    return $_[0] * 2;
1561
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
1562
});
1563

            
1564
is($dbi->one, 1, "first");
1565
is($dbi->two, 2, "second");
1566
is($dbi->twice(5), 10 , "second");
1567

            
1568
eval {$dbi->XXXXXX};
1569
ok($@, "not exists");
1570

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

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

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

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

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

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

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

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

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

            
1695
$result->filter({$key2 => 'twice'});
1696
$rows   = $result->all;
1697
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1698

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

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

            
1708
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1709
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1710
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1711
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1712
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1713
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1714

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

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

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

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

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

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

            
1769
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1770
$result = $dbi->select(table => $table1);
1771
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1772
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1773
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1774
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1775

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

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1798
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1799
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1800
$result->filter($key1 => undef);
1801
$result->end_filter($key1 => undef);
1802
$row = $result->fetch;
1803
is_deeply($row, [1, 1, 40], 'apply_filter overwrite');
1804

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

            
1819
test 'empty where select';
1820
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1821
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1822
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1823
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1824
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1825
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1826
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1827

            
1828
test 'select query option';
1829
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1830
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1831
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1832
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1833
ok(ref $query);
cleanup
Yuki Kimoto authored on 2011-11-01
1834
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1835
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1836
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1837
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1838
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1839
ok(ref $query);
test cleanup
Yuki Kimoto authored on 2011-08-10
1840

            
1841
test 'where';
1842
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1843
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1844
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1845
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1846
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1847
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1848
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1849

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

            
1854
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1855
  table => $table1,
1856
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1857
);
1858
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1859
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1860

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

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

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

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

            
1901
$where = $dbi->where;
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}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1908

            
1909
eval {
1910
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1911
           ->clause(['uuu']);
test cleanup
Yuki Kimoto authored on 2011-08-10
1912
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1913
  table => $table1,
1914
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1915
);
1916
};
1917
ok($@);
1918

            
1919
$where = $dbi->where;
1920
is("$where", '');
1921

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2091
eval {$dbi->where(ppp => 1) };
2092
like($@, qr/invalid/);
2093

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

            
2105

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

            
2117
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2118
$where->clause(['and', ":${key1}{=}"]);
2119
$where->param({$key1 => undef});
2120
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
2121
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2122
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2123

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

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

            
2135
$dbi = DBIx::Custom->connect;
2136
eval { $dbi->execute("drop table $table1") };
2137
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2138
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
2139
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2140
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2141
  ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
2142
  ->param({$key1 => 1});
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2143

            
2144
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2145
  table => $table1,
2146
  where => $where
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2147
);
2148
$row = $result->all;
2149
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
2150

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2151
test 'register_tag_processor';
2152
$dbi = DBIx::Custom->connect;
2153
$dbi->register_tag_processor(
cleanup
Yuki Kimoto authored on 2012-01-20
2154
  a => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
2155
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2156
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2157

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2170
test 'more tests';
2171
$dbi = DBIx::Custom->connect;
2172
eval{$dbi->apply_filter('table', 'column', [])};
2173
like($@, qr/apply_filter/);
2174

            
2175
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
2176
like($@, qr/apply_filter/);
2177

            
2178
$dbi->apply_filter(
2179

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

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

            
2200
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2201
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2202
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2203
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2204
like($@, qr/not registered/);
2205
$dbi->method({one => sub { 1 }});
2206
is($dbi->one, 1);
2207

            
2208
eval{DBIx::Custom->connect(dsn => undef)};
2209
like($@, qr/_connect/);
2210

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

            
2223
$dbi->register_filter(one => sub { });
2224
$dbi->default_fetch_filter('one');
2225
ok($dbi->default_fetch_filter);
2226
$dbi->default_bind_filter('one');
2227
ok($dbi->default_bind_filter);
2228
eval{$dbi->default_fetch_filter('no')};
2229
like($@, qr/not registered/);
2230
eval{$dbi->default_bind_filter('no')};
2231
like($@, qr/not registered/);
2232
$dbi->default_bind_filter(undef);
2233
ok(!defined $dbi->default_bind_filter);
2234
$dbi->default_fetch_filter(undef);
2235
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2236
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2237
like($@, qr/Tag not finished/);
2238

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

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2253
test 'option';
2254
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
2255
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
2256
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2257
ok($dbi->dbh->{PrintError});
2258
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2259
ok($dbi->dbh->{PrintError});
2260

            
2261
test 'DBIx::Custom::Result stash()';
2262
$result = DBIx::Custom::Result->new;
2263
is_deeply($result->stash, {}, 'default');
2264
$result->stash->{foo} = 1;
2265
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2266

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2267
test 'delete_at';
2268
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2269
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2270
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2271
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2272
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2273
  table => $table1,
2274
  primary_key => [$key1, $key2],
2275
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2276
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2277
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2278

            
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,
2283
  where => 1,
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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2342
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2343
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2344
$dbi->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2345
  {$key3 => 4},
2346
  table => $table1,
2347
  primary_key => $key1,
2348
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2349
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2350
is($dbi->select(table => $table1)->one->{$key1}, 1);
2351
is($dbi->select(table => $table1)->one->{$key2}, 2);
2352
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2353

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2383
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2384
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2385
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2386
  table => $table1,
2387
  primary_key => $key1,
2388
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2389
);
2390
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2391
is($row->{$key1}, 1);
2392
is($row->{$key2}, 2);
2393
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2394

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

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

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

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

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

            
2465

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2485
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2486
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2487
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2488
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2489
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2490
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2491
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2492
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2493
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2494
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2495
is($dbi->select(table => $table1)->one->{$key1}, 1);
2496
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2497

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

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

            
2530
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2531
  column => [
2532
    $model->mycolumn([$key1]),
2533
    $model->column($table2 => [$key1])
2534
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2535
);
2536
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2537
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2538
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2539
  column => [
2540
    $model->mycolumn([$key1]),
2541
    {$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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2565
test 'merge_param';
2566
$dbi = DBIx::Custom->new;
2567
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2568
  {$key1 => 1, $key2 => 2, $key3 => 3},
2569
  {$key1 => 1, $key2 => 2},
2570
  {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2571
];
2572
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2573
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2574

            
2575
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2576
  {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2577
  {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2578
];
2579
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2580
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
2581

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
2602
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2603
  table => $table1,
2604
  column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2605
  where   => {"$table1.$key2" => 3},
2606
  join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2607
           " $table2 on $table1.$key1 = $table2.$key1",
2608
  param => {"$table2.$key3" => 5}
cleanup
Yuki Kimoto authored on 2011-10-21
2609
)->all;
2610
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2611

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
2639
$dbi = DBIx::Custom->connect;
2640
eval { $dbi->execute("drop table $table1") };
2641
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2642
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2643
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
2644
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2645
  table => $table1,
2646
  where => [
2647
    "$key1 = :$key1 and $key2 = :$key2",
2648
    {$key1 => 1, $key2 => 2}
2649
  ]
cleanup
Yuki Kimoto authored on 2011-10-21
2650
)->all;
2651
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2652

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

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

            
2682

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2726
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2727
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2728
  {$key2 => 2, $key3 => 3},
2729
  primary_key => $key1, 
2730
  table => $table1,
2731
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2732
);
2733

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2738
$dbi = DBIx::Custom->connect;
2739
eval { $dbi->execute("drop table $table1") };
2740
$dbi->execute($create_table1_2);
2741
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2742
  {$key3 => 3},
2743
  primary_key => [$key1, $key2], 
2744
  table => $table1,
2745
  id => 1,
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2746
);
2747
is($dbi->select(table => $table1)->one->{$key1}, 1);
2748
ok(!$dbi->select(table => $table1)->one->{$key2});
2749
is($dbi->select(table => $table1)->one->{$key3}, 3);
2750

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2751
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2752
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2753
$dbi->execute($create_table1_2);
2754
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2755
  {$key3 => 3},
2756
  primary_key => [$key1, $key2], 
2757
  table => $table1,
2758
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2759
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2760
is($dbi->select(table => $table1)->one->{$key1}, 1);
2761
is($dbi->select(table => $table1)->one->{$key2}, 2);
2762
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2763

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2764
$dbi = DBIx::Custom->connect;
2765
eval { $dbi->execute("drop table $table1") };
2766
$dbi->execute($create_table1_2);
2767
$param = {$key3 => 3, $key2 => 4};
2768
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2769
  $param,
2770
  primary_key => [$key1, $key2], 
2771
  table => $table1,
2772
  id => [1, 2],
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2773
);
2774
is($dbi->select(table => $table1)->one->{$key1}, 1);
2775
is($dbi->select(table => $table1)->one->{$key2}, 4);
2776
is($dbi->select(table => $table1)->one->{$key3}, 3);
2777
is_deeply($param, {$key3 => 3, $key2 => 4});
2778

            
added test
Yuki Kimoto authored on 2011-10-25
2779
$dbi = DBIx::Custom->connect;
2780
eval { $dbi->execute("drop table $table1") };
2781
$dbi->execute($create_table1_2);
2782
$param = {$key3 => 3, $key2 => 4};
2783
$query = $dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2784
  $param,
2785
  primary_key => [$key1, $key2], 
2786
  table => $table1,
2787
  id => [1, 2],
2788
  query => 1
added test
Yuki Kimoto authored on 2011-10-25
2789
);
micro optimization
Yuki Kimoto authored on 2011-11-16
2790
ok(ref $query);
added test
Yuki Kimoto authored on 2011-10-25
2791
is_deeply($param, {$key3 => 3, $key2 => 4});
2792

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2835
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2836
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2837
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2838
  {$key3 => 4},
2839
  table => $table1,
2840
  primary_key => $key1,
2841
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2842
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2843
is($dbi->select(table => $table1)->one->{$key1}, 0);
2844
is($dbi->select(table => $table1)->one->{$key2}, 2);
2845
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2846

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

            
2861

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

            
2877

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

            
cleanup
Yuki Kimoto authored on 2011-11-01
2890
$dbi->insert({$key1 => 0, $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,
2894
  id => 0,
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

            
2898

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

            
2917

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2933
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2934
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2935
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2936
  table => $table1,
2937
  primary_key => $key1,
2938
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2939
);
2940
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2941
is($row->{$key1}, 0);
2942
is($row->{$key2}, 2);
2943
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2944

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

            
2957

            
2958
test 'model select_at';
2959
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2960
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2961
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2962
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2963
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2964
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2965
is($row->{$key1}, 1);
2966
is($row->{$key2}, 2);
2967
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2968

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

            
2987
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2988
  column => [$model->column($table2 => [$key1, $key3])],
2989
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2990
);
2991
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2992
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2993

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2994
test 'separator';
2995
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2996
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2997
eval { $dbi->execute("drop table $table1") };
2998
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2999
$dbi->execute($create_table1);
3000
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
3001

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3027
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3028
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3029
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3030
  column => [
3031
    $model->mycolumn,
3032
    {$table2 => [$key1, $key3]}
3033
  ],
3034
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3035
);
3036
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3037
        {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3038
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3039

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

            
3053

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3062
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3063
  table => $table1,
3064
  join => [
3065
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3066
  ],
3067
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
3068
);
3069
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3070
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3071
$model = $dbi->model($table1);
3072
$result = $model->select(column => $key1);
3073
$result->filter($key1 => sub { $_[0] * 2 });
3074
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
3075

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3076
test 'available_datetype';
3077
$dbi = DBIx::Custom->connect;
3078
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
3079

            
3080

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3081
test 'select prefix option';
3082
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3083
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3084
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3085
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3086
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3087
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
3088

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

            
added tests
Yuki Kimoto authored on 2011-08-26
3090
test 'mapper';
3091
$dbi = DBIx::Custom->connect;
3092
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3093
  id => {key => "$table1.id"},
3094
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3095
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
3096
);
3097
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3098
"$table1.price" => 1900});
added tests
Yuki Kimoto authored on 2011-08-26
3099

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

            
added tests
Yuki Kimoto authored on 2011-08-26
3109
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3110
  id => {key => "$table1.id"},
3111
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3112
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
3113
);
3114
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
3115

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

            
3123
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3124
  id => {key => "$table1.id"},
3125
  price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
3126
);
3127
is_deeply($param, {"$table1.price" => undef});
3128

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

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

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3141
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3142
  price => sub { '%' . $_[0] },
3143
  author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
3144
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3145
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
3146

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

            
3152
$where = $dbi->where;
3153
$where->clause(['and', ":${key1}{=}"]);
3154
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
3155
$where->param($param);
3156
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3157
$row = $result->all;
3158
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3159

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

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

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3182
$where = $dbi->where;
3183
$where->clause(['and', ":${key1}{=}"]);
3184
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
cleanup
Yuki Kimoto authored on 2012-01-20
3185
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3186
$where->param($param);
3187
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3188
$row = $result->all;
3189
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3190

            
3191
$where = $dbi->where;
3192
$where->clause(['and', ":${key1}{=}"]);
3193
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
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}, {$key1 => 3, $key2 => 4}]);
3198

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

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

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

            
3217
$where = $dbi->where;
3218
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3219
  id => {key => "$table1.id"},
3220
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3221
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3222
);
3223
$where->param($param);
3224
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3225
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3226

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

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

            
3245
$where = $dbi->where;
3246
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3247
  id => {key => "$table1.id"},
3248
  price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3249
);
3250
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
3251

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

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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3291
test 'order';
3292
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3293
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3294
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3295
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3296
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3297
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3298
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3299
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3300
$order->prepend($key1, "$key2 desc");
3301
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3302
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
3303
{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3304
$order->prepend("$key1 desc");
3305
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3306
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
cleanup
Yuki Kimoto authored on 2012-01-20
3307
{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3308

            
3309
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3310
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3311
$result = $dbi->select(table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
3312
column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
3313
append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3314
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
cleanup
Yuki Kimoto authored on 2012-01-20
3315
{"$table1-$key1" => 1, "$table1-$key2" => 1},
3316
{"$table1-$key1" => 2, "$table1-$key2" => 4},
3317
{"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3318

            
3319
test 'tag_parse';
3320
$dbi = DBIx::Custom->connect;
3321
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3322
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3323
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3324
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3325
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3326
ok($@);
3327

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3328
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3329
{
cleanup
Yuki Kimoto authored on 2012-01-20
3330
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3331
  $dbi = DBIx::Custom->connect;
3332
  eval { $dbi->execute("drop table $table1") };
3333
  $dbi->execute($create_table1);
3334
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3335
  eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3336
  ok($@);
3337
  eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) };
3338
  ok($@);
3339
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3340
}
3341

            
3342
{
cleanup
Yuki Kimoto authored on 2012-01-20
3343
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3344
  $dbi = DBIx::Custom->connect;
3345
  eval { $dbi->execute("drop table $table1") };
3346
  $dbi->execute($create_table1);
3347
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3348
  is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1);
3349
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3350
}
3351

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3352
test 'last_sql';
3353
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3354
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3355
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3356
$dbi->execute("select * from $table1");
micro optimization
Yuki Kimoto authored on 2011-11-18
3357
is($dbi->last_sql, " select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3358

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3390
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3391
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
3392
  $source,
3393
  {"$table1.$key1" => 1, "$table1.$key2" => 1},
3394
  filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3395
);
3396
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3397
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3398

            
3399
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3400
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3401
$dbi->execute($create_table1_highperformance);
3402
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3403
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3404
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3405
];
3406
{
cleanup
Yuki Kimoto authored on 2012-01-20
3407
  my $query;
3408
  for my $row (@$rows) {
3409
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3410
    $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3411
  }
3412
  is_deeply($dbi->select(table => $table1)->all,
3413
    [
3414
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3415
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3416
    ]
3417
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3418
}
3419

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

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3442
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3443
$dbi->execute($create_table1_highperformance);
3444
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3445
  {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
3446
  {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3447
];
3448
{
cleanup
Yuki Kimoto authored on 2012-01-20
3449
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3450
  my $query;
3451
  for my $row (@$rows) {
3452
    $query ||= $model->insert($row, query => 1);
3453
    $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3454
  }
3455
  is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3456
    [
3457
      {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3458
      {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
3459
    ]
3460
  );
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3461
}
3462

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3463
eval { $dbi->execute("drop table $table1") };
3464
$dbi->execute($create_table1);
3465
{
cleanup
Yuki Kimoto authored on 2012-01-20
3466
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3467
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3468
  eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3469
  like($@, qr/primary_key/);
3470
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3471
}
3472

            
3473
{
cleanup
Yuki Kimoto authored on 2012-01-20
3474
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3475
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3476
  $model->insert({$key1 => 1});
3477
  $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3478
    table => $table1, primary_key => $key1);
3479
  is($result->one->{$key1}, 1);
3480
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3481
}
3482

            
3483
eval { $dbi->execute("drop table $table1") };
3484
$dbi->execute($create_table1);
3485
{
cleanup
Yuki Kimoto authored on 2012-01-20
3486
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3487
  $model->insert({$key1 => 1});
3488
  eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3489
  is($result->one->{$key1}, 1);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3490
}
3491

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3492
test 'id option more';
3493
eval { $dbi->execute("drop table $table1") };
3494
$dbi->execute($create_table1_highperformance);
3495
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3496
  $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
3497
};
3498
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3499
$model->insert($row);
3500
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3501
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3502
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3503
  {$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
3504
);
3505

            
3506
eval { $dbi->execute("drop table $table1") };
3507
eval { $dbi->execute("drop table $table2") };
3508
$dbi->execute($create_table1);
3509
$dbi->execute($create_table2);
3510
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3511
$model->insert({$key1 => 1, $key2 => 2});
3512
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
3513
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3514
$model->insert({$key1 => 1, $key3 => 3});
3515
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3516
  column => {$table1 => ["$key2"]},
3517
  id => 1
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3518
);
3519
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3520

            
3521
eval { $dbi->execute("drop table $table1") };
3522
$dbi->execute($create_table1_highperformance);
3523
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3524
  $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
3525
};
3526
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3527
$model->insert($row);
3528
$query = $model->delete(id => 1, query => 1);
3529
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3530
is_deeply($dbi->select(table => $table1)->all, []);
3531

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3546
test 'result';
3547
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3548
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3549
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3550
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3551
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3552

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3553
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3554
@rows = ();
3555
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
3556
  push @rows, [@$row];
test cleanup
Yuki Kimoto authored on 2011-08-10
3557
}
3558
is_deeply(\@rows, [[1, 2], [3, 4]]);
3559

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3560
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3561
@rows = ();
3562
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
3563
  push @rows, {%$row};
test cleanup
Yuki Kimoto authored on 2011-08-10
3564
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3565
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3566

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

            
3573
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3574
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3575
$rows = $result->fetch_all;
3576
is_deeply($rows, [[1, 2], [3, 4]]);
3577

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3582
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3583
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3584
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3585
$rows = $result->fetch_all;
3586
is_deeply($rows, [[3, 2], [9, 4]], "array");
3587

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2012-02-28
3600
test 'flat';
3601
$result = $dbi->select(table => $table1);
3602
$rows = [$result->flat];
3603
is_deeply($rows, [1, 2, 3, 4]);
3604

            
added EXPERIMETAL DBIx::Cust...
Yuki Kimoto authored on 2012-02-28
3605
test 'kv';
3606
$dbi = DBIx::Custom->connect;
3607
eval { $dbi->execute("drop table $table1") };
3608
$dbi->execute($create_table1);
3609
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3610
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3611

            
3612
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key1");
3613
$rows = $result->kv;
3614
is_deeply($rows, {0 => {$key2 => 2}, 3 => {$key2 => 4}});
3615

            
3616
$dbi = DBIx::Custom->connect;
3617
eval { $dbi->execute("drop table $table1") };
3618
$dbi->execute($create_table1);
3619
$dbi->insert({$key1 => 0, $key2 => 1}, table => $table1);
3620
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3621
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3622
$dbi->insert({$key1 => 3, $key2 => 5}, table => $table1);
3623

            
3624
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key2");
3625
$rows = $result->kv(multi => 1);
3626
is_deeply($rows, {
3627
  0 => [
3628
    {$key2 => 1},
3629
    {$key2 => 2}
3630
  ],
3631
  3 => [
3632
    {$key2 => 4},
3633
    {$key2 => 5}
3634
  ]
3635
});
3636

            
3637

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3638
test 'DBIx::Custom::Result fetch_multi';
3639
eval { $dbi->execute("drop table $table1") };
3640
$dbi->execute($create_table1);
3641
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3642
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3643
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3644
$result = $dbi->select(table => $table1);
3645
$rows = $result->fetch_multi(2);
3646
is_deeply($rows, [[1, 2], [3, 4]]);
3647
$rows = $result->fetch_multi(2);
3648
is_deeply($rows, [[5, 6]]);
3649
$rows = $result->fetch_multi(2);
3650
ok(!$rows);
3651

            
3652
test 'DBIx::Custom::Result fetch_hash_multi';
3653
eval { $dbi->execute("drop table $table1") };
3654
$dbi->execute($create_table1);
3655
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3656
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3657
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3658
$result = $dbi->select(table => $table1);
3659
$rows = $result->fetch_hash_multi(2);
3660
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3661
$rows = $result->fetch_hash_multi(2);
3662
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3663
$rows = $result->fetch_hash_multi(2);
3664
ok(!$rows);
3665

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3666
test "query_builder";
3667
$datas = [
cleanup
Yuki Kimoto authored on 2012-01-20
3668
  # Basic tests
3669
  {   name            => 'placeholder basic',
3670
    source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
3671
    sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
3672
    columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3673
  },
3674
  {
3675
    name            => 'placeholder in',
3676
    source            => "{in k1 3}",
3677
    sql_expected    => "k1 in (?, ?, ?)",
3678
    columns_expected   => [qw/k1 k1 k1/]
3679
  },
3680
  
3681
  # Table name
3682
  {
3683
    name            => 'placeholder with table name',
3684
    source            => "{= a.k1} {= a.k2}",
3685
    sql_expected    => "a.k1 = ? a.k2 = ?",
3686
    columns_expected  => [qw/a.k1 a.k2/]
3687
  },
3688
  {   
3689
    name            => 'placeholder in with table name',
3690
    source            => "{in a.k1 2} {in b.k2 2}",
3691
    sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
3692
    columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3693
  },
3694
  {
3695
    name            => 'not contain tag',
3696
    source            => "aaa",
3697
    sql_expected    => "aaa",
3698
    columns_expected  => [],
3699
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3700
];
3701

            
3702
for (my $i = 0; $i < @$datas; $i++) {
cleanup
Yuki Kimoto authored on 2012-01-20
3703
  my $data = $datas->[$i];
3704
  my $dbi = DBIx::Custom->new;
3705
  my $builder = $dbi->query_builder;
3706
  my $query = $builder->build_query($data->{source});
3707
  is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3708
  is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3709
}
3710

            
cleanup
Yuki Kimoto authored on 2011-08-13
3711
$dbi = DBIx::Custom->new;
3712
$builder = $dbi->query_builder;
3713
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
3714
  p => sub {
3715
    my @args = @_;
3716
    
3717
    my $expand    = "? $args[0] $args[1]";
3718
    my $columns = [2];
3719
    return [$expand, $columns];
3720
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3721
);
3722

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3733
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3734
  q => 'string'
test cleanup
Yuki Kimoto authored on 2011-08-10
3735
});
3736

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3740
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3741
  r => sub {} 
test cleanup
Yuki Kimoto authored on 2011-08-10
3742
});
3743

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

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

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

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

            
3758

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

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

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

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

            
3774
test 'variouse source';
3775
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3776
$query = $builder->build_query($source);
3777
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3778

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

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

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

            
3791
$source = "a {= b} }";
3792
eval{$builder->build_query($source)};
3793
like($@, qr/unexpected "}"/, "error : 1");
3794

            
3795
$source = "a {= {}";
3796
eval{$builder->build_query($source)};
3797
like($@, qr/unexpected "{"/, "error : 2");
3798

            
3799
test 'select() sqlfilter option';
3800
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3801
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3802
eval { $dbi->execute("drop table $table1") };
3803
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3804
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3805
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3806
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3807
  table => $table1,
3808
  column => $key1,
3809
  sqlfilter => sub {
3810
    my $sql = shift;
3811
    $sql = "select * from ( $sql ) t where $key1 = 1";
3812
    return $sql;
3813
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3814
)->all;
3815
is_deeply($rows, [{$key1 => 1}]);
3816

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3835
test 'dbi method from model';
3836
$dbi = MyDBI9->connect;
3837
eval { $dbi->execute("drop table $table1") };
3838
$dbi->execute($create_table1);
3839
$dbi->setup_model;
3840
$model = $dbi->model($table1);
3841
eval{$model->execute("select * from $table1")};
3842
ok(!$@);
3843

            
3844
test 'column table option';
3845
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3846
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3847
eval { $dbi->execute("drop table $table1") };
3848
$dbi->execute($create_table1);
3849
eval { $dbi->execute("drop table $table2") };
3850
$dbi->execute($create_table2);
3851
$dbi->setup_model;
3852
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3853
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3854
$model = $dbi->model($table1);
3855
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3856
  column => [
3857
    $model->column($table2, {alias => $table2_alias})
3858
  ],
3859
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3860
);
3861
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3862
        {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3863

            
3864
$dbi->separator('__');
3865
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3866
  column => [
3867
    $model->column($table2, {alias => $table2_alias})
3868
  ],
3869
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3870
);
3871
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3872
  {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3873

            
3874
$dbi->separator('-');
3875
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3876
  column => [
3877
      $model->column($table2, {alias => $table2_alias})
3878
  ],
3879
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3880
);
3881
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3882
  {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3883

            
3884
test 'create_model';
3885
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3886
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3887
eval { $dbi->execute("drop table $table1") };
3888
eval { $dbi->execute("drop table $table2") };
3889
$dbi->execute($create_table1);
3890
$dbi->execute($create_table2);
3891

            
3892
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3893
  table => $table1,
3894
  join => [
3895
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3896
  ],
3897
  primary_key => [$key1]
cleanup test
Yuki Kimoto authored on 2011-08-15
3898
);
3899
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3900
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3901
);
3902
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3903
  table => $table3,
3904
  filter => [
3905
    $key1 => {in => sub { uc $_[0] }}
3906
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
3907
);
3908
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3909
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3910
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3911
$model = $dbi->model($table1);
3912
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3913
  column => [$model->mycolumn, $model->column($table2)],
3914
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-15
3915
);
3916
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3917
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3918
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3919

            
3920
test 'model method';
3921
$dbi = DBIx::Custom->connect;
3922
eval { $dbi->execute("drop table $table2") };
3923
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3924
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3925
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3926
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3927
);
3928
$model->method(foo => sub { shift->select(@_) });
3929
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3930

            
3931
test 'model helper';
3932
$dbi = DBIx::Custom->connect;
3933
eval { $dbi->execute("drop table $table2") };
3934
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3935
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3936
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3937
  table => $table2
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3938
);
3939
$model->helper(foo => sub { shift->select(@_) });
3940
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3941

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

            
3949
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3950
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3951
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3952
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3953
where $key1 = 1
3954
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3955
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3956
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3957
$rows   = $result->all;
3958
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3959
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3960
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
3961

            
3962

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

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4034
test 'Model class';
4035
$dbi = MyDBI1->connect;
4036
eval { $dbi->execute("drop table $table1") };
4037
$dbi->execute($create_table1);
4038
$model = $dbi->model($table1);
4039
$model->insert({$key1 => 'a', $key2 => 'b'});
4040
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4041
eval { $dbi->execute("drop table $table2") };
4042
$dbi->execute($create_table2);
4043
$model = $dbi->model($table2);
4044
$model->insert({$key1 => 'a'});
4045
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4046
is($dbi->models->{$table1}, $dbi->model($table1));
4047
is($dbi->models->{$table2}, $dbi->model($table2));
4048

            
4049
$dbi = MyDBI4->connect;
4050
eval { $dbi->execute("drop table $table1") };
4051
$dbi->execute($create_table1);
4052
$model = $dbi->model($table1);
4053
$model->insert({$key1 => 'a', $key2 => 'b'});
4054
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4055
eval { $dbi->execute("drop table $table2") };
4056
$dbi->execute($create_table2);
4057
$model = $dbi->model($table2);
4058
$model->insert({$key1 => 'a'});
4059
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4060

            
4061
$dbi = MyDBI5->connect;
4062
eval { $dbi->execute("drop table $table1") };
4063
eval { $dbi->execute("drop table $table2") };
4064
$dbi->execute($create_table1);
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}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
4069
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4070
$model = $dbi->model($table1);
4071
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
4072

            
4073
test 'primary_key';
4074
$dbi = MyDBI1->connect;
4075
$model = $dbi->model($table1);
4076
$model->primary_key([$key1, $key2]);
4077
is_deeply($model->primary_key, [$key1, $key2]);
4078

            
4079
test 'columns';
4080
$dbi = MyDBI1->connect;
4081
$model = $dbi->model($table1);
4082
$model->columns([$key1, $key2]);
4083
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4084

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4085
test 'setup_model';
4086
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
4087
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4088
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4089
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
4090

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4091
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4092
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4093
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
4094
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
4095
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4096

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4097
test 'each_column';
4098
$dbi = DBIx::Custom->connect;
4099
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4100
eval { $dbi->execute("drop table $table1") };
4101
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4102
eval { $dbi->execute("drop table $table3") };
4103
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4104
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4105

            
4106
$infos = [];
4107
$dbi->each_column(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4108
  my ($self, $table, $column, $cinfo) = @_;
4109
  
4110
  if ($table =~ /^table\d/i) {
4111
     my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
4112
     push @$infos, $info;
4113
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4114
});
4115
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4116
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4117
  [
4118
    [$table1, $key1, $key1],
4119
    [$table1, $key2, $key2],
4120
    [$table2, $key1, $key1],
4121
    [$table2, $key3, $key3]
4122
  ]
4123
  
cleanup test
Yuki Kimoto authored on 2011-08-10
4124
);
cleanup test
Yuki Kimoto authored on 2011-08-16
4125

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4126
test 'each_table';
4127
$dbi = DBIx::Custom->connect;
4128
eval { $dbi->execute("drop table $table1") };
4129
eval { $dbi->execute("drop table $table2") };
4130
$dbi->execute($create_table2);
4131
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4132

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

            
cleanup test
Yuki Kimoto authored on 2011-08-16
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);
4155

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4175
test 'type_rule into';
4176
eval { $dbi->execute("drop table $table1") };
4177
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4178
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
4179

            
4180

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4181
$dbi = DBIx::Custom->connect;
4182
eval { $dbi->execute("drop table $table1") };
4183
$dbi->execute($create_table1_type);
4184

            
cleanup
Yuki Kimoto authored on 2011-08-16
4185
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4186
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4187
  into1 => {
4188
    $date_typename => sub { '2010-' . $_[0] }
4189
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4190
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4191
$dbi->insert({$key1 => '01-01'}, table => $table1);
4192
$result = $dbi->select(table => $table1);
4193
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4194

            
4195
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4196
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4197
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4198
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4199
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4200
  into1 => [
4201
     [$date_typename, $datetime_typename] => sub {
4202
        my $value = shift;
4203
        $value =~ s/02/03/g;
4204
        return $value;
4205
     }
4206
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
4207
);
4208
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
4209
$result = $dbi->select(table => $table1);
4210
$row = $result->one;
4211
like($row->{$key1}, qr/^2010-01-03/);
4212
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4213

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

            
4236
$dbi = DBIx::Custom->connect;
4237
eval { $dbi->execute("drop table $table1") };
4238
$dbi->execute($create_table1_type);
4239
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4240
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4241
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4242
  into1 => [
4243
    [$date_typename, $datetime_typename] => sub {
4244
      my $value = shift;
4245
      $value =~ s/02/03/g;
4246
      return $value;
4247
    }
4248
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4249
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4250
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
4251
  "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
4252
  {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
4253
  table => $table1
cleanup test
Yuki Kimoto authored on 2011-08-15
4254
);
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->register_filter(convert => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4263
  my $value = shift || '';
4264
  $value =~ s/02/03/;
4265
  return $value;
cleanup test
Yuki Kimoto authored on 2011-08-15
4266
});
cleanup
Yuki Kimoto authored on 2011-08-16
4267
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4268
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4269
  from1 => {
4270
    $date_datatype => 'convert',
4271
  },
4272
  into1 => {
4273
      $date_typename => 'convert',
4274
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4275
);
4276
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
4277
$result = $dbi->select(table => $table1);
4278
like($result->fetch->[0], qr/^2010-03-03/);
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
4279
$result = $dbi->select(column => [$key1, $key1], table => $table1);
4280
$row = $result->fetch;
4281
like($row->[0], qr/^2010-03-03/);
4282
like($row->[1], qr/^2010-03-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4283

            
4284
test 'type_rule and filter order';
4285
$dbi = DBIx::Custom->connect;
4286
eval { $dbi->execute("drop table $table1") };
4287
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4288
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4289
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4290
  into1 => {
4291
    $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4292
  },
4293
  into2 => {
4294
    $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4295
  },
4296
  from1 => {
4297
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4298
  },
4299
  from2 => {
4300
    $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
4301
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4302
);
4303
$dbi->insert({$key1 => '2010-01-03'}, 
cleanup
Yuki Kimoto authored on 2012-01-20
4304
table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
cleanup test
Yuki Kimoto authored on 2011-08-15
4305
$result = $dbi->select(table => $table1);
4306
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4307
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4308

            
4309

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4336
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
4337
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
4338
eval { $dbi->execute("drop table $table1") };
4339
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4340
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4341
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4342
  from1 => {
4343
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4344
  },
4345
  into1 => {
4346
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4347
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4348
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4349
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4350
$result = $dbi->select(table => $table1, type_rule_off => 1);
4351
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4352

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4353
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4354
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4355
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4356
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4357
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4358
  from1 => {
4359
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4360
  },
4361
  into1 => {
4362
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4363
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4364
);
4365
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4366
$result = $dbi->select(table => $table1, type_rule_off => 1);
4367
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4368

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4415
eval{$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4416
  into1 => {
4417
    $date_typename => 'pp'
4418
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4419
)};
4420
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4421

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4422
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4423
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4424
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4425
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4426
  $dbi->type_rule(
4427
    from1 => {
4428
      Date => sub { $_[0] * 2 },
4429
    }
4430
  );
cleanup test
Yuki Kimoto authored on 2011-08-10
4431
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4432
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4433

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4434
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4435
  $dbi->type_rule(
4436
    into1 => {
4437
      Date => sub { $_[0] * 2 },
4438
    }
4439
  );
cleanup test
Yuki Kimoto authored on 2011-08-15
4440
};
4441
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4442

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

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

            
4481
$result = $dbi->select(table => $table1);
4482
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4483
  from1 => {
4484
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4485
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4486
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4487
$row = $result->one;
4488
like($row->{$key1}, qr/2010-01-05/);
4489
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4490

            
4491
$result = $dbi->select(table => $table1);
4492
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4493
  from1 => {
4494
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4495
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4496
);
4497
$row = $result->one;
4498
like($row->{$key1}, qr/2010-01-05/);
4499
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4500

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

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

            
4518
$result = $dbi->select(table => $table1);
4519
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4520
  from1 => [$date_datatype => undef]
cleanup test
Yuki Kimoto authored on 2011-08-15
4521
);
4522
$row = $result->one;
4523
like($row->{$key1}, qr/^2010-01-03/);
4524
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4525

            
4526
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4527
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4528
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4529
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4530
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4531
  from1 => {
4532
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4533
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4534
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4535
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4536
$result = $dbi->select(table => $table1);
4537
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4538
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4539

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4554
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4555
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4556
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4557
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4558
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4559
  into1 => {
4560
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4561
  },
4562
  into2 => {
4563
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4564
  },
4565
  from1 => {
4566
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4567
  },
4568
  from2 => {
4569
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4570
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4571
);
4572
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4573
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4574
like($result->type_rule_off->fetch_one->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4575
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4576
like($result->type_rule_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4577

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4626
test 'join';
4627
$dbi = DBIx::Custom->connect;
4628
eval { $dbi->execute("drop table $table1") };
4629
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4630
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4631
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4632
eval { $dbi->execute("drop table $table2") };
4633
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4634
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4635
eval { $dbi->execute("drop table $table3") };
4636
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4637
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4638
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4639
  table => $table1,
4640
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4641
  where   => {"$table1.$key2" => 2},
4642
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4643
)->all;
4644
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4645

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

            
4668
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4669
  table => $table1,
4670
  where   => {$key1 => 1},
4671
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4672
)->all;
4673
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4674

            
4675
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4676
  table => $table1,
4677
  where   => {$key1 => 1},
4678
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4679
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4680
)->all;
4681
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4682

            
4683
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4684
  column => "$table3.$key4 as ${table3}__$key4",
4685
  table => $table1,
4686
  where   => {"$table1.$key1" => 1},
4687
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4688
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4689
)->all;
4690
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4691

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

            
4701
$dbi = DBIx::Custom->connect;
4702
eval { $dbi->execute("drop table $table1") };
4703
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4704
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4705
eval { $dbi->execute("drop table $table2") };
4706
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4707
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4708
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4709
  table => $table1,
4710
  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",
4711
  where   => {"$table1.$key2" => 2},
4712
  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
4713
)->all;
4714
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
cleanup
Yuki Kimoto authored on 2012-01-20
4715
  'quote');
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4716

            
4717

            
4718
$dbi = DBIx::Custom->connect;
4719
eval { $dbi->execute("drop table $table1") };
4720
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4721
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4722
$sql = <<"EOS";
4723
left outer join (
cleanup
Yuki Kimoto authored on 2012-01-20
4724
select * from $table1 t1
4725
where t1.$key2 = (
4726
  select max(t2.$key2) from $table1 t2
4727
  where t1.$key1 = t2.$key1
4728
)
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4729
) $table3 on $table1.$key1 = $table3.$key1
4730
EOS
4731
$join = [$sql];
4732
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4733
  table => $table1,
4734
  column => "$table3.$key1 as ${table3}__$key1",
4735
  join  => $join
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4736
)->all;
4737
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4738

            
4739
$dbi = DBIx::Custom->connect;
4740
eval { $dbi->execute("drop table $table1") };
4741
eval { $dbi->execute("drop table $table2") };
4742
$dbi->execute($create_table1);
4743
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4744
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4745
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4746
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4747
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4748
  table => $table1,
4749
  join => [
4750
    "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4751
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4752
);
4753
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4754
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4755
  table => $table1,
4756
  column => [{$table2 => [$key3]}],
4757
  join => [
4758
    "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4759
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4760
);
4761
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4762
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4763
  table => $table1,
4764
  column => [{$table2 => [$key3]}],
4765
  join => [
4766
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4767
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4768
);
4769
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4770

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

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4791
$dbi = DBIx::Custom->connect;
4792
eval { $dbi->execute("drop table $table1") };
4793
eval { $dbi->execute("drop table $table2") };
4794
$dbi->execute($create_table1);
4795
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4796
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4797
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4798
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4799
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4800
  table => $table1,
4801
  column => [{$table2 => [$key3]}],
4802
  join => [
4803
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4804
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4805
);
4806
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4807

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4825
test 'columns';
4826
$dbi = MyDBI1->connect;
4827
$model = $dbi->model($table1);
4828

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4829
test 'count';
4830
$dbi = DBIx::Custom->connect;
4831
eval { $dbi->execute("drop table $table1") };
4832
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4833
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4834
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4835
is($dbi->count(table => $table1), 2);
4836
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4837
$model = $dbi->create_model(table => $table1);
4838
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4839

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4840
eval { $dbi->execute("drop table $table1") };
4841
eval { $dbi->execute("drop table $table2") };
4842
$dbi->execute($create_table1);
4843
$dbi->execute($create_table2);
4844
$model = $dbi->create_model(table => $table1, primary_key => $key1);
4845
$model->insert({$key1 => 1, $key2 => 2});
4846
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
4847
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4848
$model->insert({$key1 => 1, $key3 => 3});
4849
is($model->count(id => 1), 1);
4850
is($model->count(where => {"$table2.$key3" => 3}), 1);
4851

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