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

            
- DBIx::Custom::Mapper::map ...
Yuki Kimoto authored on 2012-02-29
3291
$param = $dbi->mapper(param => {author => 'Ken',})->map(
3292
  author => ["$table1.author" => '%<value>%'],
3293
);
3294
is_deeply($param, {"$table1.author" => '%Ken%'});
3295

            
3296
$param = $dbi->mapper(param => {author => 'Ken'})->map(
3297
  author => ["$table1.author" => 'p'],
3298
);
3299
is_deeply($param, {"$table1.author" => 'p'});
3300

            
3301
$param = $dbi->mapper(param => {author => 'Ken',})->map(
3302
  author => {value => '%<value>%'}
3303
);
3304
is_deeply($param, {"author" => '%Ken%'});
3305

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

            
3324
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3325
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3326
$result = $dbi->select(table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
3327
column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
3328
append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3329
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
cleanup
Yuki Kimoto authored on 2012-01-20
3330
{"$table1-$key1" => 1, "$table1-$key2" => 1},
3331
{"$table1-$key1" => 2, "$table1-$key2" => 4},
3332
{"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3333

            
3334
test 'tag_parse';
3335
$dbi = DBIx::Custom->connect;
3336
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3337
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3338
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3339
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3340
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3341
ok($@);
3342

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3343
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3344
{
cleanup
Yuki Kimoto authored on 2012-01-20
3345
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3346
  $dbi = DBIx::Custom->connect;
3347
  eval { $dbi->execute("drop table $table1") };
3348
  $dbi->execute($create_table1);
3349
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3350
  eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3351
  ok($@);
3352
  eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) };
3353
  ok($@);
3354
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3355
}
3356

            
3357
{
cleanup
Yuki Kimoto authored on 2012-01-20
3358
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3359
  $dbi = DBIx::Custom->connect;
3360
  eval { $dbi->execute("drop table $table1") };
3361
  $dbi->execute($create_table1);
3362
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3363
  is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1);
3364
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3365
}
3366

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3367
test 'last_sql';
3368
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3369
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3370
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3371
$dbi->execute("select * from $table1");
micro optimization
Yuki Kimoto authored on 2011-11-18
3372
is($dbi->last_sql, " select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3373

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

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

            
3384
test 'Named placeholder :name(operater) syntax';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3385
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3386
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
3387
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
3388
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
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 :${key1}{=} and :${key2}{=}";
cleanup
Yuki Kimoto authored on 2011-11-01
3391
$result = $dbi->execute($source, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
3392
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3393
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3394

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

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

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

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

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

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

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3478
eval { $dbi->execute("drop table $table1") };
3479
$dbi->execute($create_table1);
3480
{
cleanup
Yuki Kimoto authored on 2012-01-20
3481
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3482
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3483
  eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3484
  like($@, qr/primary_key/);
3485
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3486
}
3487

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

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

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

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

            
3536
eval { $dbi->execute("drop table $table1") };
3537
$dbi->execute($create_table1_highperformance);
3538
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3539
  $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
3540
};
3541
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3542
$model->insert($row);
3543
$query = $model->delete(id => 1, query => 1);
3544
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3545
is_deeply($dbi->select(table => $table1)->all, []);
3546

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3561
test 'result';
3562
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3563
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3564
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3565
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3566
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3567

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3568
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3569
@rows = ();
3570
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
3571
  push @rows, [@$row];
test cleanup
Yuki Kimoto authored on 2011-08-10
3572
}
3573
is_deeply(\@rows, [[1, 2], [3, 4]]);
3574

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3575
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3576
@rows = ();
3577
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
3578
  push @rows, {%$row};
test cleanup
Yuki Kimoto authored on 2011-08-10
3579
}
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

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

            
3588
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3589
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3590
$rows = $result->fetch_all;
3591
is_deeply($rows, [[1, 2], [3, 4]]);
3592

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

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

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2012-02-28
3615
test 'flat';
3616
$result = $dbi->select(table => $table1);
3617
$rows = [$result->flat];
3618
is_deeply($rows, [1, 2, 3, 4]);
3619

            
added EXPERIMETAL DBIx::Cust...
Yuki Kimoto authored on 2012-02-28
3620
test 'kv';
3621
$dbi = DBIx::Custom->connect;
3622
eval { $dbi->execute("drop table $table1") };
3623
$dbi->execute($create_table1);
3624
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3625
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3626

            
3627
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key1");
3628
$rows = $result->kv;
3629
is_deeply($rows, {0 => {$key2 => 2}, 3 => {$key2 => 4}});
3630

            
3631
$dbi = DBIx::Custom->connect;
3632
eval { $dbi->execute("drop table $table1") };
3633
$dbi->execute($create_table1);
3634
$dbi->insert({$key1 => 0, $key2 => 1}, table => $table1);
3635
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3636
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3637
$dbi->insert({$key1 => 3, $key2 => 5}, table => $table1);
3638

            
3639
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key2");
3640
$rows = $result->kv(multi => 1);
3641
is_deeply($rows, {
3642
  0 => [
3643
    {$key2 => 1},
3644
    {$key2 => 2}
3645
  ],
3646
  3 => [
3647
    {$key2 => 4},
3648
    {$key2 => 5}
3649
  ]
3650
});
3651

            
3652

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3653
test 'DBIx::Custom::Result fetch_multi';
3654
eval { $dbi->execute("drop table $table1") };
3655
$dbi->execute($create_table1);
3656
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3657
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3658
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3659
$result = $dbi->select(table => $table1);
3660
$rows = $result->fetch_multi(2);
3661
is_deeply($rows, [[1, 2], [3, 4]]);
3662
$rows = $result->fetch_multi(2);
3663
is_deeply($rows, [[5, 6]]);
3664
$rows = $result->fetch_multi(2);
3665
ok(!$rows);
3666

            
3667
test 'DBIx::Custom::Result fetch_hash_multi';
3668
eval { $dbi->execute("drop table $table1") };
3669
$dbi->execute($create_table1);
3670
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3671
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3672
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3673
$result = $dbi->select(table => $table1);
3674
$rows = $result->fetch_hash_multi(2);
3675
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3676
$rows = $result->fetch_hash_multi(2);
3677
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3678
$rows = $result->fetch_hash_multi(2);
3679
ok(!$rows);
3680

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

            
3717
for (my $i = 0; $i < @$datas; $i++) {
cleanup
Yuki Kimoto authored on 2012-01-20
3718
  my $data = $datas->[$i];
3719
  my $dbi = DBIx::Custom->new;
3720
  my $builder = $dbi->query_builder;
3721
  my $query = $builder->build_query($data->{source});
3722
  is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3723
  is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3724
}
3725

            
cleanup
Yuki Kimoto authored on 2011-08-13
3726
$dbi = DBIx::Custom->new;
3727
$builder = $dbi->query_builder;
3728
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
3729
  p => sub {
3730
    my @args = @_;
3731
    
3732
    my $expand    = "? $args[0] $args[1]";
3733
    my $columns = [2];
3734
    return [$expand, $columns];
3735
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3736
);
3737

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3748
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3749
  q => 'string'
test cleanup
Yuki Kimoto authored on 2011-08-10
3750
});
3751

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3755
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3756
  r => sub {} 
test cleanup
Yuki Kimoto authored on 2011-08-10
3757
});
3758

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

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

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

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

            
3773

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

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

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

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

            
3789
test 'variouse source';
3790
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3791
$query = $builder->build_query($source);
3792
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3793

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

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

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

            
3806
$source = "a {= b} }";
3807
eval{$builder->build_query($source)};
3808
like($@, qr/unexpected "}"/, "error : 1");
3809

            
3810
$source = "a {= {}";
3811
eval{$builder->build_query($source)};
3812
like($@, qr/unexpected "{"/, "error : 2");
3813

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3850
test 'dbi method from model';
3851
$dbi = MyDBI9->connect;
3852
eval { $dbi->execute("drop table $table1") };
3853
$dbi->execute($create_table1);
3854
$dbi->setup_model;
3855
$model = $dbi->model($table1);
3856
eval{$model->execute("select * from $table1")};
3857
ok(!$@);
3858

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

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

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

            
3899
test 'create_model';
3900
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3901
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3902
eval { $dbi->execute("drop table $table1") };
3903
eval { $dbi->execute("drop table $table2") };
3904
$dbi->execute($create_table1);
3905
$dbi->execute($create_table2);
3906

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

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

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

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

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

            
3977

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

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4049
test 'Model class';
4050
$dbi = MyDBI1->connect;
4051
eval { $dbi->execute("drop table $table1") };
4052
$dbi->execute($create_table1);
4053
$model = $dbi->model($table1);
4054
$model->insert({$key1 => 'a', $key2 => 'b'});
4055
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4056
eval { $dbi->execute("drop table $table2") };
4057
$dbi->execute($create_table2);
4058
$model = $dbi->model($table2);
4059
$model->insert({$key1 => 'a'});
4060
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4061
is($dbi->models->{$table1}, $dbi->model($table1));
4062
is($dbi->models->{$table2}, $dbi->model($table2));
4063

            
4064
$dbi = MyDBI4->connect;
4065
eval { $dbi->execute("drop table $table1") };
4066
$dbi->execute($create_table1);
4067
$model = $dbi->model($table1);
4068
$model->insert({$key1 => 'a', $key2 => 'b'});
4069
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4070
eval { $dbi->execute("drop table $table2") };
4071
$dbi->execute($create_table2);
4072
$model = $dbi->model($table2);
4073
$model->insert({$key1 => 'a'});
4074
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4075

            
4076
$dbi = MyDBI5->connect;
4077
eval { $dbi->execute("drop table $table1") };
4078
eval { $dbi->execute("drop table $table2") };
4079
$dbi->execute($create_table1);
4080
$dbi->execute($create_table2);
4081
$model = $dbi->model($table2);
4082
$model->insert({$key1 => 'a'});
4083
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
4084
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4085
$model = $dbi->model($table1);
4086
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
4087

            
4088
test 'primary_key';
4089
$dbi = MyDBI1->connect;
4090
$model = $dbi->model($table1);
4091
$model->primary_key([$key1, $key2]);
4092
is_deeply($model->primary_key, [$key1, $key2]);
4093

            
4094
test 'columns';
4095
$dbi = MyDBI1->connect;
4096
$model = $dbi->model($table1);
4097
$model->columns([$key1, $key2]);
4098
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4099

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4100
test 'setup_model';
4101
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
4102
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4103
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4104
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
4105

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4106
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4107
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4108
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
4109
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
4110
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4111

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4112
test 'each_column';
4113
$dbi = DBIx::Custom->connect;
4114
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4115
eval { $dbi->execute("drop table $table1") };
4116
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4117
eval { $dbi->execute("drop table $table3") };
4118
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4119
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4120

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4141
test 'each_table';
4142
$dbi = DBIx::Custom->connect;
4143
eval { $dbi->execute("drop table $table1") };
4144
eval { $dbi->execute("drop table $table2") };
4145
$dbi->execute($create_table2);
4146
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4147

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

            
cleanup test
Yuki Kimoto authored on 2011-08-16
4165
$dbi = DBIx::Custom->connect;
4166
eval { $dbi->execute("drop table $table1") };
4167
eval { $dbi->execute("drop table $table2") };
4168
$dbi->execute($create_table2);
4169
$dbi->execute($create_table1_type);
4170

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4190
test 'type_rule into';
4191
eval { $dbi->execute("drop table $table1") };
4192
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4193
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
4194

            
4195

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4196
$dbi = DBIx::Custom->connect;
4197
eval { $dbi->execute("drop table $table1") };
4198
$dbi->execute($create_table1_type);
4199

            
cleanup
Yuki Kimoto authored on 2011-08-16
4200
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4201
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4202
  into1 => {
4203
    $date_typename => sub { '2010-' . $_[0] }
4204
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4205
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4206
$dbi->insert({$key1 => '01-01'}, table => $table1);
4207
$result = $dbi->select(table => $table1);
4208
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4209

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

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

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

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

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

            
4324

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4430
eval{$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4431
  into1 => {
4432
    $date_typename => 'pp'
4433
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4434
)};
4435
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4436

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4437
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4438
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4439
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4440
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4441
  $dbi->type_rule(
4442
    from1 => {
4443
      Date => sub { $_[0] * 2 },
4444
    }
4445
  );
cleanup test
Yuki Kimoto authored on 2011-08-10
4446
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4447
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4448

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4449
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4450
  $dbi->type_rule(
4451
    into1 => {
4452
      Date => sub { $_[0] * 2 },
4453
    }
4454
  );
cleanup test
Yuki Kimoto authored on 2011-08-15
4455
};
4456
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4457

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

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

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

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

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

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

            
4533
$result = $dbi->select(table => $table1);
4534
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4535
  from1 => [$date_datatype => undef]
cleanup test
Yuki Kimoto authored on 2011-08-15
4536
);
4537
$row = $result->one;
4538
like($row->{$key1}, qr/^2010-01-03/);
4539
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4540

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

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

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

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

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

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

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

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

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

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

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

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

            
4732

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

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

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4840
test 'columns';
4841
$dbi = MyDBI1->connect;
4842
$model = $dbi->model($table1);
4843

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4844
test 'count';
4845
$dbi = DBIx::Custom->connect;
4846
eval { $dbi->execute("drop table $table1") };
4847
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4848
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4849
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4850
is($dbi->count(table => $table1), 2);
4851
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4852
$model = $dbi->create_model(table => $table1);
4853
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4854

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4855
eval { $dbi->execute("drop table $table1") };
4856
eval { $dbi->execute("drop table $table2") };
4857
$dbi->execute($create_table1);
4858
$dbi->execute($create_table2);
4859
$model = $dbi->create_model(table => $table1, primary_key => $key1);
4860
$model->insert({$key1 => 1, $key2 => 2});
4861
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
4862
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4863
$model->insert({$key1 => 1, $key3 => 3});
4864
is($model->count(id => 1), 1);
4865
is($model->count(where => {"$table2.$key3" => 3}), 1);
4866

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