DBIx-Custom / t / common.t /
Newer Older
4868 lines | 159.84kb
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);
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
1321
$DB::single = 1;
test cleanup
Yuki Kimoto authored on 2011-08-10
1322
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1323
  table => [$table1, $table2],
1324
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
1325
  where   => {"$table1.$key2" => 2},
1326
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1327
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1328
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
1329

            
1330
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1331
  table => [$table1, $table2],
1332
  column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
1333
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1334
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1335
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
1336

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1466

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

            
1472
$dbi->begin_work;
1473

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

            
1480
$dbi->rollback if $@;
1481

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

            
1486
$dbi->begin_work;
1487

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

            
1493
$dbi->commit unless $@;
1494

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1513
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1514
$dbi->execute($create_table1);
1515
$dbi->{_cached} = {};
1516
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1517
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1518
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1519

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2106

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

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

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

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

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

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

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

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

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

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

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

            
2179
$dbi->apply_filter(
2180

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-11-01
2280
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2281
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2282
  table => $table1,
2283
  primary_key => $key1,
2284
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2285
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2286
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2287

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2466

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

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

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

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

            
2531
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2532
  column => [
2533
    $model->mycolumn([$key1]),
2534
    $model->column($table2 => [$key1])
2535
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2536
);
2537
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2538
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2539
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2540
  column => [
2541
    $model->mycolumn([$key1]),
2542
    {$table2 => [$key1]}
2543
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2544
);
2545
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2546
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2547

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

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

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

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

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

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

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

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

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

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

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

            
2683

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2862

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

            
2878

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

            
cleanup
Yuki Kimoto authored on 2011-11-01
2891
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2892
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2893
  table => $table1,
2894
  primary_key => $key1,
2895
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2896
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2897
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2898

            
2899

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

            
2918

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

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

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

            
2958

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

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

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

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

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

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

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

            
3054

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

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

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

            
3081

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3653

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3774

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3978

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4196

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

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

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

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

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

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

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

            
4325

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4733

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

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

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

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

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

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

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

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

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